[Catalyst-commits] r10050 - in
Catalyst-Devel/1.00/branches/improved-restarter: . lib/Catalyst
autarch at dev.catalyst.perl.org
autarch at dev.catalyst.perl.org
Thu May 7 23:06:08 GMT 2009
Author: autarch
Date: 2009-05-07 23:06:08 +0000 (Thu, 07 May 2009)
New Revision: 10050
Removed:
Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Watcher.pm
Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Watcher/
Modified:
Catalyst-Devel/1.00/branches/improved-restarter/Makefile.PL
Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Helper.pm
Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Restarter.pm
Log:
Rewrote restarter to use the soon-to-be-on-CPAN File::ChangeNotify
Modified: Catalyst-Devel/1.00/branches/improved-restarter/Makefile.PL
===================================================================
--- Catalyst-Devel/1.00/branches/improved-restarter/Makefile.PL 2009-05-07 16:35:25 UTC (rev 10049)
+++ Catalyst-Devel/1.00/branches/improved-restarter/Makefile.PL 2009-05-07 23:06:08 UTC (rev 10050)
@@ -9,6 +9,7 @@
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Class::Accessor::Fast';
requires 'Config::General'; # as of 1.07, we use .conf and not .yaml
+requires 'File::ChangeNotify';
requires 'File::Copy::Recursive';
requires 'Module::Install' => '0.64';
requires 'parent'; # as of 1.04
Modified: Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Helper.pm
===================================================================
--- Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Helper.pm 2009-05-07 16:35:25 UTC (rev 10049)
+++ Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Helper.pm 2009-05-07 23:06:08 UTC (rev 10050)
@@ -1034,9 +1034,9 @@
if $follow_symlinks;
$args{directories} = $watch_directory
if defined $watch_directory;
- $args{interval} = $check_interval
+ $args{sleep_interval} = $check_interval
if defined $check_interval;
- $args{regex} = qr/$file_regex/
+ $args{filter} = qr/$file_regex/
if defined $file_regex;
my $restarter = Catalyst::Restarter->new(
Modified: Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Restarter.pm
===================================================================
--- Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Restarter.pm 2009-05-07 16:35:25 UTC (rev 10049)
+++ Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Restarter.pm 2009-05-07 23:06:08 UTC (rev 10050)
@@ -2,7 +2,7 @@
use Moose;
-use Catalyst::Watcher;
+use File::ChangeNotify;
use namespace::clean -except => 'meta';
has restart_sub => (
@@ -13,7 +13,7 @@
has _watcher => (
is => 'rw',
- isa => 'Catalyst::Watcher',
+ isa => 'File::ChangeNotify::Watcher',
);
has _child => (
@@ -27,9 +27,11 @@
delete $p->{restart_sub};
+ $p->{filter} ||= qr/(?:\/|^)(?!\.\#).+(?:\.yml$|\.yaml$|\.conf|\.pm)$/;
+
# We could make this lazily, but this lets us check that we
# received valid arguments for the watcher up front.
- $self->_watcher( Catalyst::Watcher->instantiate_subclass( %{$p} ) );
+ $self->_watcher( File::ChangeNotify->instantiate_watcher( %{$p} ) );
}
sub run_and_watch {
@@ -56,16 +58,24 @@
sub _restart_on_changes {
my $self = shift;
- $self->_watcher->watch($self);
+ my @events = $self->_watcher->wait_for_events();
+ $self->_handle_events(@events);
}
-sub handle_changes {
- my $self = shift;
- my @files = @_;
+sub _handle_events {
+ my $self = shift;
+ my @events = @_;
print STDERR "\n";
print STDERR "Saw changes to the following files:\n";
- print STDERR " - $_->{file} ($_->{status})\n" for @files;
+
+ for my $event (@events) {
+ my $path = $event->path();
+ my $type = $event->type();
+
+ print STDERR " - $path ($type)\n";
+ }
+
print STDERR "\n";
print STDERR "Attempting to restart the server\n\n";
Deleted: Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Watcher.pm
===================================================================
--- Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Watcher.pm 2009-05-07 16:35:25 UTC (rev 10049)
+++ Catalyst-Devel/1.00/branches/improved-restarter/lib/Catalyst/Watcher.pm 2009-05-07 23:06:08 UTC (rev 10050)
@@ -1,59 +0,0 @@
-package Catalyst::Watcher;
-
-use Moose;
-use Moose::Util::TypeConstraints;
-
-use Cwd qw( abs_path );
-use File::Spec;
-use FindBin;
-use namespace::clean -except => 'meta';
-
-has regex => (
- is => 'ro',
- isa => 'RegexpRef',
- default => sub { qr/(?:\/|^)(?!\.\#).+(?:\.yml|\.yaml|\.conf|\.pm)$/ },
-);
-
-my $dir = subtype
- as 'Str'
- => where { -d $_ }
- => message { "$_ is not a valid directory" };
-
-my $array_of_dirs = subtype
- as 'ArrayRef[Str]',
- => where { map { -d } @{$_} }
- => message { "@{$_} is not a list of valid directories" };
-
-coerce $array_of_dirs
- => from $dir
- => via { [ $_ ] };
-
-has directories => (
- is => 'ro',
- isa => $array_of_dirs,
- default => sub { [ abs_path( File::Spec->catdir( $FindBin::Bin, '..' ) ) ] },
- coerce => 1,
-);
-
-has follow_symlinks => (
- is => 'ro',
- isa => 'Bool',
- default => 0,
-);
-
-sub instantiate_subclass {
- my $class = shift;
-
- if ( eval { require Catalyst::Watcher::Inotify; 1; } ) {
- return Catalyst::Watcher::Inotify->new(@_);
- }
- else {
- die $@ if $@ && $@ !~ /Can't locate/;
- require Catalyst::Watcher::FileModified;
- return Catalyst::Watcher::FileModified->new(@_);
- }
-}
-
-__PACKAGE__->meta->make_immutable;
-
-1;
More information about the Catalyst-commits
mailing list