package Catalyst::Engine::HTTP::Restarter::Watcher;
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 }
+}
has delay => (is => 'rw');
has regex => (is => 'rw');
has modified => (is => 'rw');
has directory => (is => 'rw');
has watch_list => (is => 'rw');
-has follow_simlinks => (is => 'rw');
-
-sub new {
- my ( $class, %args ) = @_;
-
- my $self = {%args};
+has follow_symlinks => (is => 'rw');
- bless $self, $class;
-
- $self->_init;
-
- return $self;
+sub BUILD {
+ shift->_init;
}
sub _init {
my @changes;
my @changed_files;
-
+
my $delay = ( defined $self->delay ) ? $self->delay : 1;
sleep $delay if $delay > 0;
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) {
+ $meta->make_mutable if $meta->is_immutable;
+ }
+ });
+ }
+
+ delete $INC{$file}; # Remove from %INC so it will reload
local $SIG{__WARN__} = sub { };
open my $olderr, '>&STDERR';
eval "require '$file'";
open STDERR, '>&', $olderr;
+ B::Hooks::OP::Check::StashChange::unregister($id) if $id;
+
return ($@) ? $@ : 0;
}
my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
directory => '/path/to/MyApp',
- regex => '\.yml$|\.yaml$|\.pm$',
+ regex => '\.yml$|\.yaml$|\.conf|\.pm$',
delay => 1,
);
-
+
while (1) {
my @changed_files = $watcher->watch();
}
=head1 AUTHORS
-Sebastian Riedel, <sri@cpan.org>
-
-Andy Grundman, <andy@hybridized.org>
+Catalyst Contributors, see Catalyst.pm
=head1 THANKS