Skip to content

Instantly share code, notes, and snippets.

@kentaro
Created April 21, 2011 04:28
Show Gist options
  • Save kentaro/933719 to your computer and use it in GitHub Desktop.
Save kentaro/933719 to your computer and use it in GitHub Desktop.
Reload browser when static files get modified
# ... snip ...
{
use Plack::Loader::Restarter;
no warnings 'redefine';
my $orig = \&Plack::Loader::Restarter::_fork_and_start;
*Plack::Loader::Restarter::_fork_and_start = sub {
my ($self, $server) = @_;
my $restart = exists $self->{pid};
$orig->($self, $server);
if ($restart) {
system(q{osascript -e 'tell application "Google Chrome" to reload active tab of window 1'});
warn 'Your browser has been reloaded!';
}
}
}
my $runner = Plack::Runner->new;
$runner->parse_options(
'--server' => 'HTTP::Server::Simple',
'--port' => $port || 3000,
'--app' => 'script/app.psgi',
'--Reload' => join(',', glob("$FindBin::Bin/../static", "$FindBin::Bin/../templates"),
);
$runner->run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment