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%2FWatcher.pm;h=6aada3e06d61fd03acd674a4adcc6d8d29b78fab;hp=0ff391651a70db2b08acd4269f2e7076e910d279;hb=ae29b412955743885e80350085167b54b69672da;hpb=0bf7ab7160f4f2fd0f00cd3d53ac311e9ad50241 diff --git a/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm b/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm index 0ff3916..6aada3e 100644 --- a/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm +++ b/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm @@ -1,32 +1,34 @@ package Catalyst::Engine::HTTP::Restarter::Watcher; -use strict; -use warnings; -use base 'Class::Accessor::Fast'; +use Moose; +with 'MooseX::Emulate::Class::Accessor::Fast'; + use File::Find; use File::Modified; use File::Spec; use Time::HiRes qw/sleep/; +use Moose::Util qw/find_meta/; +use namespace::clean -except => 'meta'; + +BEGIN { + # If we can detect stash changes, then we do magic + # to make their metaclass mutable (if they have one) + # so that restarting works as expected. + eval { require B::Hooks::OP::Check::StashChange; }; + *DETECT_PACKAGE_COMPILATION = $@ + ? sub () { 0 } + : sub () { 1 } +} -__PACKAGE__->mk_accessors( - qw/delay - directory - modified - regex - follow_symlinks - watch_list/ -); - -sub new { - my ( $class, %args ) = @_; - - my $self = {%args}; - - bless $self, $class; - - $self->_init; +has delay => (is => 'rw'); +has regex => (is => 'rw'); +has modified => (is => 'rw'); +has directory => (is => 'rw'); +has watch_list => (is => 'rw'); +has follow_symlinks => (is => 'rw'); - return $self; +sub BUILD { + shift->_init; } sub _init { @@ -134,7 +136,20 @@ sub _index_directory { sub _test { my ( $self, $file ) = @_; - delete $INC{$file}; + my $id; + if (DETECT_PACKAGE_COMPILATION) { + $id = B::Hooks::OP::Check::StashChange::register(sub { + my ($new, $old) = @_; + my $meta = find_meta($new); + if ($meta) { # A little paranoia here - Moose::Meta::Role has neither of these methods. + my $is_immutable = $meta->can('is_immutable'); + my $make_mutable = $meta->can('make_mutable'); + $meta->$make_mutable() if $is_immutable && $make_mutable && $meta->$is_immutable(); + } + }); + } + + delete $INC{$file}; # Remove from %INC so it will reload local $SIG{__WARN__} = sub { }; open my $olderr, '>&STDERR'; @@ -142,6 +157,8 @@ sub _test { eval "require '$file'"; open STDERR, '>&', $olderr; + B::Hooks::OP::Check::StashChange::unregister($id) if $id; + return ($@) ? $@ : 0; } @@ -182,6 +199,17 @@ Creates a new Watcher object. Returns a list of files that have been added, deleted, or changed since the last time watch was called. +=head2 DETECT_PACKAGE_COMPILATION + +Returns true if L is installed and +can be used to detect when files are compiled. This is used internally +to make the L metaclass of any class being reloaded immutable. + +If L is not installed, then the +restarter makes all application components immutable. This covers the +simple case, but is less useful if you're using Moose in components +outside Catalyst's namespaces, but inside your application directory. + =head1 SEE ALSO L, L, L