blib/lib/Plack/Middleware/Debug/Log4perl.pm

filter: Statementstmt 95.7% 45 / 47 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 50.0% 1 / 2 totaltotal 92.7% 64 / 69 CC 6 SCAR 7.4
CC
6
Cov
93%
run
4.0
render_list_pairs
2.1
__ANON__
2.0
CRAP 2.1
↑ Summary
1  
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Plack::Middleware::Debug::Log4perl;
5  
6 5 ▶use parent qw(Plack::Middleware::Debug::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our $VERSION = '0.04';
9  
10 5 ▶use Log::Log4perl qw(get_logger :levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Log::Log4perl::Layout;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Log::Log4perl::Level;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # let's try keeping a handle on the layout
17 5 my $timer;
18  
19 sub run
20 8 ▶{
Subroutine run: called CC=4 SCAR=13.9
Pod documented
21 8 my($self, $env, $panel) = @_;
22  
23 8 ▶ if (Log::Log4perl->initialized()) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Log::Log4perl"->initialized) 7 1 8
24  
25 7 ▶ if (my $appender = Log::Log4perl->appender_by_name('psgi_debug_panel')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $appender = 'Log::Log4perl'->appender_by_name('psgi_debug_panel')) { } 6 1 7
26  
27 6 $appender->clear();
28  
29 6 ▶ $timer->reset() if $timer;
Branch: 1 branch
BranchTrueFalseTotal
if $timer 3 3 6
30 }
31 else {
32  
33 1 my $logger = Log::Log4perl->get_logger("");
34  
35 # Define a layout
36 1 my $layout = Log::Log4perl::Layout::PatternLayout->new("%r >> %p >> %m >> %c >> at %F line %L%n");
37  
38 # Define an 'in memory' appender
39 1 my $appender = Log::Log4perl::Appender->new(
40 "Log::Log4perl::Appender::TestBuffer",
41 name => "psgi_debug_panel");
42  
43 1 $appender->layout($layout);
44  
45 1 $logger->add_appender($appender);
46 1 $logger->level($TRACE);
47  
48 # hang on to the timer, so we can reset it
49 1 $timer = $layout->{timer};
50 }
51 }
52  
53 8 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
54 8 my $res = shift;
55  
56 8 ▶ if (my $appender = Log::Log4perl->appenders()->{psgi_debug_panel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $appender = 'Log::Log4perl'->appenders->{'psgi_debug_panel'}) { } 8 0 8
57  
58 8 my $log = $appender->{appender}->{buffer};
59  
60 8 $log =~ s/ >> /\n/g;
61 8 my $list = [ split '\n', $log ];
62  
63 8 ▶ $panel->content( sub { $self->render_list_pairs($list) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
64 }
65 else {
66  
67 0 $panel->content( 'Log4perl appender not enabled' );
68 }
69 8 };
70 }
71  
72 5 my $list_template = __PACKAGE__->build_template(<<'EOTMPL');
73 <table>
74 <thead>
75 <tr>
76 <th>Time</th>
77 <th>Level</th>
78 <th>Message</th>
79 <th>Source</th>
80 <th>Line</th>
81 </tr>
82 </thead>
83 <tbody>
84 % my $i;
85 % while (@{$_[0]->{list}}) {
86 % my($time, $level, $message, $source, $line) = splice(@{$_[0]->{list}}, 0, 5);
87 <tr class="<%= ++$i % 2 ? 'plDebugOdd' : 'plDebugEven' %>">
88 <td><%= $time %></td>
89 <td><%= $level %></td>
90 <td><%= $message %></td>
91 <td><%= $source %></td>
92 <td><%= $line %></td>
93 </tr>
94 % }
95 </tbody>
96 </table>
97 EOTMPL
98  
99 8 ▶sub render_list_pairs {
Subroutine render_list_pairs: called CC=2 SCAR=7.6
Pod undocumented
100  
101 8 my ($self, $list, $sections) = @_;
102 8 ▶ if ($sections) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sections) { } 0 8 8
103 0 $self->render($list_template, { list => $list });
104 }else{
105 8 $self->render($list_template, { list => $list });
106 }
107 }
108  
109 5 1;
110 __END__
↑ Summary