Changeset 29323

Show
Ignore:
Timestamp:
01/31/09 01:45:11 (4 years ago)
Author:
yappo
Message:

add normal test case

Location:
lang/perl/HTTP-Engine-Middleware/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTTP-Engine-Middleware/trunk/lib/HTTP/Engine/Middleware.pm

    r29322 r29323  
    2020    is      => 'ro', 
    2121    isa     => 'Str', 
     22); 
     23 
     24has 'diecatch' => ( 
     25    is  => 'rw', 
     26    isa => 'Bool', 
    2227); 
    2328 
     
    177182            } 
    178183        } 
    179         my $res = eval { $handle->($req) }; 
     184        my $res; 
     185        my $msg; 
     186        { 
     187            local $@; 
     188            $self->diecatch(0); 
     189            eval { $res = $handle->($req) }; 
     190            $msg = $@ if !$self->diecatch && $@; 
     191        } 
     192        die $msg if $msg; 
    180193        for my $middleware (reverse @{ $self->middlewares }) { 
    181194            my $instance = $self->_instance_of->{$middleware}; 
  • lang/perl/HTTP-Engine-Middleware/trunk/lib/HTTP/Engine/Middleware/DebugScreen.pm

    r29321 r29323  
    3636    $self->stacktrace_required(0); 
    3737 
    38     localize_elem '%SIG', '__DIE__' => sub { died($self, @_) } => SUB UP; 
     38    localize_elem '%SIG', '__DIE__' => sub { $c->diecatch(1); died($self, @_) } => SUB UP; 
    3939 
    4040    $req; 
  • lang/perl/HTTP-Engine-Middleware/trunk/t/200_middlewares/debugscreen.t

    r29321 r29323  
    88plan skip_all => "Scope::Upper is not installed: $@" if $@; 
    99 
    10 plan tests => 4; 
     10plan tests => 6; 
    1111 
    1212use HTTP::Engine; 
     
    1616use HTTP::Engine::Middleware; 
    1717 
    18 my $mw = HTTP::Engine::Middleware->new; 
    19 $mw->install( 'HTTP::Engine::Middleware::DebugScreen', { powerd_by => 'HE::Middleware test' } ); 
     18{ 
     19    my $mw = HTTP::Engine::Middleware->new; 
     20    $mw->install( 'HTTP::Engine::Middleware::DebugScreen', { powerd_by => 'HE::Middleware test' } ); 
     21    my $res = HTTP::Engine->new( 
     22        interface => { 
     23            module          => 'Test', 
     24            request_handler => $mw->handler( 
     25                sub { die 'ERROR TEST HE' } 
     26            ), 
     27        }, 
     28    )->run( HTTP::Request->new( GET => 'http://localhost/') ); 
     29    my $out = $res->content; 
    2030 
    21 my $res = HTTP::Engine->new( 
    22     interface => { 
    23         module          => 'Test', 
    24         request_handler => $mw->handler( 
    25             sub { die 'ERROR TEST HE' } 
    26         ), 
    27     }, 
    28 )->run( HTTP::Request->new( GET => 'http://localhost/') ); 
    29 my $out = $res->content; 
     31    is $res->code, '500'; 
     32    like $out, qr/ERROR TEST HE/; 
     33    like $out, qr/Powered by HE::Middleware test/; 
     34    like $out, qr/request_handler => \$mw->handler\(/; 
     35} 
    3036 
    31 is $res->code, '500'; 
    32 like $out, qr/ERROR TEST HE/; 
    33 like $out, qr/Powered by HE::Middleware test/; 
    34 like $out, qr/request_handler => \$mw->handler\(/; 
     37{ 
     38    my $mw = HTTP::Engine::Middleware->new; 
     39    $mw->install(); 
     40    my $res = HTTP::Engine->new( 
     41        interface => { 
     42            module          => 'Test', 
     43            request_handler => $mw->handler( 
     44                sub { die 'ERROR TEST HE' } 
     45            ), 
     46        }, 
     47    )->run( HTTP::Request->new( GET => 'http://localhost/') ); 
     48    my $out = $res->content; 
     49 
     50    is $res->code, '500'; 
     51    is $out, 'internal server errror'; 
     52}