blib/lib/Plack/Middleware/Debug/Dancer/TemplateTimer.pm

filter: Statementstmt 46.8% 22 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 54.5% 6 / 11 Podpod 100% 2 / 2 totaltotal 46.1% 30 / 65 CC 4 SCAR 19.0
CC
4
Cov
43%
__ANON__
20.0
prepare_app
2.0
__ANON__
2.0
CRAP 6.7
↑ Summary
1 package Plack::Middleware::Debug::Dancer::TemplateTimer;
2  
3 =head1 NAME
4  
5 Plack::Middleware::Debug::Dancer::TemplateTimer - Template and layout rendering timer for Dancer
6  
7 =head1 VERSION
8  
9 0.001
10  
11 =cut
12  
13 1 our $VERSION = '0.001';
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use parent qw(Plack::Middleware::Debug::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Class::Method::Modifiers qw/install_modifier/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Time::HiRes qw/gettimeofday tv_interval/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Dancer;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 my $env_key = 'debug.dancer.templatetimer';
24  
25 0 ▶sub prepare_app {
Subroutine prepare_app: not called CC=1 SCAR=6.9
Pod documented
26  
27 0 ▶ install_modifier 'Dancer::Template::Abstract', 'around', 'layout', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 my $orig = shift;
29 0 my $start = [gettimeofday];
30 0 my $ret = $orig->(@_);
31 0 my $end = [gettimeofday];
32 Dancer::SharedData->request->env->{$env_key}->{layout} +=
33 0 tv_interval( $start, $end );
34 0 return $ret;
35 0 };
36  
37 0 ▶ install_modifier 'Dancer::Template::Abstract', 'around', 'render', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 my $orig = shift;
39 0 my $start = [gettimeofday];
40 0 my $ret = $orig->(@_);
41 0 my $end = [gettimeofday];
42 Dancer::SharedData->request->env->{$env_key}->{template} +=
43 0 tv_interval( $start, $end );
44 0 return $ret;
45 0 };
46 }
47  
48 1 my $list_template_dumped = __PACKAGE__->build_template(<<'EOTMPL');
49 <table>
50 <thead>
51 <tr>
52 <th>Key</th>
53 <th>Value</th>
54 </tr>
55 </thead>
56 <tbody>
57 % my $i;
58 % foreach my $key (qw| template layout total |) {
59 % next unless defined $_[0]->{vars}->{$key};
60 <tr>
61 <td><%= $key %></td>
62 <td><%= $_[0]->{vars}->{$key} %></td>
63 </tr>
64 % }
65 </tbody>
66 </table>
67 EOTMPL
68  
69 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
70 0 my ( $self, $env, $panel ) = @_;
71
72 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
73 0 my $res = shift;
74 0 $panel->title('Dancer::TemplateTimer');
75 0 ▶ my %vars = %{ $env->{$env_key} || {} };
Condition0%0/2
$env->{$env_key} || {}
l!l
00
MC/DC0%0/1
$env->{$env_key} || {}
$env->{$env_key}
Truth table0%0/2
A
A= $env->{$env_key}
Aresult
11
00
76 0 foreach my $key ( keys %vars ) {
77 0 $vars{total} += $vars{$key};
78 }
79 0 ▶ if ( $vars{total} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars{"total"}) 0 0 0
80 0 $panel->nav_subtitle($vars{total});
81 }
82 $panel->content(
83 0 $self->render( $list_template_dumped, { vars => \%vars } ) );
84 0 };
85 }
86  
87 1 1;
88  
89 __END__
↑ Summary