X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FHTTP%2FRestarter.pm;h=dfb414c7d0347b5ea2f7e30b9d47af42f63471ef;hb=4ffa3785756fc4df4b834f936f1f3acfcf7116f0;hp=3eb7d046ebb0e8d672d3ff64431eda7267bb9ae6;hpb=6f1f968a6bc42bf4a4b50a1ee22d3aaecd801876;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/HTTP/Restarter.pm b/lib/Catalyst/Engine/HTTP/Restarter.pm index 3eb7d04..dfb414c 100644 --- a/lib/Catalyst/Engine/HTTP/Restarter.pm +++ b/lib/Catalyst/Engine/HTTP/Restarter.pm @@ -1,14 +1,14 @@ package Catalyst::Engine::HTTP::Restarter; - -use MRO::Compat; -use mro 'c3'; use Moose; +use Moose::Util qw/find_meta/; +use namespace::clean -except => 'meta'; + extends 'Catalyst::Engine::HTTP'; -no Moose; use Catalyst::Engine::HTTP::Restarter::Watcher; -sub run { +around run => sub { + my $orig = shift; my ( $self, $class, $port, $host, $options ) = @_; $options ||= {}; @@ -20,9 +20,15 @@ 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 => ( - $options->{restart_directory} || + directory => ( + $options->{restart_directory} || File::Spec->catdir( $FindBin::Bin, '..' ) ), follow_symlinks => $options->{follow_symlinks}, @@ -69,9 +75,25 @@ sub run { } } - return $self->next::method( $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; __END__ @@ -99,11 +121,7 @@ L. =head1 AUTHORS -Sebastian Riedel, - -Dan Kubb, - -Andy Grundman, +Catalyst Contributors, see Catalyst.pm =head1 THANKS @@ -111,7 +129,7 @@ Many parts are ripped out of C by Jesse Vincent. =head1 COPYRIGHT -This program is free software, you can redistribute it and/or modify it under +This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =cut