The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Stuff::Reload - Modules unloader and reloader

SYNOPSIS

  use Stuff::Reload;
  my $reload = Stuff::Reload->new( %args );
  $reload->run;

METHODS

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.

CODE RELOAD STRATEGIES

Simple reload

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;

Smart code replacing

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();
  } );