File Coverage

blib/lib/Exception/Reporter/Summarizer/PlackRequest.pm
Criterion Covered Total %
statement 18 33 54.5
branch 0 2 0.0
condition 1 2 50.0
subroutine 6 10 60.0
pod 0 4 0.0
total 25 51 49.0


line stmt bran cond sub pod time code
1 1     1   427 use strict;
  1         1  
  1         23  
2 1     1   3 use warnings;
  1         1  
  1         42  
3             package Exception::Reporter::Summarizer::PlackRequest;
4             $Exception::Reporter::Summarizer::PlackRequest::VERSION = '0.001';
5 1     1   336 use parent 'Exception::Reporter::Summarizer';
  1         196  
  1         5  
6             # ABSTRACT: a summarizer for Plack::Request objects
7              
8 1     1   996 use Plack::Request;
  1         48095  
  1         29  
9              
10             #pod =head1 OVERVIEW
11             #pod
12             #pod If added as a summarizer to an L, this plugin will
13             #pod summarize L objects, adding a summary for the request.
14             #pod
15             #pod =cut
16              
17 1     1   395 use Try::Tiny;
  1         1448  
  1         284  
18              
19             sub new {
20 1     1 0 308 my ($class, $arg) = @_;
21 1   50     7 $arg ||= {};
22              
23 1         5 return bless { } => $class;
24             }
25              
26             sub can_summarize {
27 0     0 0   my ($self, $entry) = @_;
28 0     0     return try { $entry->[1]->isa('Plack::Request') };
  0            
29             }
30              
31             sub summarize {
32 0     0 0   my ($self, $entry) = @_;
33 0           my ($name, $req, $arg) = @$entry;
34              
35 0           my @summaries;
36              
37 0           push @summaries, $self->summarize_request($req);
38              
39 0           return @summaries;
40             }
41              
42             sub summarize_request {
43 0     0 0   my ($self, $req) = @_;
44              
45             my %to_dump = map {
46 0 0         $_ => defined($req->$_) ? ($req->$_ . "") : undef,
  0            
47             } qw(
48             address
49             content_length
50             content_type
51             content_encoding
52             remote_host
53             protocol
54             method
55             port
56             user
57             request_uri
58             path_info
59             path
60             query_string
61             referer
62             user_agent
63             script_name
64             scheme
65             secure
66             );
67              
68 0           $to_dump{upload} = [ $req->upload ];
69 0           $to_dump{cookies} = $req->cookies;
70              
71             return {
72             filename => 'request.txt',
73 0           %{ $self->dump(\%to_dump, { basename => 'request' }) },
  0            
74             ident => 'plack request',
75             };
76             }
77              
78             1;
79              
80             __END__