Created
April 21, 2011 04:28
-
-
Save kentaro/933719 to your computer and use it in GitHub Desktop.
Reload browser when static files get modified
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... 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