blib/lib/Plack/Middleware/Debug/Profiler/NYTProf.pm

filter: Statementstmt 36.6% 22 / 60 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 53.8% 7 / 13 Podpod 75.0% 3 / 4 totaltotal 28.3% 32 / 113 CC 17 SCAR 37.9
CC
17
Cov
24%
prepare_app
110.0
call
20.0
report
20.0
CRAP 44.2
↑ Summary
1 package Plack::Middleware::Debug::Profiler::NYTProf;
2 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Plack::Util::Accessor qw(root exclude base_URL minimal no_merge_evals);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use parent 'Plack::Middleware::Debug::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our $VERSION = '0.06';
12  
13 0 ▶sub prepare_app {
Subroutine prepare_app: not called CC=10 SCAR=47.0
Pod documented
14 0 my $self = shift;
15 0 ▶ $self->root($self->root || '/tmp');
Condition0%0/2
$self->root || '/tmp'
l!l
00
MC/DC0%0/1
$self->root || '/tmp'
$self->root
Truth table0%0/2
A
A= $self->root
Aresult
11
00
16 0 ▶ $self->base_URL($self->base_URL || '');
Condition0%0/2
$self->base_URL || ''
l!l
00
MC/DC0%0/1
$self->base_URL || ''
$self->base_URL
Truth table0%0/2
A
A= $self->base_URL
Aresult
11
00
17 0 ▶ $self->minimal($self->minimal || '0');
Condition0%0/2
$self->minimal || '0'
l!l
00
MC/DC0%0/1
$self->minimal || '0'
$self->minimal
Truth table0%0/2
A
A= $self->minimal
Aresult
11
00
18 0 ▶ $self->no_merge_evals($self->no_merge_evals || '0');
Condition0%0/2
$self->no_merge_evals || '0'
l!l
00
MC/DC0%0/1
$self->no_merge_evals || '0'
$self->no_merge_evals
Truth table0%0/2
A
A= $self->no_merge_evals
Aresult
11
00
19 0 $self->{files} = Plack::App::File->new(root => $self->root);
20  
21 0 ▶ unless(-d $self->root){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->root) 0 0 0
22 0 ▶ make_path($self->root) or die "Cannot create directory " . $self->root;
Branch: 1 branch
BranchTrueFalseTotal
make_path($self->root) or die 'Cannot create directory ' . $self->root 0 0 0
23 }
24  
25 # start=begin - start immediately (the default)
26 # start=init - start at beginning of INIT phase (after compilation)
27 # start=end - start at beginning of END phase
28 # start=no - don't automatically start
29 0 ▶ $ENV{NYTPROF} ||= "addpid=1:start=begin:file=".$self->root."/nytprof.null.out";
Condition0%0/2
$ENV{"NYTPROF"} ||= 'addpid=1:start=begin:file=' . $self->root . '/nytprof.null.out'
l!l
00
MC/DC0%0/1
$ENV{"NYTPROF"} ||= 'addpid=1:start=begin:file=' . $self->root . '/nytprof.null.out'
$ENV{"NYTPROF"}
Truth table0%0/2
A
A= $ENV{"NYTPROF"}
Aresult
11
00
30 0 require Devel::NYTProf::Core;
31 0 require Devel::NYTProf;
32  
33 0 ▶ $self->exclude($self->exclude || [qw(.*\.css .*\.png .*\.ico .*\.js)]);
Condition0%0/2
$self->exclude || ['.*\\.css', '.*\\.png', '.*\\.ico', '.*\\.js']
l!l
00
MC/DC0%0/1
$self->exclude || ['.*\\.css', '.*\\.png', '.*\\.ico', '.*\\.js']
$self->exclude
Truth table0%0/2
A
A= $self->exclude
Aresult
11
00
34 0 ▶ Carp::croak "exclude not an array" if ref($self->exclude) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->exclude ne "ARRAY" 0 0 0
35 }
36  
37 0 ▶sub call {
Subroutine call: not called CC=4 SCAR=30.0
Pod documented
38 0 my($self, $env) = @_;
39 0 my $panel = $self->default_panel;
40  
41 0 ▶ if ($env->{PATH_INFO} =~ m!nytprofhtml!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"PATH_INFO"} =~ /nytprofhtml/) 0 0 0
42 0 $env->{'plack.debug.disabled'} = 1;
43 0 return $self->{files}->call($env);
44 }
45  
46 0 foreach my $pattern (@{$self->exclude}) {
47 0 ▶ if ($env->{PATH_INFO} =~ m!^$pattern$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"PATH_INFO"} =~ /^$pattern$/) 0 0 0
48 0 return $self->SUPER::call($env);
49 }
50 }
51  
52 # $ENV{NYTPROF}'s addpid=1 will append ".$$" to the file
53 0 DB::enable_profile($self->root."/nytprof.out");
54  
55 0 my $res = $self->SUPER::call($env);
56 0 DB::disable_profile();
57 0 DB::enable_profile($self->root."/nytprof.null.out");
58 0 DB::disable_profile();
59  
60 0 $self->report($env);
61 0 return $res;
62 }
63  
64 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
65 0 my($self, $env, $panel) = @_;
66 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
67 0 my $res = shift;
68 0 ▶ $panel->nav_subtitle(join ', ', 'OK', ( $self->minimal ? 'Minimal' : () ));
Branch: 1 branch
BranchTrueFalseTotal
$self->minimal ? : 0 0 0
69 0 $panel->content('<a href="'.$self->base_URL.'/nytprofhtml.'.$$.'/index.html" target="_blank">(open in a new window)</a><br>
70 <iframe src ="'.$self->base_URL.'/nytprofhtml.'.$$.'/index.html" width="100%" height="100%">
71 <p>Your browser does not support iframes.</p>
72 </iframe>');
73 0 };
74 }
75  
76 0 ▶sub report {
Subroutine report: not called CC=4 SCAR=30.0
Pod undocumented
77 0 my ( $self, $env ) = @_;
78 0 ▶ if ( -f $self->root . "/nytprof.out.$$" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $self->root . "/nytprof.out.${$}") 0 0 0
79 0 ▶ system "nytprofhtml"
Branch: 2 branches
BranchTrueFalseTotal
$self->minimal ? : 0 0 0
$self->no_merge_evals ? : 0 0 0
80 , ( $self->minimal ? '--minimal' : () )
81 , ( $self->no_merge_evals ? '--no-mergeevals' : () )
82 , "-f", $self->root . "/nytprof.out.$$"
83 , "-o", $self->root . "/nytprofhtml.$$";
84 }
85 }
86  
87 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
88 0 DB::finish_profile();
89 }
90  
91 1 1;
92 __END__
↑ Summary