4 use HTTP::Request::Common;
5 use HTTP::Message::PSGI;
9 # Test to make sure we let HTTP style exceptions bubble up to the middleware
10 # rather than catching them outselves.
13 package MyApp::Exception;
16 my ($class, $code, $headers, $body) = @_;
17 return bless +{res => [$code, $headers, $body]}, $class;
20 sub throw { die shift->new(@_) }
23 my ($self, $env) = @_;
24 my ($code, $headers, $body) = @{$self->{res}};
26 return [$code, $headers, $body]; # for now
29 my $responder = shift;
30 $responder->([$code, $headers, $body]);
34 package MyApp::Controller::Root;
36 use base 'Catalyst::Controller';
40 die MyApp::Exception->new(
41 404, ['content-type'=>'text/plain'], ['Not Found']);
44 sub from_psgi_app :Local {
46 $c->res->from_psgi_response(
51 sub from_catalyst :Local {
53 MyApp::Exception->throw(
54 403, ['content-type'=>'text/plain'], ['Forbidden']);
57 sub classic_error :Local {
59 Catalyst::Exception->throw("Ex Parrot");
64 die "I'm not dead yet";
72 MyApp->setup_log('fatal');
75 $INC{'MyApp/Controller/Root.pm'} = '1'; # sorry...
76 MyApp->setup_log('error');
78 Test::More::ok(MyApp->setup);
80 ok my $psgi = MyApp->psgi_app;
82 test_psgi $psgi, sub {
84 my $res = $cb->(GET "/root/from_psgi_app");
86 is $res->content, 'Not Found', 'NOT FOUND';
89 test_psgi $psgi, sub {
91 my $res = $cb->(GET "/root/from_catalyst");
93 is $res->content, 'Forbidden', 'Forbidden';
96 test_psgi $psgi, sub {
98 my $res = $cb->(GET "/root/classic_error");
100 like $res->content, qr'Ex Parrot', 'Ex Parrot';
103 test_psgi $psgi, sub {
105 my $res = $cb->(GET "/root/just_die");
107 like $res->content, qr'not dead yet', 'not dead yet';
112 # We need to specify the number of expected tests because tests that live
113 # in the callbacks might never get run (thus all ran tests pass but not all
114 # required tests run).