0

I'm using Module::Build's share_dir option to install read-only supplementary content when users install my Perl module.

How do I ensure that the old content added by previous versions of my module is deleted when a new version of my module is installed?

Thanks in advance for your help.

Anirvan
  • 6,214
  • 5
  • 39
  • 53

3 Answers3

1

Yanick Champoux has recently been dealing with this problem. To do so he has created File::ShareDir::Tarball and its Dist::Zilla counterpart Dist::Zilla::Plugin::ShareDir::Tarball. The idea is that your entire sharedir is tarred so that it is only one directory. Then when your module is upgraded, the tarball is replaced and it is in the state you expect.

Joel Berger
  • 20,180
  • 5
  • 49
  • 104
  • FWIW, that solution doesn't appeal to me :) I would rather use `sub share { dist_file( 'File-ShareDir', "2012-11-02/@_"); }` that way older files don't interfere with newer code, even if they aren't removed – so not liopa Nov 02 '12 at 11:25
  • @sonotlikeopenid.anonymity, that and your answer are both good ideas, I simply posted something that is already implemented. I have no opinion about which is best. :-) – Joel Berger Nov 02 '12 at 12:08
  • Thanks. This seems like the least-bad option in my particular case. – Anirvan Nov 02 '12 at 18:10
  • versioned directories is also a possibility. I played with the idea, but then, if the previous module version is gone anyway (because that one got clobbered for sure by the install), why bother keeping the old shared files around too? – Yanick Nov 03 '12 at 00:30
1

If you're removing files from a distribution I recommend making Makefile.PL or Build.PL refuse to install, add this

my $mod = 'CGI';
if( eval "require $mod; 1" ){
  die "

YOU HAVE TO UNINSTALL $mod before you can upgrade, use one of
cpanp -u  $mod  --force
pm-uninstall -vf $mod


";
}

Or better yet, add a pre-amble which does the actual uninstalling (maybe with ExtUtils::Install::uninstall($packlist) )

Usually you'll know which version of your module requires complete uninstalling, so you might want to add a version check ...

FWIW, this would make a good Module::Build/Module::Install/ExtUtils::MakeMaker addition/extension/plugin that accepts something like

requires_uninstall_if_installed  => '<3000' ,
requires_uninstall_if_installed  => { CGI => '<3000', 'CGI::Util' => '<3000' },
requires_uninstall_if_installed  => [ qw' CGI CGI::Util '],

requires_uninstall_if_installed( '<3000' );
requires_uninstall_if_installed( { CGI => '<3000', 'CGI::Util' => '<3000' } );
requires_uninstall_if_installed( [ qw' CGI CGI::Util '] );
so not liopa
  • 485
  • 2
  • 5
  • Actually it wouldn't be very hard to make a Module::Build subclass which does somehow cleans either the share dir or the entire old module during (probably just before) `ACTION_install`. – Joel Berger Nov 02 '12 at 12:13
  • 1
    see possible implementation here: https://github.com/jberger/Module-Build-CleanInstall – Joel Berger Nov 02 '12 at 13:09
  • Thanks, @sonotlike. This is a good strategy, and I'll fall back to this if I can't make File::ShareDir::Tarball work for my needs. – Anirvan Nov 02 '12 at 18:13
1

I have now uploaded Module::Build::CleanInstall to hopefully address issues like this. Hopefully it helps. A big thanks goes to Yanick and so-not-like-openid-anonymity for the inspiration.

Joel Berger
  • 20,180
  • 5
  • 49
  • 104