Regexp/Util.pm

filter: Statementstmt 85.3% 70 / 82 Branchbran 57.1% 24 / 42 Conditioncond 66.6% 14 / 21 MC/DCmcdc 42.8% 6 / 14 Subroutinesub 94.4% 17 / 18 Podpod 100% 3 / 3 totaltotal 74.4% 134 / 180 CC 29 SCAR 19.9
CC
29
Cov
74%
__merge_perl_requirements
15.5
__to_ordinal_en
10.4
__choose_tokenizer_class
4.9
CRAP 7.3
« Regexp/Token/Code.pm ↑ Summary Regexp/Structure/Switch.pm »
1 package PPIx::Regexp::Util;
2  
3 9 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use PPIx::Regexp::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 INFINITY
11 MINIMUM_PERL
12 @CARP_NOT
13 9 };
14 9 ▶use Scalar::Util qw{ blessed };
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 ▶use base qw{ Exporter };
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 9 our @EXPORT_OK = qw{
19 is_ppi_regexp_element
20 __choose_tokenizer_class
21 __instance
22 __is_ppi_regexp_element
23 __merge_perl_requirements
24 __ns_can
25 __post_rebless_error
26 raw_width
27 __to_ordinal_en
28 width
29 };
30  
31 9 our %EXPORT_TAGS = (
32 all => \@EXPORT_OK,
33 width_one => [ qw{ raw_width width } ],
34 );
35  
36 9 our $VERSION = '0.092';
37  
38 11 ▶sub is_ppi_regexp_element {
Subroutine is_ppi_regexp_element: called CC=3 SCAR=11.4
Pod documented
39 11 my ( $elem ) = @_;
40 11 ▶ __instance( $elem, 'PPI::Element' )
Branch: 1 branch
BranchTrueFalseTotal
__instance($elem, "PPI::Element") or return 11 0 11
41 or return;
42 11 ▶ return $elem->isa( 'PPI::Token::Regexp' ) ||
Condition66%2/3
$elem->isa('PPI::Token::Regexp') || $elem->isa('PPI::Token::QuoteLike::Regexp')
l!l&&r!l&&!r
1010
MC/DC0%0/2
$elem->isa('PPI::Token::Regexp') || $elem->isa('PPI::Token::QuoteLike::Regexp')
$elem->isa('PPI::Token::Regexp') $elem->isa('PPI::Token::QuoteLike::Regexp')
Truth table66%2/3
A || B
A= $elem->isa('PPI::Token::Regexp')B= $elem->isa('PPI::Token::QuoteLike::Regexp')
ABresult
1X1
011
000
43 $elem->isa( 'PPI::Token::QuoteLike::Regexp' );
44 }
45  
46 0 ▶sub __is_ppi_regexp_element {
Subroutine __is_ppi_regexp_element: not called CC=1 SCAR=6.9
47 0 Carp::cluck(
48 '__is_ppi_regexp_element is deprecated. Use is_ppi_regexp_element'
49 );
50 0 goto &is_ppi_regexp_element;
51 }
52  
53 # TODO ditch this once the deprecation period ends
54 541 ▶sub __choose_tokenizer_class {
Subroutine __choose_tokenizer_class: called CC=3 SCAR=16.0
55 # my ( $content, $arg ) = @_;
56 541 my ( undef, $arg ) = @_;
57 541 ▶ if ( defined $arg->{parse} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg->{"parse"}) 0 541 541
58 0 my $warning = q<The 'parse' argument is deprecated.>;
59 { guess => 1, string => 1 }->{$arg->{parse}}
60 0 ▶ and $warning = join ' ', $warning,
Branch: 1 branch
BranchTrueFalseTotal
{"guess", 1, "string", 1}->{$arg->{"parse"}} and $warning = join(" ", $warning, "You should use PPIx::QuoteLike on quotish things") 0 0 0
61 q<You should use PPIx::QuoteLike on quotish things>;
62 0 croak $warning;
63 }
64 541 return 'PPIx::Regexp::Tokenizer';
65 }
66  
67 56133 ▶sub __instance {
Subroutine __instance: called CC=2 SCAR=6.9
68 56133 my ( $object, $class ) = @_;
69 56133 ▶ blessed( $object ) or return;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($object) or return 23857 32276 56133
70 23857 return $object->isa( $class );
71 }
72  
73 9 ▶sub __merge_perl_requirements { ## no critic (RequireArgUnpacking)
Subroutine __merge_perl_requirements: called CC=14 SCAR=27.4
74 my @work =
75 113 ▶ sort { $a->[0] <=> $b->[0] || $b->[1] <=> $a->[1] }
Condition66%2/3
$PPIx::Regexp::Util::a->[0] <=> $PPIx::Regexp::Util::b->[0] || $PPIx::Regexp::Util::b->[1] <=> $PPIx::Regexp::Util::a->[1]
l!l&&r!l&&!r
67046
MC/DC50%1/2
$PPIx::Regexp::Util::a->[0] <=> $PPIx::Regexp::Util::b->[0] || $PPIx::Regexp::Util::b->[1] <=> $PPIx::Regexp::Util::a->[1]
$PPIx::Regexp::Util::a->[0] <=> $PPIx::Regexp::Util::b->[0] $PPIx::Regexp::Util::b->[1] <=> $PPIx::Regexp::Util::a->[1]
Truth table66%2/3
A || B
A= $PPIx::Regexp::Util::a->[0] <=> $PPIx::Regexp::Util::b->[0]B= $PPIx::Regexp::Util::b->[1] <=> $PPIx::Regexp::Util::a->[1]
ABresult
1X1
011
000
76 30 map { ( [ $_->[0], 1 ], [ $_->[1], 0 ] ) }
77 9 ▶ map { [ $_->{introduced}, defined $_->{removed} ? $_->{removed} : INFINITY ] } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'removed'} ? : 2 28 30
78 9 my @rslt;
79 9 ▶ while ( @work ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@work) 11 9 20
80 11 my ( $intro, $rem );
81 11 ▶ $intro = ( shift @work )->[0] while @work && $work[0][1];
Branch: 1 branch
BranchTrueFalseTotal
@work and $work[0][1] and do { $intro = shift(@work)->[0] } 30 11 41
Condition66%2/3
@work and $work[0][1]
!ll&&!rl&&r
01130
MC/DC50%1/2
@work and $work[0][1]
@work $work[0][1]
Truth table66%2/3
A and B
A= @workB= $work[0][1]
ABresult
0X0
100
111
82 11 ▶ if ( @work ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@work) 11 0 11
83 11 $rem = $work[0][0];
84 11 ▶ shift @work while @work && ! $work[0][1];
Branch: 1 branch
BranchTrueFalseTotal
@work and not $work[0][1] and do { shift @work } 30 11 41
Condition100%3/3
@work and not $work[0][1]
!ll&&!rl&&r
9230
MC/DC100%2/2
@work and not $work[0][1]
@work not $work[0][1]
Truth table100%3/3
A and not(B)
A= @workB= not $work[0][1]
ABresult
0X0
100
111
85 }
86 11 ▶ defined $intro
Branch: 1 branch
BranchTrueFalseTotal
defined $intro or $intro = "5.000" 11 0 11
87 or $intro = MINIMUM_PERL;
88 11 ▶ defined $rem
Branch: 1 branch
BranchTrueFalseTotal
defined $rem or $rem = "Inf" 11 0 11
89 or $rem = INFINITY;
90 11 ▶ $intro != $rem
Branch: 1 branch
BranchTrueFalseTotal
$intro != $rem and push @rslt, {"introduced", $intro, "removed", $rem} 11 0 11
91 and push @rslt, {
92 introduced => $intro,
93 removed => $rem,
94 };
95 }
96 @rslt
97 and $rslt[-1]{removed} == INFINITY
98 9 ▶ and delete $rslt[-1]{removed};
Branch: 1 branch
BranchTrueFalseTotal
@rslt and $rslt[-1]{"removed"} == "Inf" and delete $rslt[-1]{"removed"} 9 0 9
Condition33%1/3
@rslt and $rslt[-1]{"removed"} == "Inf"
!ll&&!rl&&r
009
MC/DC0%0/2
@rslt and $rslt[-1]{"removed"} == "Inf"
@rslt $rslt[-1]{"removed"} == "Inf"
Truth table33%1/3
A and B
A= @rsltB= $rslt[-1]{"removed"} == "Inf"
ABresult
0X0
100
111
99 9 return @rslt;
100 }
101  
102 252 ▶sub __ns_can {
Subroutine __ns_can: called CC=3 SCAR=11.6
103 252 my ( $class, $name ) = @_;
104 252 ▶ my $fqn = join '::', ref $class || $class, $name;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
02520
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
105 9 ▶ no strict qw{ refs };
Subroutine BEGIN: called CC=1 SCAR=0.0
106 252 ▶ return defined &$fqn ? \&$fqn : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined &$fqn ? : 0 252 252
107 }
108  
109 8 ▶sub __post_rebless_error {
Subroutine __post_rebless_error: called CC=3 SCAR=13.6
110 8 my ( $self, %arg ) = @_;
111 8 my $rslt = 0;
112 8 ▶ unless ( defined( $self->{error} = $arg{error} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($self->{"error"} = $arg{"error"})) 0 8 8
113 0 my $class = ref $self;
114 0 Carp::cluck( "Making $class with no error message" );
115 0 $self->{error} = 'Unspecified error';
116 0 $rslt++;
117 }
118 $self->{explanation} = defined $arg{explanation} ?
119 $arg{explanation} :
120 8 ▶ $arg{error};
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'explanation'} ? : 0 8 8
121 8 return $rslt;
122  
123 }
124  
125 # Unquantified number of characters matched.
126 527 ▶sub raw_width {
Subroutine raw_width: called CC=1 SCAR=0.0
Pod documented
127 527 return ( 1, 1 );
128 }
129  
130 1 ▶sub __to_ordinal_en {
Subroutine __to_ordinal_en: called CC=5 SCAR=23.4
131 1 my ( $num ) = @_;
132 1 $num += 0;
133 1 ▶ 1 == int( ( $num % 100 ) / 10 ) # teens
Branch: 1 branch
BranchTrueFalseTotal
1 == int $num % 100 / 10 and return "${num}th" 0 1 1
134 and return "${num}th";
135 1 ▶ 1 == $num % 10
Branch: 1 branch
BranchTrueFalseTotal
1 == $num % 10 and return "${num}st" 1 0 1
136 and return "${num}st";
137 0 ▶ 2 == $num % 10
Branch: 1 branch
BranchTrueFalseTotal
2 == $num % 10 and return "${num}nd" 0 0 0
138 and return "${num}nd";
139 0 ▶ 3 == $num % 10
Branch: 1 branch
BranchTrueFalseTotal
3 == $num % 10 and return "${num}rd" 0 0 0
140 and return "${num}rd";
141 0 return "${num}th";
142 }
143  
144 727 ▶sub width {
Subroutine width: called CC=3 SCAR=11.0
Pod documented
145 727 my ( $self ) = @_;
146 727 my @raw_width = $self->raw_width();
147 727 my ( $code, $next_sib );
148 727 ▶ $next_sib = $self->snext_sibling()
Branch: 1 branch
BranchTrueFalseTotal
$next_sib = $self->snext_sibling and $code = $next_sib->can("__quantified_width") or return @raw_width 91 636 727
Condition100%3/3
$next_sib = $self->snext_sibling and $code = $next_sib->can("__quantified_width")
!ll&&!rl&&r
29833891
MC/DC100%2/2
$next_sib = $self->snext_sibling and $code = $next_sib->can("__quantified_width")
$next_sib = $self->snext_sibling $code = $next_sib->can("__quantified_width")
Truth table100%3/3
A and B
A= $next_sib = $self->snext_siblingB= $code = $next_sib->can("__quantified_width")
ABresult
0X0
100
111
149 and $code = $next_sib->can( '__quantified_width' )
150 or return @raw_width;
151 91 return $code->( $next_sib, @raw_width );
152 }
153  
154 9 1;
155  
156 __END__
« Regexp/Token/Code.pm ↑ Summary Regexp/Structure/Switch.pm »