lib/Perl/Critic/Policy/RegularExpressions/ProhibitSingleCharAlternation.pm

filter: Statementstmt 57.7% 26 / 45 Branchbran 6.2% 1 / 16 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 91.6% 11 / 12 Podpod 80.0% 4 / 5 totaltotal 41.5% 42 / 101 CC 16 SCAR 47.3
CC
16
Cov
36%
violates
202.6
__ANON__
6.0
BEGIN
1.0
CRAP 113.4
« lib/Perl/Critic/Policy/InputOutput/ProhibitBarewordDirHandles.pm ↑ Summary lib/Perl/Critic/TestUtils.pm »
1 package Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw( :characters :severities );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Scalar my $EXPL => [265];
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return qw() }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 74 ▶sub default_severity { return $SEVERITY_LOWEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 85 ▶sub default_themes { return qw( core pbp performance ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 31 ▶sub applies_to { return qw(PPI::Token::Regexp::Match
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24 PPI::Token::Regexp::Substitute
25 PPI::Token::QuoteLike::Regexp) }
26  
27 #-----------------------------------------------------------------------------
28  
29 1 ▶sub violates {
Subroutine violates: called CC=15 SCAR=53.1
Pod documented
30 1 my ( $self, $elem, $document ) = @_;
31  
32 # optimization: don't bother parsing the regexp if there are no pipes
33 1 ▶ return if $elem !~ m/[|]/xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem =~ /[|]/msx 1 0 1
34  
35 0 ▶ my $re = $document->ppix_regexp_from_element( $elem ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $re = $document->ppix_regexp_from_element($elem) or return 0 0 0
36 0 ▶ $re->failures() and return;
Branch: 1 branch
BranchTrueFalseTotal
$re->failures and return 0 0 0
37  
38 0 my @violations;
39 0 ▶ foreach my $node ( @{ $re->find_parents( sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
40 0 ▶ return $_[1]->isa( 'PPIx::Regexp::Token::Operator' )
Condition0%0/3
$_[1]->isa('PPIx::Regexp::Token::Operator') && $_[1]->content eq '|'
!ll&&!rl&&r
000
MC/DC0%0/2
$_[1]->isa('PPIx::Regexp::Token::Operator') && $_[1]->content eq '|'
$_[1]->isa('PPIx::Regexp::Token::Operator') $_[1]->content eq '|'
Truth table0%0/3
A && B
A= $_[1]->isa('PPIx::Regexp::Token::Operator')B= $_[1]->content eq '|'
ABresult
0X0
100
111
41 && $_[1]->content() eq q<|>;
42 0 ▶ } ) || [] } ) {
Condition0%0/2
$re->find_parents(sub { return $_[1]->isa('PPIx::Regexp::Token::Operator') && $_[1]->content eq '|'; } ) || []
l!l
00
MC/DC0%0/1
$re->find_parents(sub { return $_[1]->isa('PPIx::Regexp::Token::Operator') && $_[1]->content eq '|'; } ) || []
$re->find_parents(sub { return $_[1]->isa('PPIx::Regexp::Token::Operator') && $_[1]->content eq '|'; } )
Truth table0%0/2
A
A= $re->find_parents(sub { return $_[1]->isa('PPIx::Regexp::Token::Operator') && $_[1]->content eq '|'; } )
Aresult
11
00
43  
44 0 my @singles;
45 my @alternative;
46 0 foreach my $kid ( $node->children() ) {
47 0 ▶ if ( $kid->isa( 'PPIx::Regexp::Token::Operator' )
Branch: 2 branches
BranchTrueFalseTotal
if ($kid->isa('PPIx::Regexp::Token::Operator') and $kid->content eq '|') { } 0 0 0
elsif ($kid->significant) { } 0 0 0
Condition0%0/3
$kid->isa("PPIx::Regexp::Token::Operator") and $kid->content eq "|"
!ll&&!rl&&r
000
MC/DC0%0/2
$kid->isa("PPIx::Regexp::Token::Operator") and $kid->content eq "|"
$kid->isa("PPIx::Regexp::Token::Operator") $kid->content eq "|"
Truth table0%0/3
A and B
A= $kid->isa("PPIx::Regexp::Token::Operator")B= $kid->content eq "|"
ABresult
0X0
100
111
48 && $kid->content() eq q<|>
49 ) {
50 @alternative == 1
51 and $alternative[0]->isa( 'PPIx::Regexp::Token::Literal' )
52 0 ▶ and push @singles, map { $_->content() } @alternative;
Branch: 1 branch
BranchTrueFalseTotal
@alternative == 1 and $alternative[0]->isa("PPIx::Regexp::Token::Literal") and push @singles, map({$_->content;} @alternative) 0 0 0
Condition0%0/3
@alternative == 1 and $alternative[0]->isa("PPIx::Regexp::Token::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
@alternative == 1 and $alternative[0]->isa("PPIx::Regexp::Token::Literal")
@alternative == 1 $alternative[0]->isa("PPIx::Regexp::Token::Literal")
Truth table0%0/3
A and B
A= @alternative == 1B= $alternative[0]->isa("PPIx::Regexp::Token::Literal")
ABresult
0X0
100
111
53 0 @alternative = ();
54 } elsif ( $kid->significant() ) {
55 0 push @alternative, $kid;
56 }
57 }
58 @alternative == 1
59 and $alternative[0]->isa( 'PPIx::Regexp::Token::Literal' )
60 0 ▶ and push @singles, map { $_->content() } @alternative;
Branch: 1 branch
BranchTrueFalseTotal
@alternative == 1 and $alternative[0]->isa("PPIx::Regexp::Token::Literal") and push @singles, map({$_->content;} @alternative) 0 0 0
Condition0%0/3
@alternative == 1 and $alternative[0]->isa("PPIx::Regexp::Token::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
@alternative == 1 and $alternative[0]->isa("PPIx::Regexp::Token::Literal")
@alternative == 1 $alternative[0]->isa("PPIx::Regexp::Token::Literal")
Truth table0%0/3
A and B
A= @alternative == 1B= $alternative[0]->isa("PPIx::Regexp::Token::Literal")
ABresult
0X0
100
111
61  
62 0 ▶ if ( 1 < @singles ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 < @singles) 0 0 0
63 0 my $description =
64 'Use ['
65 . join( $EMPTY, @singles )
66 . '] instead of '
67 . join q<|>, @singles;
68 0 push @violations, $self->violation( $description, $EXPL, $elem );
69 }
70 }
71  
72 0 return @violations;
73 }
74  
75 40 1;
76  
77 __END__
« lib/Perl/Critic/Policy/InputOutput/ProhibitBarewordDirHandles.pm ↑ Summary lib/Perl/Critic/TestUtils.pm »