Plack::Middleware::Refresh - Refresh all modules in %INC


Plack documentation Contained in the Plack distribution.

Index


Code Index:

NAME

Top

Plack::Middleware::Refresh - Refresh all modules in %INC

SYNOPSIS

Top

  enable "Refresh", cooldown => 3;
  $app;

DESCRIPTION

Top

This is yet another approach to refresh modules in %INC during the development cycle, without the need to have a forking process to watch for filesystem updates. This middleware, in a request time, compares the last refresh time and the current time and if the difference is bigger than cooldown seconds which defaults to 10, call Module::Refresh to reload all Perl modules in %INC if the files have been modified.

Note that this only reloads modules and not other files such as templates.

This middleware is quite similar to what Rack::Reoader does. If you have issues with this reloading technique, for instance when you have in-file templates that needs to be recompiled, or Moose classes that has make_immutable, take a look at plackup's default -r option or Plack::Loader::Shotgun instead.

AUTHOR

Top

Tatsuhiko Miyagawa

SEE ALSO

Top

Module::Refresh Rack::Reloader


Plack documentation Contained in the Plack distribution.

package Plack::Middleware::Refresh;
use strict;
use parent qw(Plack::Middleware);
use Module::Refresh;
use Plack::Util::Accessor qw(last cooldown);

sub prepare_app {
    my $self = shift;
    $self->cooldown(10) unless defined $self->cooldown;

    Module::Refresh->new;
    $self->last(time - $self->cooldown);
}

sub call {
    my($self, $env) = @_;

    if (time > $self->last + $self->cooldown) {
        Module::Refresh->refresh;
        $self->last(time);
    }

    $self->app->($env);
}

1;

__END__