pass run_if_script args to new
Christian Walde [Fri, 24 Oct 2014 17:35:13 +0000 (19:35 +0200)]
lib/Web/Simple/Application.pm
t/run_if_script.t

index 7ef273b..68f8b2c 100644 (file)
@@ -50,16 +50,16 @@ sub _build_final_dispatcher {
 }
 
 sub run_if_script {
-  my ( $self ) = @_;
+  my ( $self, @args ) = @_;
   # ->to_psgi_app is true for require() but also works for plackup
   return $self->to_psgi_app if caller(1);
-  $self = ref($self) ? $self : $self->_build_for_run_if_script;
-  $self->run(@_);
+  $self = ref($self) ? $self : $self->_build_for_run_if_script(@args);
+  $self->run;
 }
 
 sub _build_for_run_if_script {
-  my ( $self ) = @_;
-  try { $self->new }
+  my ( $self, @args ) = @_;
+  try { $self->new(@args) }
   catch {
     die "Failed to create new '$self' object during run_if_script"
       . " (should your .pm file end with just '1;'?) : $_\n";
index dc66514..0839046 100644 (file)
@@ -38,14 +38,14 @@ my $rt = RunTest->new( test => 3 );
 
 is_deeply(
     [ $rt->run_if_script ],                 #
-    [ $rt, $rt, "run" ],
+    [ $rt, "run" ],
     "calling run_if_script on an object runs it directly"
 );
 
-is_deeply(
-    [ $rt->run_if_script( 4 ) ],            #
-    [ $rt, $rt, 4, "run" ],
-    "passing arguments to run_if_script has them passed on to the run method"
+is(
+    ( RunTest->run_if_script( test => 4 ) )[0]->test,    #
+    4,
+    "passing arguments to run_if_script has them passed on to the new method"
 );
 
 like(