Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/RegularExpressions/ProhibitFixedStringMatches.pm |
Statements | Executed 23 statements in 503µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 19µs | 19µs | BEGIN@10 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 12µs | 16µs | BEGIN@12 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 8µs | 37µs | BEGIN@16 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 8µs | 28µs | BEGIN@13 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 7µs | 375µs | BEGIN@15 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 7µs | 61µs | BEGIN@20 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 7µs | 183µs | BEGIN@18 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
1 | 1 | 1 | 1µs | 1µs | CORE:qr (opcode) | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::
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::RegularExpressions::ProhibitFixedStringMatches; | ||||
9 | |||||
10 | 2 | 40µs | 1 | 19µs | # spent 19µs within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@10 which was called:
# once (19µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 19µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@10 |
11 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::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::RegularExpressions::ProhibitFixedStringMatches::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 20µs | # spent 16µs (12+4) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@12 which was called:
# once (12µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 16µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 26µs | 2 | 49µs | # spent 28µs (8+21) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@13 which was called:
# once (8µs+21µs) by Module::Pluggable::Object::_require at line 13 # spent 28µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@13
# spent 21µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 23µs | 2 | 743µs | # spent 375µs (7+368) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@15 which was called:
# once (7µs+368µs) by Module::Pluggable::Object::_require at line 15 # spent 375µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@15
# spent 368µs making 1 call to English::import |
16 | 2 | 23µs | 2 | 65µs | # spent 37µs (8+29) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@16 which was called:
# once (8µs+29µs) by Module::Pluggable::Object::_require at line 16 # spent 37µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@16
# spent 29µs making 1 call to Exporter::import |
17 | |||||
18 | 2 | 24µs | 2 | 359µs | # spent 183µs (7+176) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@18 which was called:
# once (7µs+176µs) by Module::Pluggable::Object::_require at line 18 # spent 183µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@18
# spent 176µs making 1 call to Exporter::import |
19 | |||||
20 | 2 | 303µs | 2 | 115µs | # spent 61µs (7+54) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@20 which was called:
# once (7µs+54µs) by Module::Pluggable::Object::_require at line 20 # spent 61µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::BEGIN@20
# spent 54µs making 1 call to base::import |
21 | |||||
22 | 1 | 600ns | our $VERSION = '1.121'; | ||
23 | |||||
24 | #----------------------------------------------------------------------------- | ||||
25 | |||||
26 | 1 | 2µs | 1 | 29µs | Readonly::Scalar my $DESC => q{Use 'eq' or hash instead of fixed-pattern regexps}; # spent 29µs making 1 call to Readonly::Scalar |
27 | 1 | 2µs | 1 | 42µs | Readonly::Scalar my $EXPL => [271,272]; # spent 42µs making 1 call to Readonly::Scalar |
28 | |||||
29 | 1 | 6µs | 2 | 22µs | Readonly::Scalar my $RE_METACHAR => qr/[\\#\$()*+.?\@\[\]^{|}]/xms; # spent 21µs making 1 call to Readonly::Scalar
# spent 1µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::CORE:qr |
30 | |||||
31 | #----------------------------------------------------------------------------- | ||||
32 | |||||
33 | 1 | 5µs | # spent 2µs within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
34 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
35 | sub default_themes { return qw( core pbp performance ) } | ||||
36 | sub applies_to { return qw(PPI::Token::Regexp::Match | ||||
37 | PPI::Token::Regexp::Substitute | ||||
38 | PPI::Token::QuoteLike::Regexp) } | ||||
39 | |||||
40 | #----------------------------------------------------------------------------- | ||||
41 | |||||
42 | sub violates { | ||||
43 | my ( $self, $elem, $doc ) = @_; | ||||
44 | |||||
45 | my $re = $elem->get_match_string(); | ||||
46 | |||||
47 | # only flag regexps that are anchored front and back | ||||
48 | if ($re =~ m{\A \s* | ||||
49 | (\\A|\^) # front anchor == $1 | ||||
50 | (.*?) | ||||
51 | (\\z|\$) # end anchor == $2 | ||||
52 | \s* \z}xms) { | ||||
53 | |||||
54 | my ($front_anchor, $words, $end_anchor) = ($1, $2, $3); | ||||
55 | |||||
56 | # If it's a multiline match, then end-of-line anchors don't represent the whole string | ||||
57 | if ($front_anchor eq q{^} || $end_anchor eq q{$}) { | ||||
58 | my $regexp = $doc->ppix_regexp_from_element( $elem ) | ||||
59 | or return; | ||||
60 | return if $regexp->modifier_asserted( 'm' ); | ||||
61 | } | ||||
62 | |||||
63 | # check for grouping and optional alternation. Grouping may or may not capture | ||||
64 | if ($words =~ m{\A \s* | ||||
65 | [(] # start group | ||||
66 | (?:[?]:)? # optional non-capturing indicator | ||||
67 | \s* (.*?) \s* # interior of group | ||||
68 | [)] # end of group | ||||
69 | \s* \z}xms) { | ||||
70 | $words = $1; | ||||
71 | $words =~ s/[|]//gxms; # ignore alternation inside of parens -- just look at words | ||||
72 | } | ||||
73 | |||||
74 | # Regexps that contain metachars are not fixed strings | ||||
75 | return if $words =~ m/$RE_METACHAR/oxms; | ||||
76 | |||||
77 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
78 | |||||
79 | } else { | ||||
80 | return; # OK | ||||
81 | } | ||||
82 | } | ||||
83 | |||||
84 | 1 | 4µs | 1; | ||
85 | |||||
86 | __END__ | ||||
# spent 1µs within Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches::CORE:qr which was called:
# once (1µs+0s) by Module::Pluggable::Object::_require at line 29 |