Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/RegularExpressions/ProhibitEscapedMetacharacters.pm |
Statements | Executed 23 statements in 476µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 8µs | 136µs | BEGIN@15 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 8µs | 27µs | BEGIN@16 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 8µs | 19µs | BEGIN@11 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 8µs | 11µs | BEGIN@12 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 7µs | 60µs | BEGIN@19 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 7µs | 218µs | BEGIN@18 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 7µs | 372µs | BEGIN@14 | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::
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::ProhibitEscapedMetacharacters; | ||||
9 | |||||
10 | 2 | 42µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::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::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@10 |
11 | 2 | 20µs | 2 | 30µs | # spent 19µs (8+11) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@11 which was called:
# once (8µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 19µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 21µs | 2 | 15µs | # spent 11µs (8+4) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 11µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 24µs | 2 | 737µs | # spent 372µs (7+365) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@14 which was called:
# once (7µs+365µs) by Module::Pluggable::Object::_require at line 14 # spent 372µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@14
# spent 365µs making 1 call to English::import |
15 | 2 | 22µs | 2 | 264µs | # spent 136µs (8+128) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@15 which was called:
# once (8µs+128µs) by Module::Pluggable::Object::_require at line 15 # spent 136µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@15
# spent 128µs making 1 call to Exporter::Tiny::import |
16 | 2 | 23µs | 2 | 46µs | # spent 27µs (8+19) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@16 which was called:
# once (8µs+19µs) by Module::Pluggable::Object::_require at line 16 # spent 27µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@16
# spent 19µs making 1 call to Exporter::import |
17 | |||||
18 | 2 | 23µs | 2 | 429µs | # spent 218µs (7+211) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@18 which was called:
# once (7µs+211µs) by Module::Pluggable::Object::_require at line 18 # spent 218µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@18
# spent 211µs making 1 call to Exporter::import |
19 | 2 | 277µs | 2 | 112µs | # spent 60µs (7+52) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@19 which was called:
# once (7µs+52µs) by Module::Pluggable::Object::_require at line 19 # spent 60µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::BEGIN@19
# spent 52µs making 1 call to base::import |
20 | |||||
21 | 1 | 600ns | our $VERSION = '1.121'; | ||
22 | |||||
23 | #----------------------------------------------------------------------------- | ||||
24 | |||||
25 | 1 | 2µs | 1 | 2.84ms | Readonly::Scalar my $DESC => q{Use character classes for literal metachars instead of escapes}; # spent 2.84ms making 1 call to Readonly::Scalar |
26 | 1 | 2µs | 1 | 48µs | Readonly::Scalar my $EXPL => [247]; # spent 48µs making 1 call to Readonly::Scalar |
27 | |||||
28 | 1 | 7µs | 2 | 44µs | Readonly::Hash my %REGEXP_METACHARS => hashify(split / /xms, '{ } ( ) . * + ? |'); # spent 39µs making 1 call to Readonly::Hash
# spent 6µs making 1 call to Perl::Critic::Utils::hashify |
29 | |||||
30 | #----------------------------------------------------------------------------- | ||||
31 | |||||
32 | 1 | 4µs | # spent 2µs within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
33 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
34 | sub default_themes { return qw( core pbp cosmetic ) } | ||||
35 | sub applies_to { return qw(PPI::Token::Regexp::Match | ||||
36 | PPI::Token::Regexp::Substitute | ||||
37 | PPI::Token::QuoteLike::Regexp) } | ||||
38 | |||||
39 | #----------------------------------------------------------------------------- | ||||
40 | |||||
41 | sub violates { | ||||
42 | my ( $self, $elem, $document ) = @_; | ||||
43 | |||||
44 | # optimization: don't bother parsing the regexp if there are no escapes | ||||
45 | return if $elem !~ m/\\/xms; | ||||
46 | |||||
47 | my $re = $document->ppix_regexp_from_element( $elem ) or return; | ||||
48 | $re->failures() and return; | ||||
49 | my $qr = $re->regular_expression() or return; | ||||
50 | |||||
51 | my $exacts = $qr->find( 'PPIx::Regexp::Token::Literal' ) or return; | ||||
52 | foreach my $exact( @{ $exacts } ) { | ||||
53 | $exact->content() =~ m/ \\ ( . ) /xms or next; | ||||
54 | return $self->violation( $DESC, $EXPL, $elem ) if $REGEXP_METACHARS{$1}; | ||||
55 | } | ||||
56 | |||||
57 | return; # OK | ||||
58 | } | ||||
59 | |||||
60 | 1 | 5µs | 1; | ||
61 | |||||
62 | __END__ |