← 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/ProhibitMismatchedOperators.pm
StatementsExecuted 23 statements in 811µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11117µs17µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::BEGIN@9Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@9
1118µs58µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::BEGIN@15Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@15
1118µs11µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::BEGIN@11Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@11
1118µs29µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::BEGIN@12Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@12
1117µs19µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::BEGIN@10Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@10
1117µs187µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::BEGIN@14Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@14
1116µs7µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::default_severityPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::default_severity
1112µs2µsPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::supported_parametersPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::supported_parameters
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::_get_potential_leading_operatorPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::_get_potential_leading_operator
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::_get_token_compatibilityPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::_get_token_compatibility
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::_have_stringy_xPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::_have_stringy_x
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::_is_file_operatorPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::_is_file_operator
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::applies_toPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::applies_to
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::default_themesPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::default_themes
0000s0sPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::::violatesPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::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::ProhibitMismatchedOperators;
9244µs117µs
# spent 17µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@9 which was called: # once (17µs+0s) by Module::Pluggable::Object::_require at line 9
use 5.006001;
10221µs230µs
# spent 19µs (7+11) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@10 which was called: # once (7µs+11µs) by Module::Pluggable::Object::_require at line 10
use strict;
# spent 19µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@10 # spent 11µs making 1 call to strict::import
11220µs215µs
# spent 11µs (8+4) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@11 which was called: # once (8µs+4µs) by Module::Pluggable::Object::_require at line 11
use warnings;
# spent 11µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@11 # spent 4µs making 1 call to warnings::import
12223µs250µs
# spent 29µs (8+21) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@12 which was called: # once (8µs+21µs) by Module::Pluggable::Object::_require at line 12
use Readonly;
# spent 29µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@12 # spent 21µs making 1 call to Exporter::import
13
14227µs2366µs
# spent 187µs (7+179) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@14 which was called: # once (7µs+179µs) by Module::Pluggable::Object::_require at line 14
use Perl::Critic::Utils qw{ :booleans :severities };
# spent 187µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@14 # spent 179µs making 1 call to Exporter::import
152503µs2108µs
# spent 58µs (8+50) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@15 which was called: # once (8µs+50µs) by Module::Pluggable::Object::_require at line 15
use base 'Perl::Critic::Policy';
# spent 58µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::BEGIN@15 # spent 50µs making 1 call to base::import
16
171600nsour $VERSION = '1.121';
18
19#-----------------------------------------------------------------------------
20
2112µs129µsReadonly::Scalar my $DESC => q<Mismatched operator>;
# spent 29µs making 1 call to Readonly::Scalar
2211µs121µsReadonly::Scalar my $EXPL => q<Numeric/string operators and operands should match>;
# spent 21µs making 1 call to Readonly::Scalar
23
24# token compatibility [ numeric, string ]
25113µs797µsReadonly::Hash my %TOKEN_COMPATIBILITY => (
# spent 90µs making 1 call to Readonly::Hash # spent 7µs making 6 calls to Readonly::Scalar::FETCH, avg 1µs/call
26 'PPI::Token::Number' => [$TRUE, $FALSE],
27 'PPI::Token::Symbol' => [$TRUE, $TRUE ],
28 'PPI::Token::Quote' => [$FALSE, $TRUE ],
29);
30
31Readonly::Hash my %FILE_OPERATOR_COMPATIBILITY =>
32197µs53575µs map {; "-$_" => [$TRUE, $FALSE] }
# spent 524µs making 1 call to Readonly::Hash # spent 51µs making 52 calls to Readonly::Scalar::FETCH, avg 988ns/call
33 qw< r w x o R W X O e z s f d l p S b c t u g k T B M A >;
34
3511µs122µsReadonly::Scalar my $TOKEN_COMPATIBILITY_INDEX_NUMERIC => 0;
# spent 22µs making 1 call to Readonly::Scalar
3611µs121µsReadonly::Scalar my $TOKEN_COMPATIBILITY_INDEX_STRING => 1;
# spent 21µs making 1 call to Readonly::Scalar
37
38Readonly::Hash my %OPERATOR_TYPES => (
39 # numeric
40 (
41 map { $_ => $TOKEN_COMPATIBILITY_INDEX_NUMERIC }
42 qw[ == != > >= < <= + - * / += -= *= /= ]
43 ),
44 # string
45140µs2365µs map { $_ => $TOKEN_COMPATIBILITY_INDEX_STRING }
# spent 44µs making 1 call to Readonly::Hash # spent 22µs making 22 calls to Readonly::Scalar::FETCH, avg 991ns/call
46 qw< eq ne lt gt le ge . .= >,
47);
48
49#-----------------------------------------------------------------------------
50
5114µs
# spent 2µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::supported_parameters which was called: # once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters { return () }
5211µs
# spent 7µs (6+1) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators::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_MEDIUM }
53sub default_themes { return qw< core bugs certrule > }
54sub applies_to { return 'PPI::Token::Operator' }
55
56#-----------------------------------------------------------------------------
57
58sub violates {
59 my ($self, $elem) = @_;
60
61 my $elem_text = $elem->content();
62
63 return if not exists $OPERATOR_TYPES{$elem_text};
64
65 my $leading_operator = $self->_get_potential_leading_operator($elem)
66 or return;
67
68 my $next_elem = $elem->snext_sibling() or return;
69
70 if ( $next_elem->isa('PPI::Token::Operator') ) {
71 $elem_text .= $next_elem->content();
72 $next_elem = $next_elem->snext_sibling();
73 }
74
75 return if not exists $OPERATOR_TYPES{$elem_text};
76 my $operator_type = $OPERATOR_TYPES{$elem_text};
77
78 my $leading_operator_compatibility =
79 $self->_get_token_compatibility($leading_operator);
80 my $next_compatibility = $self->_get_token_compatibility($next_elem);
81
82 return if
83 (
84 ! defined $leading_operator_compatibility
85 || $leading_operator_compatibility->[$operator_type]
86 )
87 && (
88 ! defined $next_compatibility
89 || $next_compatibility->[$operator_type]
90 );
91
92 return if
93 $operator_type
94 && defined $leading_operator_compatibility
95 && ! $leading_operator_compatibility->[$operator_type]
96 && $self->_have_stringy_x($leading_operator); # RT 54524
97
98 return $self->violation($DESC, $EXPL, $elem);
99}
100
101#-----------------------------------------------------------------------------
102
103sub _get_token_compatibility {
104 my ($self, $elem) = @_;
105
106 return $FILE_OPERATOR_COMPATIBILITY{ $elem->content() }
107 if $self->_is_file_operator($elem);
108
109 for my $class (keys %TOKEN_COMPATIBILITY) {
110 return $TOKEN_COMPATIBILITY{$class} if $elem->isa($class);
111 }
112
113 return;
114}
115
116#-----------------------------------------------------------------------------
117
118sub _have_stringy_x {
119 my ($self, $elem) = @_;
120
121 return if not $elem;
122
123 my $prev_oper = $elem->sprevious_sibling() or return;
124
125 return if not $prev_oper->isa('PPI::Token::Operator');
126 return if 'x' ne $prev_oper->content();
127
128 return !! $prev_oper->sprevious_sibling();
129}
130
131#-----------------------------------------------------------------------------
132
133sub _get_potential_leading_operator {
134 my ($self, $elem) = @_;
135
136 my $previous_element = $elem->sprevious_sibling() or return;
137
138 if ( $self->_get_token_compatibility($previous_element) ) {
139 my $previous_sibling = $previous_element->sprevious_sibling();
140 if (
141 $previous_sibling and $self->_is_file_operator($previous_sibling)
142 ) {
143 $previous_element = $previous_sibling;
144 }
145 }
146
147 return $previous_element;
148}
149
150#-----------------------------------------------------------------------------
151
152sub _is_file_operator {
153 my ($self, $elem) = @_;
154
155 return if not $elem;
156 return if not $elem->isa('PPI::Token::Operator');
157 return !! $FILE_OPERATOR_COMPATIBILITY{ $elem->content() }
158}
159
160112µs1;
161
162__END__