Factor restarter arg assembly out into it's own routine for ease of testing. Use...
Tomas Doran [Thu, 26 Nov 2009 02:23:00 +0000 (02:23 +0000)]
lib/Catalyst/Script/Create.pm
lib/Catalyst/Script/Server.pm
lib/Catalyst/Script/Test.pm

index 361aa26..e65a597 100644 (file)
@@ -34,7 +34,7 @@ has helper_class => ( isa => 'Str', is => 'ro', default => 'Catalyst::Helper' );
 sub run {
     my ($self) = @_;
 
-    $self->_exit_with_usage if !$ARGV[0];
+    $self->_exit_with_usage if !$self->ARGV->[0];
 
     my $helper_class = $self->helper_class;
     Class::MOP::load_class($helper_class);
index c3c6584..68e6b85 100644 (file)
@@ -119,8 +119,26 @@ has follow_symlinks => (
     documentation => 'Follow symbolic links',
 );
 
+sub _restarter_args {
+    my $self = shift;
+    my %args;
+    $args{follow_symlinks} = $self->follow_symlinks
+        if $self->follow_symlinks;
+    $args{directories}     = $self->restart_directory
+        if $self->_has_restart_directory;
+    $args{sleep_interval}  = $self->restart_delay
+        if $self->_has_restart_delay;
+    if ($self->_has_restart_regex) {
+        my $regex = $self->restart_regex;
+        $args{filter} = qr/$regex/;
+    }
+    $args{start_sub} = sub { $self->_run_application };
+    $args{argv}      = $self->ARGV;
+    return %args;
+}
+
 sub run {
-    my ($self) = shift;
+    my $self = shift;
 
     local $ENV{CATALYST_DEBUG} = 1
         if $self->debug;
@@ -141,20 +159,9 @@ sub run {
 
         my $subclass = Catalyst::Restarter->pick_subclass;
 
-        my %args;
-        $args{follow_symlinks} = $self->follow_symlinks
-            if $self->follow_symlinks;
-        $args{directories}     = $self->restart_directory
-            if $self->_has_restart_directory;
-        $args{sleep_interval}  = $self->restart_delay
-            if $self->_has_restart_delay;
-        $args{filter} = qr/$self->restart_regex/
-            if $self->_has_restart_regex;
-
+        
         my $restarter = $subclass->new(
-            %args,
-            start_sub => sub { $self->_run_application },
-            argv      => $self->ARGV,
+            $self->_restarter_args()
         );
 
         $restarter->run_and_watch;
index a05b182..53473a4 100644 (file)
@@ -10,7 +10,7 @@ sub run {
 
     Catalyst::Test->import($self->application_name);
 
-    print request($ARGV[0])->content  . "\n";
+    print request($self->ARGV->[0])->content  . "\n";
 }