KYTProf.pm

filter: Statementstmt 95.4% 63 / 66 Branchbran 54.1% 13 / 24 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 94.1% 16 / 17 Podpod 100% 2 / 2 totaltotal 81.6% 102 / 125 CC 19 SCAR 13.1
CC
19
Cov
82%
_set_kytprof_options
7.9
_load_profiles
5.1
_diable_module_profiling
3.7
CRAP 3.7
« KYTProf/Profile/KVS.pm ↑ Summary KYTProf/Profile/TemplateEngine.pm »
1 package Plack::Middleware::Profiler::KYTProf;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use parent qw(Plack::Middleware);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 our $VERSION = '0.08';
6  
7 4 ▶use Plack::Util::Accessor qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 namespace_regex
9 ignore_class_regex
10 context_classes_regex
11 logger
12 threshold
13 remove_linefeed
14 profiles
15 mutes
16 enable_profile_if
17 4 );
18 4 ▶use Module::Load qw(load);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 my %PROFILER_SETUPED;
21  
22 3 ▶sub prepare_app {
Subroutine prepare_app: called CC=1 SCAR=0.0
Pod documented
23 3 my $self = shift;
24  
25 3 $self->_setup_enable_profile_if;
26 }
27  
28 3 ▶sub _setup_enable_profile_if {
Subroutine _setup_enable_profile_if: called CC=2 SCAR=7.1
29 3 my $self = shift;
30 3 ▶ $self->enable_profile_if( sub {1} ) unless $self->enable_profile_if;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless $self->enable_profile_if 3 0 3
31 }
32  
33 3 ▶sub _setup_profiler_if_needed {
Subroutine _setup_profiler_if_needed: called CC=3 SCAR=11.2
34 3 my ( $self, $env ) = @_;
35  
36 3 my $pid = $$;
37 3 ▶ return if $PROFILER_SETUPED{$pid};
Branch: 1 branch
BranchTrueFalseTotal
if $PROFILER_SETUPED{$pid} 0 3 3
38 3 $PROFILER_SETUPED{$pid} = 1;
39  
40 3 my $is_profiler_enabled = $self->enable_profile_if->($env);
41 3 ▶ return unless $is_profiler_enabled;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_profiler_enabled 0 3 3
42  
43 3 $self->_setup_profiler;
44 }
45  
46 3 ▶sub _setup_profiler {
Subroutine _setup_profiler: called CC=1 SCAR=0.0
47 3 my $self = shift;
48  
49 3 $self->_load_kytprof;
50 3 $self->_set_kytprof_options;
51 3 $self->_load_profiles;
52 3 $self->_diable_module_profiling;
53 }
54  
55 3 ▶sub _load_kytprof {
Subroutine _load_kytprof: called CC=1 SCAR=0.0
56 3 my $self = shift;
57 3 $self->_load_module('Devel::KYTProf');
58 }
59  
60 3 ▶sub _set_kytprof_options {
Subroutine _set_kytprof_options: called CC=7 SCAR=20.7
61 3 my $self = shift;
62 3 ▶ Devel::KYTProf->namespace_regex( $self->namespace_regex )
Branch: 1 branch
BranchTrueFalseTotal
if $self->namespace_regex 0 3 3
63 if $self->namespace_regex;
64 3 ▶ Devel::KYTProf->ignore_class_regex( $self->ignore_class_regex )
Branch: 1 branch
BranchTrueFalseTotal
if $self->ignore_class_regex 0 3 3
65 if $self->ignore_class_regex;
66 3 ▶ Devel::KYTProf->context_classes_regex( $self->context_classes_regex )
Branch: 1 branch
BranchTrueFalseTotal
if $self->context_classes_regex 0 3 3
67 if $self->context_classes_regex;
68  
69 # TODO Should we create logger adapter for popular logging framework?
70 3 ▶ Devel::KYTProf->logger( $self->logger ) if $self->logger;
Branch: 1 branch
BranchTrueFalseTotal
if $self->logger 0 3 3
71 3 ▶ Devel::KYTProf->threshold( $self->threshold ) if $self->threshold;
Branch: 1 branch
BranchTrueFalseTotal
if $self->threshold 1 2 3
72 3 ▶ Devel::KYTProf->remove_linefeed( $self->remove_linefeed )
Branch: 1 branch
BranchTrueFalseTotal
if $self->remove_linefeed 0 3 3
73 if $self->remove_linefeed;
74 }
75  
76 3 ▶sub _diable_module_profiling {
Subroutine _diable_module_profiling: called CC=3 SCAR=13.1
77 3 my $self = shift;
78 3 ▶ foreach my $module ( keys %{ $self->mutes || {} } ) {
Condition50%1/2
$self->mutes || {}
l!l
03
MC/DC0%0/1
$self->mutes || {}
$self->mutes
Truth table50%1/2
A
A= $self->mutes
Aresult
11
00
79 0 my $method = $self->mutes->{$module};
80 0 Devel::KYTProf->mute( $module, $method );
81 }
82 }
83  
84 3 ▶sub _load_profiles {
Subroutine _load_profiles: called CC=5 SCAR=16.2
85 3 my $self = shift;
86  
87 3 ▶ my $profiles ||= $self->profiles;
Condition66%2/3
my $profiles ||= $self->profiles
l!l&&r!l&&!r
021
MC/DC50%1/2
my $profiles ||= $self->profiles
my $profiles $self->profiles
Truth table66%2/3
A ||= B
A= my $profilesB= $self->profiles
ABresult
1X1
011
000
88 3 ▶ $profiles ||= [
Condition100%2/2
$profiles ||= ["Plack::Middleware::Profiler::KYTProf::Profile::TemplateEngine", "Plack::Middleware::Profiler::KYTProf::Profile::KVS"]
l!l
21
MC/DC100%1/1
$profiles ||= ["Plack::Middleware::Profiler::KYTProf::Profile::TemplateEngine", "Plack::Middleware::Profiler::KYTProf::Profile::KVS"]
$profiles
Truth table100%2/2
A
A= $profiles
Aresult
11
00
89 'Plack::Middleware::Profiler::KYTProf::Profile::TemplateEngine',
90 'Plack::Middleware::Profiler::KYTProf::Profile::KVS'
91 ];
92 3 foreach my $profile (@$profiles) {
93 4 $self->_load_module($profile);
94 4 ▶ die "profile class must implement load method"
Branch: 1 branch
BranchTrueFalseTotal
unless $profile->can("load") 0 4 4
95 unless $profile->can('load');
96 4 $profile->load;
97 }
98 }
99  
100 7 ▶sub _load_module {
Subroutine _load_module: called CC=2 SCAR=7.0
101 7 my ( $self, $module ) = @_;
102 7 ▶ eval { load $module; 1; } or die "Can't load ${module}";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &load($module); 1 } } or die "Can't load $module" 7 0 7
103 }
104  
105 3 ▶sub call {
Subroutine call: called CC=3 SCAR=12.3
Pod documented
106 3 my ( $self, $env ) = @_;
107 3 $self->_setup_profiler_if_needed($env);
108  
109 3 my $res = $self->app->($env);
110  
111 3 ▶ if ( ref($res) && ref($res) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res and ref $res eq "ARRAY") 3 0 3
Condition33%1/3
ref $res and ref $res eq "ARRAY"
!ll&&!rl&&r
003
MC/DC0%0/2
ref $res and ref $res eq "ARRAY"
ref $res ref $res eq "ARRAY"
Truth table33%1/3
A and B
A= ref $resB= ref $res eq "ARRAY"
ABresult
0X0
100
111
112 3 return $res;
113 }
114  
115 Plack::Util::response_cb(
116 $res,
117 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=0.0
118 }
119 0 );
120 }
121  
122 4 1;
123  
124 __END__
« KYTProf/Profile/KVS.pm ↑ Summary KYTProf/Profile/TemplateEngine.pm »