Stuff::Reload - Modules unloader and reloader
use Stuff::Reload; my $reload = Stuff::Reload->new( %args ); $reload->run;
new
my $reload = Stuff::Reload->new( %args );
run
my $errors = $modules->run; my $errors = $modules->run( sub { # callback called when any modification happen } );
check
my $modules = $reload->check; if( $modules->modified ) { # Do some finalizing... my $errors = $modules->reload_safe; }
Method check checks if any of traced modules were changed. Returns $modules object, which can be used to perform custom reload strategy.
You can simply reload your code when it was modified. If your modules "pure" (have no side effects at loading) then you can use it.
# Initialization. use Stuff::Reload; my $reloader = Stuff::Reload->new; # ... # At some point where reload can happen. # All modified modules will be reloaded. my $errors = $reloader->run;
But the best way to reload code is to use unload and restart application initialization process.
sub init { # initialization code } sub shutdown { # shutdown code } use Stuff::Reload; my $reloader = Stuff::Reload->new( default_mode => 'unload' ); init(); # ... # At some point where reload can happen. my $errors = $reloader->run( sub { shutdown(); shift->reload; init(); } );
To install Stuff, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Stuff
CPAN shell
perl -MCPAN -e shell install Stuff
For more information on module installation, please visit the detailed CPAN module installation guide.