Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm |
Statements | Executed 20 statements in 774µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 109µs | 154µs | supported_parameters | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
1 | 1 | 1 | 10µs | 61µs | BEGIN@18 | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
1 | 1 | 1 | 8µs | 12µs | BEGIN@12 | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
1 | 1 | 1 | 8µs | 28µs | BEGIN@13 | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
1 | 1 | 1 | 7µs | 418µs | BEGIN@15 | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _allowed_operators_by_delimiter | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _back_quote_allowed_operators | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _double_quote_allowed_operators | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _info_for_match | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _info_for_single_character_operator | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _info_for_transliterate | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _info_for_two_character_operator | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | _single_quote_allowed_operators | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | initialize_if_enabled | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::
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::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters; | ||||
9 | |||||
10 | 2 | 42µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@10 which was called:
# once (16µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 16µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@10 |
11 | 2 | 24µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@11 which was called:
# once (7µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 18µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 19µs | 2 | 16µs | # spent 12µs (8+4) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 12µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 24µs | 2 | 48µs | # spent 28µs (8+20) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@13 which was called:
# once (8µs+20µs) by Module::Pluggable::Object::_require at line 13 # spent 28µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
14 | |||||
15 | 1 | 300ns | # spent 418µs (7+411) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@15 which was called:
# once (7µs+411µs) by Module::Pluggable::Object::_require at line 17 | ||
16 | :booleans :characters :severities :data_conversion | ||||
17 | 1 | 27µs | 2 | 828µs | }; # spent 418µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@15
# spent 411µs making 1 call to Exporter::import |
18 | 2 | 552µs | 2 | 112µs | # spent 61µs (10+51) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@18 which was called:
# once (10µs+51µs) by Module::Pluggable::Object::_require at line 18 # spent 61µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::BEGIN@18
# spent 51µs making 1 call to base::import |
19 | |||||
20 | 1 | 600ns | our $VERSION = '1.121'; | ||
21 | |||||
22 | #----------------------------------------------------------------------------- | ||||
23 | |||||
24 | 1 | 2µs | 1 | 46µs | Readonly::Hash my %DESCRIPTIONS => ( # spent 46µs making 1 call to Readonly::Hash |
25 | $QUOTE => q{Single-quote used as quote-like operator delimiter}, | ||||
26 | $DQUOTE => q{Double-quote used as quote-like operator delimiter}, | ||||
27 | $BACKTICK => q{Back-quote (back-tick) used as quote-like operator delimiter}, | ||||
28 | ); | ||||
29 | |||||
30 | 1 | 1µs | 1 | 23µs | Readonly::Scalar my $EXPL => # spent 23µs making 1 call to Readonly::Scalar |
31 | q{Using quotes as delimiters for quote-like operators obfuscates code}; | ||||
32 | |||||
33 | 1 | 1µs | 1 | 23µs | Readonly::Array my @OPERATORS => qw{ m q qq qr qw qx s tr y }; # spent 23µs making 1 call to Readonly::Array |
34 | |||||
35 | 1 | 2µs | 1 | 29µs | Readonly::Hash my %INFO_RETRIEVERS_BY_PPI_CLASS => ( # spent 29µs making 1 call to Readonly::Hash |
36 | 'PPI::Token::Quote::Literal' => \&_info_for_single_character_operator, | ||||
37 | 'PPI::Token::Quote::Interpolate' => \&_info_for_two_character_operator, | ||||
38 | 'PPI::Token::QuoteLike::Command' => \&_info_for_two_character_operator, | ||||
39 | 'PPI::Token::QuoteLike::Regexp' => \&_info_for_two_character_operator, | ||||
40 | 'PPI::Token::QuoteLike::Words' => \&_info_for_two_character_operator, | ||||
41 | 'PPI::Token::Regexp::Match' => \&_info_for_match, | ||||
42 | 'PPI::Token::Regexp::Substitute' => \&_info_for_single_character_operator, | ||||
43 | 'PPI::Token::Regexp::Transliterate' => \&_info_for_transliterate, | ||||
44 | ); | ||||
45 | |||||
46 | #----------------------------------------------------------------------------- | ||||
47 | |||||
48 | # spent 154µs (109+45) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::supported_parameters which was called:
# once (109µs+45µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
49 | return ( | ||||
50 | { | ||||
51 | 1 | 69µs | 34 | 45µs | name => 'single_quote_allowed_operators', # spent 37µs making 27 calls to Readonly::Array::FETCH, avg 1µs/call
# spent 4µs making 4 calls to Readonly::Scalar::FETCH, avg 1µs/call
# spent 4µs making 3 calls to Readonly::Array::FETCHSIZE, avg 1µs/call |
52 | description => | ||||
53 | 'The operators to allow single-quotes as delimiters for.', | ||||
54 | default_string => 'm s qr qx', | ||||
55 | behavior => 'enumeration', | ||||
56 | enumeration_values => [ @OPERATORS ], | ||||
57 | enumeration_allow_multiple_values => 1, | ||||
58 | }, | ||||
59 | { | ||||
60 | name => 'double_quote_allowed_operators', | ||||
61 | description => | ||||
62 | 'The operators to allow double-quotes as delimiters for.', | ||||
63 | default_string => $EMPTY, | ||||
64 | behavior => 'enumeration', | ||||
65 | enumeration_values => [ @OPERATORS ], | ||||
66 | enumeration_allow_multiple_values => 1, | ||||
67 | }, | ||||
68 | { | ||||
69 | name => 'back_quote_allowed_operators', | ||||
70 | description => | ||||
71 | 'The operators to allow back-quotes (back-ticks) as delimiters for.', | ||||
72 | default_string => $EMPTY, | ||||
73 | behavior => 'enumeration', | ||||
74 | enumeration_values => [ @OPERATORS ], | ||||
75 | enumeration_allow_multiple_values => 1, | ||||
76 | }, | ||||
77 | ); | ||||
78 | } | ||||
79 | |||||
80 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
81 | sub default_themes { return qw( core maintenance ) } | ||||
82 | |||||
83 | sub applies_to { | ||||
84 | return qw{ | ||||
85 | PPI::Token::Quote::Interpolate | ||||
86 | PPI::Token::Quote::Literal | ||||
87 | PPI::Token::QuoteLike::Command | ||||
88 | PPI::Token::QuoteLike::Regexp | ||||
89 | PPI::Token::QuoteLike::Words | ||||
90 | PPI::Token::Regexp::Match | ||||
91 | PPI::Token::Regexp::Substitute | ||||
92 | PPI::Token::Regexp::Transliterate | ||||
93 | }; | ||||
94 | } | ||||
95 | |||||
96 | #----------------------------------------------------------------------------- | ||||
97 | |||||
98 | sub initialize_if_enabled { | ||||
99 | my ($self, $config) = @_; | ||||
100 | |||||
101 | $self->{_allowed_operators_by_delimiter} = { | ||||
102 | $QUOTE => $self->_single_quote_allowed_operators(), | ||||
103 | $DQUOTE => $self->_double_quote_allowed_operators(), | ||||
104 | $BACKTICK => $self->_back_quote_allowed_operators(), | ||||
105 | }; | ||||
106 | |||||
107 | return $TRUE; | ||||
108 | } | ||||
109 | |||||
110 | #----------------------------------------------------------------------------- | ||||
111 | |||||
112 | sub _single_quote_allowed_operators { | ||||
113 | my ( $self ) = @_; | ||||
114 | |||||
115 | return $self->{_single_quote_allowed_operators}; | ||||
116 | } | ||||
117 | |||||
118 | sub _double_quote_allowed_operators { | ||||
119 | my ( $self ) = @_; | ||||
120 | |||||
121 | return $self->{_double_quote_allowed_operators}; | ||||
122 | } | ||||
123 | |||||
124 | sub _back_quote_allowed_operators { | ||||
125 | my ( $self ) = @_; | ||||
126 | |||||
127 | return $self->{_back_quote_allowed_operators}; | ||||
128 | } | ||||
129 | |||||
130 | sub _allowed_operators_by_delimiter { | ||||
131 | my ( $self ) = @_; | ||||
132 | |||||
133 | return $self->{_allowed_operators_by_delimiter}; | ||||
134 | } | ||||
135 | |||||
136 | #----------------------------------------------------------------------------- | ||||
137 | |||||
138 | sub violates { | ||||
139 | my ( $self, $elem, undef ) = @_; | ||||
140 | |||||
141 | my $info_retriever = $INFO_RETRIEVERS_BY_PPI_CLASS{ ref $elem }; | ||||
142 | return if not $info_retriever; | ||||
143 | |||||
144 | my ($operator, $delimiter) = $info_retriever->( $elem ); | ||||
145 | |||||
146 | my $allowed_operators = | ||||
147 | $self->_allowed_operators_by_delimiter()->{$delimiter}; | ||||
148 | return if not $allowed_operators; | ||||
149 | |||||
150 | if ( not $allowed_operators->{$operator} ) { | ||||
151 | return $self->violation( $DESCRIPTIONS{$delimiter}, $EXPL, $elem ); | ||||
152 | } | ||||
153 | |||||
154 | return; | ||||
155 | } | ||||
156 | |||||
157 | #----------------------------------------------------------------------------- | ||||
158 | |||||
159 | sub _info_for_single_character_operator { | ||||
160 | my ( $elem ) = @_; | ||||
161 | |||||
162 | ## no critic (ProhibitParensWithBuiltins) | ||||
163 | return ( substr ($elem, 0, 1), substr ($elem, 1, 1) ); | ||||
164 | ## use critic | ||||
165 | } | ||||
166 | |||||
167 | #----------------------------------------------------------------------------- | ||||
168 | |||||
169 | sub _info_for_two_character_operator { | ||||
170 | my ( $elem ) = @_; | ||||
171 | |||||
172 | ## no critic (ProhibitParensWithBuiltins) | ||||
173 | return ( substr ($elem, 0, 2), substr ($elem, 2, 1) ); | ||||
174 | ## use critic | ||||
175 | } | ||||
176 | |||||
177 | #----------------------------------------------------------------------------- | ||||
178 | |||||
179 | sub _info_for_match { | ||||
180 | my ( $elem ) = @_; | ||||
181 | |||||
182 | if ( $elem =~ m/ ^ m /xms ) { | ||||
183 | return ('m', substr $elem, 1, 1); | ||||
184 | } | ||||
185 | |||||
186 | return ('m', q{/}); | ||||
187 | } | ||||
188 | |||||
189 | #----------------------------------------------------------------------------- | ||||
190 | |||||
191 | sub _info_for_transliterate { | ||||
192 | my ( $elem ) = @_; | ||||
193 | |||||
194 | if ( $elem =~ m/ ^ tr /xms ) { | ||||
195 | return ('tr', substr $elem, 2, 1); | ||||
196 | } | ||||
197 | |||||
198 | return ('y', substr $elem, 1, 1); | ||||
199 | } | ||||
200 | |||||
201 | |||||
202 | 1 | 8µs | 1; | ||
203 | |||||
204 | __END__ |