← 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/ProhibitCommaSeparatedStatements.pm
StatementsExecuted 20 statements in 634µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::BEGIN@10Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@10
11114µs16µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::supported_parametersPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::supported_parameters
1119µs30µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::BEGIN@17Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@17
1118µs12µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::BEGIN@12Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@12
1117µs28µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::BEGIN@13Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@13
1117µs58µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::BEGIN@19Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@19
1117µs615µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::BEGIN@16Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@16
1117µs18µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::BEGIN@11Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@11
1116µs7µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::default_severityPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::default_severity
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::_is_direct_part_of_map_or_grep_blockPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::_is_direct_part_of_map_or_grep_block
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::_is_last_statement_in_a_blockPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::_is_last_statement_in_a_block
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::_is_parent_a_constructor_or_listPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::_is_parent_a_constructor_or_list
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::_is_parent_a_for_loopPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::_is_parent_a_for_loop
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::_succeeding_commas_are_list_element_separatorsPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::_succeeding_commas_are_list_element_separators
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::applies_toPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::applies_to
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::default_themesPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::default_themes
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::::violatesPerl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::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::ProhibitCommaSeparatedStatements;
9
10239µs116µs
# spent 16µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11224µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@11 which was called: # once (7µs+11µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 18µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@11 # spent 11µs making 1 call to strict::import
12218µs215µs
# spent 12µs (8+4) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@12 which was called: # once (8µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
13224µs248µs
# spent 28µs (7+21) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@13 which was called: # once (7µs+21µs) by Module::Pluggable::Object::_require at line 13
use Readonly;
14
15
16225µs21.22ms
# spent 615µs (7+608) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@16 which was called: # once (7µs+608µs) by Module::Pluggable::Object::_require at line 16
use Perl::Critic::Utils qw{ :booleans :characters :severities :classification };
# spent 615µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@16 # spent 608µs making 1 call to Exporter::import
17228µs252µs
# spent 30µs (9+21) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@17 which was called: # once (9µs+21µs) by Module::Pluggable::Object::_require at line 17
use Perl::Critic::Utils::PPI qw{ is_ppi_statement_subclass };
18
192456µs2108µs
# spent 58µs (7+51) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@19 which was called: # once (7µs+51µs) by Module::Pluggable::Object::_require at line 19
use base 'Perl::Critic::Policy';
# spent 58µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::BEGIN@19 # spent 51µs making 1 call to base::import
20
211600nsour $VERSION = '1.121';
22
23#-----------------------------------------------------------------------------
24
2512µs130µsReadonly::Scalar my $DESC => q{Comma used to separate statements};
# spent 30µs making 1 call to Readonly::Scalar
2612µs143µsReadonly::Scalar my $EXPL => [ 68, 71 ];
# spent 43µs making 1 call to Readonly::Scalar
27
28#-----------------------------------------------------------------------------
29
30
# spent 16µs (14+2) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::supported_parameters which was called: # once (14µs+2µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
31 return (
32 {
33111µs22µs name => 'allow_last_statement_to_be_comma_separated_in_map_and_grep',
# spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 950ns/call
34 description => 'Allow map and grep blocks to return lists.',
35 default_string => $FALSE,
36 behavior => 'boolean',
37 },
38 );
39}
40
4112µs
# spent 7µs (6+1) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements::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_HIGH }
42sub default_themes { return qw( core bugs pbp certrule ) }
43sub applies_to { return 'PPI::Statement' }
44
45#-----------------------------------------------------------------------------
46
47sub violates {
48 my ( $self, $elem, undef ) = @_;
49
50 # Grrr... PPI instantiates non-leaf nodes in its class hierarchy...
51 return if is_ppi_statement_subclass($elem);
52
53 # Now, if PPI hasn't introduced any new PPI::Statement subclasses, we've
54 # got an element who's class really is PPI::Statement.
55
56 return if _is_parent_a_constructor_or_list($elem);
57 return if _is_parent_a_for_loop($elem);
58
59 if (
60 $self->{_allow_last_statement_to_be_comma_separated_in_map_and_grep}
61 ) {
62 return if not _is_direct_part_of_map_or_grep_block($elem);
63 }
64
65 foreach my $child ( $elem->schildren() ) {
66 if (
67 not $self->{_allow_last_statement_to_be_comma_separated_in_map_and_grep}
68 and not _is_last_statement_in_a_block($child)
69 ) {
70 if ( $child->isa('PPI::Token::Word') ) {
71 return if _succeeding_commas_are_list_element_separators($child);
72 }
73 elsif ( $child->isa('PPI::Token::Operator') ) {
74 if ( $child->content() eq $COMMA ) {
75 return $self->violation($DESC, $EXPL, $elem);
76 }
77 }
78 }
79 }
80
81 return;
82}
83
84sub _is_parent_a_constructor_or_list {
85 my ($elem) = @_;
86
87 my $parent = $elem->parent();
88
89 return if not $parent;
90
91 return (
92 $parent->isa('PPI::Structure::Constructor')
93 or $parent->isa('PPI::Structure::List')
94 );
95}
96
97sub _is_parent_a_for_loop {
98 my ($elem) = @_;
99
100 my $parent = $elem->parent();
101
102 return if not $parent;
103
104 return if not $parent->isa('PPI::Structure::For');
105
106 return 1 == scalar $parent->schildren(); # Multiple means C-style loop.
107}
108
109sub _is_direct_part_of_map_or_grep_block {
110 my ($elem) = @_;
111
112 my $parent = $elem->parent();
113 return if not $parent;
114 return if not $parent->isa('PPI::Structure::Block');
115
116 my $block_prior_sibling = $parent->sprevious_sibling();
117 return if not $block_prior_sibling;
118 return if not $block_prior_sibling->isa('PPI::Token::Word');
119
120 return $block_prior_sibling eq 'map' || $block_prior_sibling eq 'grep';
121}
122
123sub _is_last_statement_in_a_block {
124 my ($elem) = @_;
125
126 my $parent = $elem->parent();
127 return if not $parent;
128 return if not $parent->isa('PPI::Structure::Block');
129
130 my $next_sibling = $elem->snext_sibling();
131 return if not $next_sibling;
132
133 return 1;
134}
135
136sub _succeeding_commas_are_list_element_separators {
137 my ($elem) = @_;
138
139 if (
140 is_perl_builtin_with_zero_and_or_one_arguments($elem)
141 and not is_perl_builtin_with_multiple_arguments($elem)
142 ) {
143 return;
144 }
145
146 my $sibling = $elem->snext_sibling();
147
148 return 1 if not $sibling; # There won't be any succeeding commas.
149
150 return not $sibling->isa('PPI::Structure::List');
151}
152
15313µs1;
154
155__END__