I'm using Module::Build
to build my distribution. My distro is making a cache file in $HOME/.cache/my_*.cache
I need to be able to cleanup this file on module uninstall (or at least make sure it's not there during module install).
CodePudding user response:
You need to define your own clean
target, then do whatever it is you need to do. In your Module::Build
subclass, you'd define an ACTION_clean
method to do the work. See Dave Rolsky's article on Module::Build for Perl.com.
But, Module::Build
is a dead end. It was removed from the Standard Library in v5.21 and there hasn't been significant development on it since 2017. It was an idea that never quite reached its potential. It would have been nice to have a pure-Perl build system, but build systems require a lot of maintenance. After Strawberry Perl effectively solved the Windows problem (partly by providing a make
variant), there wasn't as much of a need for Module::Build
.
Consider using ExtUtils::MakeMaker
, which comes with Perl. If you have simple needs, you'll do a lot less work. In that case, you'd pass WriteMakefile
a clean
key with the appropriate value.
my %WriteMakefile = (
...,
'clean' => { FILES => "$ENV{HOME}/.cache/my_*.cache" },
);
CodePudding user response:
Thanks for the idea. I ended up creating a subclass of Module::Build with the necessary cleanup:
my $class = Module::Build->subclass(
code => q{
sub _clear_cache {
for ( glob "$ENV{HOME}/.cache/my_pod*.cache" ) {
print "Removing: $_\n";
unlink or warn $!;
}
}
sub ACTION_install {
my ($s) = @_;
$s->_clear_cache;
$s->SUPER::ACTION_install;
}
sub ACTION_clean {
my ($s) = @_;
$s->_clear_cache;
$s->SUPER::ACTION_clean;
}
},
);
my $builder = $class->new( ...