← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ValuesAndExpressions/ProhibitLongChainsOfMethodCalls.pm
StatementsExecuted 19 statements in 462µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::BEGIN@10Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@10
11110µs334µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::BEGIN@15Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@15
1118µs29µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::BEGIN@16Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@16
1117µs28µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::BEGIN@13Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@13
1117µs11µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::BEGIN@12Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@12
1117µs57µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::BEGIN@18Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@18
1117µs18µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::BEGIN@11Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@11
1116µs7µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::default_severityPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::default_severity
1115µs5µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::supported_parametersPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::supported_parameters
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::_max_chain_lengthPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::_max_chain_length
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::applies_toPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::applies_to
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::default_themesPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::default_themes
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::::violatesPerl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::violates
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1##############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7
8package Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls;
9
10240µs116µs
# spent 16µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11220µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@11 which was called: # once (7µs+11µs) by Module::Pluggable::Object::_require at line 11
use strict;
12219µs214µs
# spent 11µs (7+4) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@12 which was called: # once (7µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
13226µs249µs
# spent 28µs (7+21) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@13 which was called: # once (7µs+21µs) by Module::Pluggable::Object::_require at line 13
use Readonly;
14
15225µs2657µs
# spent 334µs (10+323) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@15 which was called: # once (10µs+323µs) by Module::Pluggable::Object::_require at line 15
use Perl::Critic::Utils qw{ :characters :severities };
16225µs249µs
# spent 29µs (8+20) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@16 which was called: # once (8µs+20µs) by Module::Pluggable::Object::_require at line 16
use Perl::Critic::Utils::PPI qw{ is_ppi_expression_or_generic_statement };
17
182292µs2106µs
# spent 57µs (7+50) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::BEGIN@18 which was called: # once (7µs+50µs) by Module::Pluggable::Object::_require at line 18
use base 'Perl::Critic::Policy';
19
201600nsour $VERSION = '1.121';
21
22#-----------------------------------------------------------------------------
23
2412µs129µsReadonly::Scalar my $EXPL =>
# spent 29µs making 1 call to Readonly::Scalar
25 q{Long chains of method calls indicate code that is too tightly coupled};
26
27#-----------------------------------------------------------------------------
28
29
# spent 5µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::supported_parameters which was called: # once (5µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
30 return (
31 {
3218µs name => 'max_chain_length',
33 description => 'The number of chained calls to allow.',
34 default_string => '3',
35 behavior => 'integer',
36 integer_minimum => 1,
37 },
38 );
39}
40
4112µs
# spent 7µs (6+1) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls::default_severity which was called: # once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_LOW }
42sub default_themes { return qw( core maintenance ) }
43sub applies_to { return qw{ PPI::Statement }; }
44
45#-----------------------------------------------------------------------------
46
47sub _max_chain_length {
48 my ( $self ) = @_;
49
50 return $self->{_max_chain_length};
51}
52
53#-----------------------------------------------------------------------------
54
55sub violates {
56 my ( $self, $elem, undef ) = @_;
57
58 return if not is_ppi_expression_or_generic_statement($elem);
59
60 my $chain_length = 0;
61 my $max_chain_length = $self->_max_chain_length();
62 my @children = $elem->schildren();
63 my $child = shift @children;
64
65 while ($child) {
66 # if it looks like we've got a subroutine call, drop the parameter
67 # list.
68 if (
69 $child->isa('PPI::Token::Word')
70 and @children
71 and $children[0]->isa('PPI::Structure::List')
72 ) {
73 shift @children;
74 }
75
76 if (
77 $child->isa('PPI::Token::Word')
78 or $child->isa('PPI::Token::Symbol')
79 ) {
80 if ( @children ) {
81 if ( $children[0]->isa('PPI::Token::Operator') ) {
82 if ( q{->} eq $children[0]->content() ) {
83 $chain_length++;
84 shift @children;
85 }
86 }
87 elsif ( not $children[0]->isa('PPI::Token::Structure') ) {
88 $chain_length = 0;
89 }
90 }
91 }
92 else {
93 if ($chain_length > $max_chain_length) {
94 return
95 $self->violation(
96 "Found method-call chain of length $chain_length.",
97 $EXPL,
98 $elem,
99 );
100 }
101
102 $chain_length = 0;
103 }
104
105 $child = shift @children;
106 }
107
108 if ($chain_length > $max_chain_length) {
109 return
110 $self->violation(
111 "Found method-call chain of length $chain_length.",
112 $EXPL,
113 $elem,
114 );
115 }
116
117 return;
118}
119
120
12113µs1;
122
123__END__