}
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";
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(