| 1 | package HTTP::Engine::Middleware::DebugRequest; | ||||||||||
| 2 | 1 | ▶ | use HTTP::Engine::Middleware; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Text::SimpleTable; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | with 'HTTP::Engine::Middleware::Role::Logger'; | |||||||||
| 6 | |||||||||||
| 7 | before_handle { | ||||||||||
| 8 | 3 | ▶ | my ( $c, $self, $req ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | $self->report_request_info($req); | |||||||||
| 10 | 3 | $req; | |||||||||
| 11 | 1 | }; | |||||||||
| 12 | |||||||||||
| 13 | sub report_request_info { | ||||||||||
| 14 | 3 | ▶ | my ( $self, $request ) = @_; | ||||||||
|
Subroutine
report_request_info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 15 | 3 | $self->report_request_basic_info($request); | |||||||||
| 16 | 3 | $self->report_params($request); | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | sub report_params { | ||||||||||
| 20 | 3 | ▶ | my ( $self, $req ) = @_; | ||||||||
|
Subroutine
report_params: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||
| 21 | 3 | ▶ | if ( keys %{ $req->parameters } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 2 | my $t | |||||||||
| 23 | = Text::SimpleTable->new( [ 20, 'Parameter' ], [ 36, 'Value' ] ); | ||||||||||
| 24 | 2 | for my $key ( sort keys %{ $req->parameters } ) { | |||||||||
| 25 | 2 | my $param = $req->parameters->{$key}; | |||||||||
| 26 | 2 | ▶ | my $value = defined($param) ? $param : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 2 | ▶ | $t->row( $key, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | ref $value eq 'ARRAY' ? ( join ', ', @$value ) : $value ); | ||||||||||
| 29 | } | ||||||||||
| 30 | 2 | my $message = "Parameters: \n" . $t->draw; | |||||||||
| 31 | 2 | $self->log( $message ); | |||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | sub report_request_basic_info { | ||||||||||
| 36 | 3 | ▶ | my ( $self, $req ) = @_; | ||||||||
|
Subroutine
report_request_basic_info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 37 | 3 | my $t = Text::SimpleTable->new( | |||||||||
| 38 | [ 40, 'Path' ], | ||||||||||
| 39 | [ 8, 'Method' ], | ||||||||||
| 40 | [ 30, 'Base' ] | ||||||||||
| 41 | ); | ||||||||||
| 42 | 3 | $t->row( $req->path, $req->method, $req->base ); | |||||||||
| 43 | 3 | my $message = "Matching Info:\n" . $t->draw; | |||||||||
| 44 | 3 | $self->log( $message ); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | __MIDDLEWARE__ | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||
| 50 | |||||||||||
| 51 | =head1 NAME | ||||||||||
| 52 | |||||||||||
| 53 | HTTP::Engine::Middleware::DebugRequest - dump request | ||||||||||
| 54 | |||||||||||
| 55 | =head1 SYNOPSIS | ||||||||||
| 56 | |||||||||||
| 57 | my $mw = HTTP::Engine::Middleware->new; | ||||||||||
| 58 | $mw->install( 'HTTP::Engine::Middleware::DebugRequest' => { | ||||||||||
| 59 | logger => sub { | ||||||||||
| 60 | warn @_; | ||||||||||
| 61 | }, | ||||||||||
| 62 | }); | ||||||||||
| 63 | HTTP::Engine->new( | ||||||||||
| 64 | interface => { | ||||||||||
| 65 | module => 'YourFavoriteInterfaceHere', | ||||||||||
| 66 | request_handler => $mw->handler( \&handler ), | ||||||||||
| 67 | } | ||||||||||
| 68 | )->run(); | ||||||||||
| 69 | |||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||
| 71 | |||||||||||
| 72 | This middleware prints request info like Catalyst. | ||||||||||
| 73 | |||||||||||
| 74 | =head1 AUTHOR | ||||||||||
| 75 | |||||||||||
| 76 | dann | ||||||||||
| 77 | |||||||||||
| 78 | =head1 SEE ALSO | ||||||||||
| 79 | |||||||||||
| 80 | L<HTTP::Engine::Middleware> | ||||||||||
| 81 | |||||||||||