Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/RegularExpressions/ProhibitSingleCharAlternation.pm |
Statements | Executed 23 statements in 529µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 17µs | BEGIN@10 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 11µs | 22µs | BEGIN@11 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 9µs | 146µs | BEGIN@16 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 8µs | 42µs | BEGIN@14 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 8µs | 37µs | BEGIN@17 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 8µs | 11µs | BEGIN@12 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 8µs | 61µs | BEGIN@20 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 7µs | 377µs | BEGIN@15 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 7µs | 360µs | BEGIN@19 | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
0 | 0 | 0 | 0s | 0s | __ANON__[:52] | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::
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::ProhibitSingleCharAlternation; | ||||
9 | |||||
10 | 2 | 40µs | 1 | 17µs | # spent 17µs within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@10 which was called:
# once (17µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 17µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@10 |
11 | 2 | 21µs | 2 | 33µs | # spent 22µs (11+11) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@11 which was called:
# once (11µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 22µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 19µs | 2 | 15µs | # spent 11µs (8+4) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::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::ProhibitSingleCharAlternation::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 26µs | 2 | 76µs | # spent 42µs (8+34) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@14 which was called:
# once (8µs+34µs) by Module::Pluggable::Object::_require at line 14 # spent 42µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@14
# spent 34µs making 1 call to Exporter::import |
15 | 2 | 34µs | 2 | 746µs | # spent 377µs (7+369) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@15 which was called:
# once (7µs+369µs) by Module::Pluggable::Object::_require at line 15 # spent 377µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@15
# spent 369µs making 1 call to English::import |
16 | 2 | 23µs | 2 | 282µs | # spent 146µs (9+136) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@16 which was called:
# once (9µs+136µs) by Module::Pluggable::Object::_require at line 16 # spent 146µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@16
# spent 136µs making 1 call to Exporter::Tiny::import |
17 | 2 | 23µs | 2 | 66µs | # spent 37µs (8+29) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@17 which was called:
# once (8µs+29µs) by Module::Pluggable::Object::_require at line 17 # spent 37µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@17
# spent 29µs making 1 call to Exporter::import |
18 | |||||
19 | 2 | 24µs | 2 | 713µs | # spent 360µs (7+353) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@19 which was called:
# once (7µs+353µs) by Module::Pluggable::Object::_require at line 19 # spent 360µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@19
# spent 353µs making 1 call to Exporter::import |
20 | 2 | 304µs | 2 | 114µs | # spent 61µs (8+53) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@20 which was called:
# once (8µs+53µs) by Module::Pluggable::Object::_require at line 20 # spent 61µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::BEGIN@20
# spent 53µs making 1 call to base::import |
21 | |||||
22 | 1 | 600ns | our $VERSION = '1.121'; | ||
23 | |||||
24 | #----------------------------------------------------------------------------- | ||||
25 | |||||
26 | 1 | 2µs | 1 | 49µs | Readonly::Scalar my $EXPL => [265]; # spent 49µs making 1 call to Readonly::Scalar |
27 | |||||
28 | #----------------------------------------------------------------------------- | ||||
29 | |||||
30 | 1 | 5µs | # spent 2µs within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
31 | 1 | 1µs | # spent 7µs (6+1) within Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
32 | sub default_themes { return qw( core pbp performance ) } | ||||
33 | sub applies_to { return qw(PPI::Token::Regexp::Match | ||||
34 | PPI::Token::Regexp::Substitute | ||||
35 | PPI::Token::QuoteLike::Regexp) } | ||||
36 | |||||
37 | #----------------------------------------------------------------------------- | ||||
38 | |||||
39 | sub violates { | ||||
40 | my ( $self, $elem, $document ) = @_; | ||||
41 | |||||
42 | # optimization: don't bother parsing the regexp if there are no pipes | ||||
43 | return if $elem !~ m/[|]/xms; | ||||
44 | |||||
45 | my $re = $document->ppix_regexp_from_element( $elem ) or return; | ||||
46 | $re->failures() and return; | ||||
47 | |||||
48 | my @violations; | ||||
49 | foreach my $node ( @{ $re->find_parents( sub { | ||||
50 | return $_[1]->isa( 'PPIx::Regexp::Token::Operator' ) | ||||
51 | && $_[1]->content() eq q<|>; | ||||
52 | } ) || [] } ) { | ||||
53 | |||||
54 | my @singles; | ||||
55 | my @alternative; | ||||
56 | foreach my $kid ( $node->children() ) { | ||||
57 | if ( $kid->isa( 'PPIx::Regexp::Token::Operator' ) | ||||
58 | && $kid->content() eq q<|> | ||||
59 | ) { | ||||
60 | @alternative == 1 | ||||
61 | and $alternative[0]->isa( 'PPIx::Regexp::Token::Literal' ) | ||||
62 | and push @singles, map { $_->content() } @alternative; | ||||
63 | @alternative = (); | ||||
64 | } elsif ( $kid->significant() ) { | ||||
65 | push @alternative, $kid; | ||||
66 | } | ||||
67 | } | ||||
68 | @alternative == 1 | ||||
69 | and $alternative[0]->isa( 'PPIx::Regexp::Token::Literal' ) | ||||
70 | and push @singles, map { $_->content() } @alternative; | ||||
71 | |||||
72 | if ( 1 < @singles ) { | ||||
73 | my $description = | ||||
74 | 'Use [' | ||||
75 | . join( $EMPTY, @singles ) | ||||
76 | . '] instead of ' | ||||
77 | . join q<|>, @singles; | ||||
78 | push @violations, $self->violation( $description, $EXPL, $elem ); | ||||
79 | } | ||||
80 | } | ||||
81 | |||||
82 | return @violations; | ||||
83 | } | ||||
84 | |||||
85 | 1 | 6µs | 1; | ||
86 | |||||
87 | __END__ |