X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FHTTP%2FRestarter%2FWatcher.pm;h=8890646ead541370ccc212e38e9bcbba8fa4dbf2;hb=4ffa3785756fc4df4b834f936f1f3acfcf7116f0;hp=4095e83e8f4b1c7294e6b57fd233aa85c6b582a9;hpb=c03163b837135f3bf3d65380e90b4a68bcc38099;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm b/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm index 4095e83..8890646 100644 --- a/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm +++ b/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm @@ -22,26 +22,21 @@ BEGIN { has delay => (is => 'rw'); has regex => (is => 'rw'); -has modified => (is => 'rw'); +has modified => (is => 'rw', builder => '_build_modified', lazy => 1); has directory => (is => 'rw'); -has watch_list => (is => 'rw'); +has watch_list => (is => 'rw', builder => '_build_watch_list', lazy => 1); has follow_symlinks => (is => 'rw'); -sub BUILD { - shift->_init; +sub _build_watch_list { + my ($self) = @_; + return $self->_index_directory; } -sub _init { - my $self = shift; - - my $watch_list = $self->_index_directory; - $self->watch_list($watch_list); - - $self->modified( - File::Modified->new( - method => 'mtime', - files => [ keys %{$watch_list} ], - ) +sub _build_modified { + my ($self) = @_; + return File::Modified->new( + method => 'mtime', + files => [ keys %{ $self->watch_list } ], ); } @@ -50,7 +45,7 @@ sub watch { my @changes; my @changed_files; - + my $delay = ( defined $self->delay ) ? $self->delay : 1; sleep $delay if $delay > 0; @@ -141,12 +136,19 @@ sub _test { $id = B::Hooks::OP::Check::StashChange::register(sub { my ($new, $old) = @_; my $meta = find_meta($new); - if ($meta) { - $meta->make_mutable if $meta->is_immutable; + 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(); + eval { # Do not explode the watcher process if this fails. + my $superclasses = $meta->can('superclasses'); + $meta->$superclasses('Moose::Object') if $superclasses; + }; } }); } + local $Catalyst::__AM_RESTARTING = 1; # Hack to avoid C3 fail delete $INC{$file}; # Remove from %INC so it will reload local $SIG{__WARN__} = sub { }; @@ -175,7 +177,7 @@ files regex => '\.yml$|\.yaml$|\.conf|\.pm$', delay => 1, ); - + while (1) { my @changed_files = $watcher->watch(); } @@ -222,7 +224,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