| 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
| |||||||||||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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]
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]
| |||||||||||||||||||||||||||||
| 76 | 30 | map { ( [ $_->[0], 1 ], [ $_->[1], 0 ] ) } | |||||||||||||||||||||||||||
| 77 | 9 | ▶ | map { [ $_->{introduced}, defined $_->{removed} ? $_->{removed} : INFINITY ] } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 9 | my @rslt; | |||||||||||||||||||||||||||
| 79 | 9 | ▶ | while ( @work ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 11 | my ( $intro, $rem ); | |||||||||||||||||||||||||||
| 81 | 11 | ▶ | $intro = ( shift @work )->[0] while @work && $work[0][1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@work and $work[0][1]
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]
| |||||||||||||||||||||||||||||
| 82 | 11 | ▶ | if ( @work ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 11 | $rem = $work[0][0]; | |||||||||||||||||||||||||||
| 84 | 11 | ▶ | shift @work while @work && ! $work[0][1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@work and not $work[0][1]
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]
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 11 | ▶ | defined $intro | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | or $intro = MINIMUM_PERL; | ||||||||||||||||||||||||||||
| 88 | 11 | ▶ | defined $rem | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | or $rem = INFINITY; | ||||||||||||||||||||||||||||
| 90 | 11 | ▶ | $intro != $rem | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
@rslt and $rslt[-1]{"removed"} == "Inf"
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"
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 105 | 9 | ▶ | no strict qw{ refs }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | 252 | ▶ | return defined &$fqn ? \&$fqn : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 134 | and return "${num}th"; | ||||||||||||||||||||||||||||
| 135 | 1 | ▶ | 1 == $num % 10 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | and return "${num}st"; | ||||||||||||||||||||||||||||
| 137 | 0 | ▶ | 2 == $num % 10 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | and return "${num}nd"; | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | 3 == $num % 10 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$next_sib = $self->snext_sibling and $code = $next_sib->can("__quantified_width")
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")
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||