Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ControlStructures/ProhibitNegativeExpressionsInUnlessAndUntilConditions.pm |
Statements | Executed 20 statements in 590µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 18µs | 18µs | BEGIN@10 | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 11µs | 15µs | BEGIN@12 | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 8µs | 29µs | BEGIN@14 | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 8µs | 395µs | BEGIN@13 | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 8µs | 607µs | BEGIN@16 | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 8µs | 68µs | BEGIN@18 | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 7µs | 19µs | BEGIN@11 | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
0 | 0 | 0 | 0s | 0s | _get_condition_elements | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
0 | 0 | 0 | 0s | 0s | _get_negative_operators | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
0 | 0 | 0 | 0s | 0s | _is_negative_operator | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
0 | 0 | 0 | 0s | 0s | _violation_for_operator | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ############################################################################## | ||||
2 | # $URL$ | ||||
3 | # $Date$ | ||||
4 | # $Author$ | ||||
5 | # $Revision$ | ||||
6 | ############################################################################## | ||||
7 | |||||
8 | package Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions; | ||||
9 | |||||
10 | 2 | 41µs | 1 | 18µs | # spent 18µs within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@10 which was called:
# once (18µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 18µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@10 |
11 | 2 | 21µs | 2 | 31µs | # spent 19µs (7+12) within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@11 which was called:
# once (7µs+12µs) by Module::Pluggable::Object::_require at line 11 # spent 19µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 19µs | # spent 15µs (11+4) within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@12 which was called:
# once (11µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 15µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 24µs | 2 | 783µs | # spent 395µs (8+388) within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@13 which was called:
# once (8µs+388µs) by Module::Pluggable::Object::_require at line 13 # spent 395µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@13
# spent 388µs making 1 call to English::import |
14 | 2 | 25µs | 2 | 49µs | # spent 29µs (8+20) within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@14 which was called:
# once (8µs+20µs) by Module::Pluggable::Object::_require at line 14 # spent 29µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@14
# spent 20µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 26µs | 2 | 1.21ms | # spent 607µs (8+599) within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@16 which was called:
# once (8µs+599µs) by Module::Pluggable::Object::_require at line 16 # spent 607µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@16
# spent 599µs making 1 call to Exporter::import |
17 | |||||
18 | 2 | 412µs | 2 | 128µs | # spent 68µs (8+60) within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@18 which was called:
# once (8µs+60µs) by Module::Pluggable::Object::_require at line 18 # spent 68µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::BEGIN@18
# spent 60µs making 1 call to base::import |
19 | |||||
20 | 1 | 600ns | our $VERSION = '1.121'; | ||
21 | |||||
22 | #----------------------------------------------------------------------------- | ||||
23 | |||||
24 | 1 | 3µs | 1 | 51µs | Readonly::Scalar my $EXPL => [99]; # spent 51µs making 1 call to Readonly::Scalar |
25 | |||||
26 | #----------------------------------------------------------------------------- | ||||
27 | |||||
28 | 1 | 4µs | # spent 2µs within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
29 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
30 | sub default_themes { return qw( core maintenance pbp ) } | ||||
31 | sub applies_to { return 'PPI::Token::Word' } | ||||
32 | |||||
33 | #----------------------------------------------------------------------------- | ||||
34 | |||||
35 | sub violates { | ||||
36 | my ( $self, $token, undef ) = @_; | ||||
37 | |||||
38 | return if $token ne 'until' && $token ne 'unless'; | ||||
39 | |||||
40 | return if is_hash_key($token); | ||||
41 | return if is_subroutine_name($token); | ||||
42 | return if is_method_call($token); | ||||
43 | return if is_included_module_name($token); | ||||
44 | |||||
45 | return | ||||
46 | map | ||||
47 | { $self->_violation_for_operator( $_, $token ) } | ||||
48 | _get_negative_operators( $token ); | ||||
49 | } | ||||
50 | |||||
51 | #----------------------------------------------------------------------------- | ||||
52 | |||||
53 | sub _get_negative_operators { | ||||
54 | my ($token) = @_; | ||||
55 | |||||
56 | my @operators; | ||||
57 | foreach my $element ( _get_condition_elements($token) ) { | ||||
58 | if ( $element->isa('PPI::Node') ) { | ||||
59 | my $operators = $element->find( \&_is_negative_operator ); | ||||
60 | if ($operators) { | ||||
61 | push @operators, @{$operators}; | ||||
62 | } | ||||
63 | } | ||||
64 | else { | ||||
65 | if ( _is_negative_operator( undef, $element ) ) { | ||||
66 | push @operators, $element; | ||||
67 | } | ||||
68 | } | ||||
69 | } | ||||
70 | |||||
71 | return @operators; | ||||
72 | } | ||||
73 | |||||
74 | #----------------------------------------------------------------------------- | ||||
75 | |||||
76 | sub _get_condition_elements { | ||||
77 | my ($token) = @_; | ||||
78 | |||||
79 | my $statement = $token->statement(); | ||||
80 | return if not $statement; | ||||
81 | |||||
82 | if ($statement->isa('PPI::Statement::Compound')) { | ||||
83 | my $condition = $token->snext_sibling(); | ||||
84 | |||||
85 | return if not $condition; | ||||
86 | return if not $condition->isa('PPI::Structure::Condition'); | ||||
87 | |||||
88 | return ( $condition ); | ||||
89 | } | ||||
90 | |||||
91 | my @condition_elements; | ||||
92 | my $element = $token; | ||||
93 | while ( | ||||
94 | $element = $element->snext_sibling() | ||||
95 | and $element ne $SCOLON | ||||
96 | ) { | ||||
97 | push @condition_elements, $element; | ||||
98 | } | ||||
99 | |||||
100 | return @condition_elements; | ||||
101 | } | ||||
102 | |||||
103 | #----------------------------------------------------------------------------- | ||||
104 | |||||
105 | 1 | 4µs | 2 | 46µs | Readonly::Hash my %NEGATIVE_OPERATORS => hashify( # spent 40µs making 1 call to Readonly::Hash
# spent 5µs making 1 call to Perl::Critic::Utils::hashify |
106 | qw/ | ||||
107 | ! not | ||||
108 | !~ ne != | ||||
109 | < > <= >= <=> | ||||
110 | lt gt le ge cmp | ||||
111 | / | ||||
112 | ); | ||||
113 | |||||
114 | sub _is_negative_operator { | ||||
115 | my (undef, $element) = @_; | ||||
116 | |||||
117 | return | ||||
118 | $element->isa('PPI::Token::Operator') | ||||
119 | && $NEGATIVE_OPERATORS{$element}; | ||||
120 | } | ||||
121 | |||||
122 | #----------------------------------------------------------------------------- | ||||
123 | |||||
124 | sub _violation_for_operator { | ||||
125 | my ($self, $operator, $control_structure) = @_; | ||||
126 | |||||
127 | return | ||||
128 | $self->violation( | ||||
129 | qq<Found "$operator" in condition for an "$control_structure">, | ||||
130 | $EXPL, | ||||
131 | $control_structure, | ||||
132 | ); | ||||
133 | } | ||||
134 | |||||
135 | 1 | 6µs | 1; | ||
136 | |||||
137 | #----------------------------------------------------------------------------- | ||||
138 | |||||
139 | __END__ |