}
$class->import;
- my $app = $class->psgi_app;
-
- $request = sub { local_request( $app, @_ ) };
+ $request = sub { local_request( $class, @_ ) };
}
my $get = sub { $request->(@_)->content };
my $ctx_request = sub {
my $me = ref $self || $self;
- ### throw an exception if ctx_request is being used against a remote
- ### server
+ # fail if ctx_request is being used against a remote server
Catalyst::Exception->throw("$me only works with local requests, not remote")
if $ENV{CATALYST_SERVER};
- ### check explicitly for the class here, or the Cat->meta call will blow
- ### up in our face
+ # check explicitly for the class here, or the Cat->meta call will blow
+ # up in our face
Catalyst::Exception->throw("Must specify a test app: use Catalyst::Test 'TestApp'") unless $class;
- ### place holder for $c after the request finishes; reset every time
- ### requests are done.
+ # place holder for $c after the request finishes; reset every time
+ # requests are done.
my $ctx_closed_over;
- ### hook into 'dispatch' -- the function gets called after all plugins
- ### have done their work, and it's an easy place to capture $c.
+ # hook into 'dispatch' -- the function gets called after all plugins
+ # have done their work, and it's an easy place to capture $c.
my $meta = Class::MOP::get_metaclass_by_name($class);
$meta->make_mutable;
});
$meta->make_immutable( replace_constructor => 1 );
Class::C3::reinitialize(); # Fixes RT#46459, I've failed to write a test for how/why, but it does.
- ### do the request; C::T::request will know about the class name, and
- ### we've already stopped it from doing remote requests above.
+
+ # do the request; C::T::request will know about the class name, and
+ # we've already stopped it from doing remote requests above.
my $res = $request->( @_ );
# Make sure not to leave a reference $ctx hanging around.
my $ctx = $ctx_closed_over;
undef $ctx_closed_over;
- ### return both values
return ( $res, $ctx );
};
=cut
sub local_request {
- my $app = shift;
+ my $class = shift;
+
+ my $app = ref($class) eq "CODE" ? $class : $class->_finalized_psgi_app;
my $request = Catalyst::Utils::request(shift);
my %extra_env;
test_psgi
app => sub { $app->({ %{ $_[0] }, %extra_env }) },
client => sub {
- my $resp = shift->($request);
+ my $psgi_app = shift;
+
+ my $resp = $psgi_app->($request);
# HTML head parsing based on LWP::UserAgent
#