X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FHTTP%2FRestarter.pm;h=bae57b18cac9443027dc27732c7bd2d983efbf47;hp=42f57ddb39078beeb5a97678acae8399e2b923b8;hb=4f03bb77eaf3b07fac86f455bf688c2b6f1d5273;hpb=57a87bb3b029e5702f5fd0b7925cf6ab9c243596 diff --git a/lib/Catalyst/Engine/HTTP/Restarter.pm b/lib/Catalyst/Engine/HTTP/Restarter.pm index 42f57dd..bae57b1 100644 --- a/lib/Catalyst/Engine/HTTP/Restarter.pm +++ b/lib/Catalyst/Engine/HTTP/Restarter.pm @@ -1,12 +1,14 @@ package Catalyst::Engine::HTTP::Restarter; +use Moose; +use Moose::Util qw/find_meta/; +use namespace::clean -except => 'meta'; + +extends 'Catalyst::Engine::HTTP'; -use strict; -use warnings; -use base 'Catalyst::Engine::HTTP'; use Catalyst::Engine::HTTP::Restarter::Watcher; -use NEXT; -sub run { +around run => sub { + my $orig = shift; my ( $self, $class, $port, $host, $options ) = @_; $options ||= {}; @@ -18,8 +20,18 @@ sub run { close STDIN; close STDOUT; + # Avoid "Setting config after setup" error restarting MyApp.pm + $class->setup_finished(0); + # Best effort if we can't trap compiles.. + $self->_make_components_mutable($class) + if !Catalyst::Engine::HTTP::Restarter::Watcher::DETECT_PACKAGE_COMPILATION; + my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new( - directory => File::Spec->catdir( $FindBin::Bin, '..' ), + directory => ( + $options->{restart_directory} || + File::Spec->catdir( $FindBin::Bin, '..' ) + ), + follow_symlinks => $options->{follow_symlinks}, regex => $options->{restart_regex}, delay => $options->{restart_delay}, ); @@ -63,7 +75,23 @@ sub run { } } - return $self->NEXT::run( $class, $port, $host, $options ); + return $self->$orig( $class, $port, $host, $options ); +}; + +# Naive way of trying to avoid Moose blowing up when you re-require components +# which have been made immutable. +sub _make_components_mutable { + my ($self, $class) = @_; + + my @metas = grep { defined($_) } + map { find_meta($_) } + ($class, map { blessed($_) } + values %{ $class->components }); + + foreach my $meta (@metas) { + # Paranoia unneeded, all component metaclasses should have immutable + $meta->make_mutable if $meta->is_immutable; + } } 1; @@ -84,11 +112,7 @@ and restart the server when any changes are detected. =head1 METHODS -=over 4 - -=item run - -=back +=head2 run =head1 SEE ALSO @@ -97,11 +121,7 @@ L. =head1 AUTHORS -Sebastian Riedel, - -Dan Kubb, - -Andy Grundman, +Catalyst Contributors, see Catalyst.pm =head1 THANKS