| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PPIx::Regexp::Util; |
|
2
|
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
115147
|
use 5.006; |
|
|
9
|
|
|
|
|
34
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
9
|
|
|
9
|
|
54
|
use strict; |
|
|
9
|
|
|
|
|
34
|
|
|
|
9
|
|
|
|
|
220
|
|
|
6
|
9
|
|
|
9
|
|
43
|
use warnings; |
|
|
9
|
|
|
|
|
24
|
|
|
|
9
|
|
|
|
|
297
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
53
|
use Carp; |
|
|
9
|
|
|
|
|
26
|
|
|
|
9
|
|
|
|
|
572
|
|
|
9
|
9
|
|
|
|
|
1359
|
use PPIx::Regexp::Constant qw{ |
|
10
|
|
|
|
|
|
|
INFINITY |
|
11
|
|
|
|
|
|
|
MINIMUM_PERL |
|
12
|
|
|
|
|
|
|
@CARP_NOT |
|
13
|
9
|
|
|
9
|
|
3745
|
}; |
|
|
9
|
|
|
|
|
150
|
|
|
14
|
9
|
|
|
9
|
|
65
|
use Scalar::Util qw{ blessed }; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
386
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
9
|
|
|
9
|
|
49
|
use base qw{ Exporter }; |
|
|
9
|
|
|
|
|
26
|
|
|
|
9
|
|
|
|
|
5948
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
32
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
|
33
|
|
|
|
|
|
|
width_one => [ qw{ raw_width width } ], |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.088'; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub is_ppi_regexp_element { |
|
39
|
11
|
|
|
11
|
1
|
33
|
my ( $elem ) = @_; |
|
40
|
11
|
50
|
|
|
|
30
|
__instance( $elem, 'PPI::Element' ) |
|
41
|
|
|
|
|
|
|
or return; |
|
42
|
11
|
|
66
|
|
|
84
|
return $elem->isa( 'PPI::Token::Regexp' ) || |
|
43
|
|
|
|
|
|
|
$elem->isa( 'PPI::Token::QuoteLike::Regexp' ); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub __is_ppi_regexp_element { |
|
47
|
0
|
|
|
0
|
|
0
|
Carp::cluck( |
|
48
|
|
|
|
|
|
|
'__is_ppi_regexp_element is deprecated. Use is_ppi_regexp_element' |
|
49
|
|
|
|
|
|
|
); |
|
50
|
0
|
|
|
|
|
0
|
goto &is_ppi_regexp_element; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# TODO ditch this once the deprecation period ends |
|
54
|
|
|
|
|
|
|
sub __choose_tokenizer_class { |
|
55
|
|
|
|
|
|
|
# my ( $content, $arg ) = @_; |
|
56
|
538
|
|
|
538
|
|
1680
|
my ( undef, $arg ) = @_; |
|
57
|
538
|
50
|
|
|
|
2044
|
if ( defined $arg->{parse} ) { |
|
58
|
0
|
|
|
|
|
0
|
my $warning = q; |
|
59
|
|
|
|
|
|
|
{ guess => 1, string => 1 }->{$arg->{parse}} |
|
60
|
0
|
0
|
|
|
|
0
|
and $warning = join ' ', $warning, |
|
61
|
|
|
|
|
|
|
q; |
|
62
|
0
|
|
|
|
|
0
|
croak $warning; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
538
|
|
|
|
|
1597
|
return 'PPIx::Regexp::Tokenizer'; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub __instance { |
|
68
|
55876
|
|
|
55876
|
|
94177
|
my ( $object, $class ) = @_; |
|
69
|
55876
|
100
|
|
|
|
164823
|
blessed( $object ) or return; |
|
70
|
23759
|
|
|
|
|
101819
|
return $object->isa( $class ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub __merge_perl_requirements { ## no critic (RequireArgUnpacking) |
|
74
|
|
|
|
|
|
|
my @work = |
|
75
|
113
|
50
|
|
|
|
217
|
sort { $a->[0] <=> $b->[0] || $b->[1] <=> $a->[1] } |
|
76
|
30
|
|
|
|
|
90
|
map { ( [ $_->[0], 1 ], [ $_->[1], 0 ] ) } |
|
77
|
9
|
100
|
|
9
|
|
20
|
map { [ $_->{introduced}, defined $_->{removed} ? $_->{removed} : INFINITY ] } @_; |
|
|
30
|
|
|
|
|
87
|
|
|
78
|
9
|
|
|
|
|
21
|
my @rslt; |
|
79
|
9
|
|
|
|
|
21
|
while ( @work ) { |
|
80
|
11
|
|
|
|
|
20
|
my ( $intro, $rem ); |
|
81
|
11
|
|
66
|
|
|
97
|
$intro = ( shift @work )->[0] while @work && $work[0][1]; |
|
82
|
11
|
50
|
|
|
|
23
|
if ( @work ) { |
|
83
|
11
|
|
|
|
|
20
|
$rem = $work[0][0]; |
|
84
|
11
|
|
100
|
|
|
73
|
shift @work while @work && ! $work[0][1]; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
11
|
50
|
|
|
|
24
|
defined $intro |
|
87
|
|
|
|
|
|
|
or $intro = MINIMUM_PERL; |
|
88
|
11
|
50
|
|
|
|
20
|
defined $rem |
|
89
|
|
|
|
|
|
|
or $rem = INFINITY; |
|
90
|
11
|
50
|
|
|
|
71
|
$intro != $rem |
|
91
|
|
|
|
|
|
|
and push @rslt, { |
|
92
|
|
|
|
|
|
|
introduced => $intro, |
|
93
|
|
|
|
|
|
|
removed => $rem, |
|
94
|
|
|
|
|
|
|
}; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
@rslt |
|
97
|
|
|
|
|
|
|
and $rslt[-1]{removed} == INFINITY |
|
98
|
9
|
50
|
33
|
|
|
51
|
and delete $rslt[-1]{removed}; |
|
99
|
9
|
|
|
|
|
36
|
return @rslt; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub __ns_can { |
|
103
|
252
|
|
|
252
|
|
483
|
my ( $class, $name ) = @_; |
|
104
|
252
|
|
33
|
|
|
915
|
my $fqn = join '::', ref $class || $class, $name; |
|
105
|
9
|
|
|
9
|
|
126
|
no strict qw{ refs }; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
3741
|
|
|
106
|
252
|
50
|
|
|
|
1669
|
return defined &$fqn ? \&$fqn : undef; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub __post_rebless_error { |
|
110
|
8
|
|
|
8
|
|
30
|
my ( $self, %arg ) = @_; |
|
111
|
8
|
|
|
|
|
20
|
my $rslt = 0; |
|
112
|
8
|
50
|
|
|
|
39
|
unless ( defined( $self->{error} = $arg{error} ) ) { |
|
113
|
0
|
|
|
|
|
0
|
my $class = ref $self; |
|
114
|
0
|
|
|
|
|
0
|
Carp::cluck( "Making $class with no error message" ); |
|
115
|
0
|
|
|
|
|
0
|
$self->{error} = 'Unspecified error'; |
|
116
|
0
|
|
|
|
|
0
|
$rslt++; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
$self->{explanation} = defined $arg{explanation} ? |
|
119
|
|
|
|
|
|
|
$arg{explanation} : |
|
120
|
8
|
50
|
|
|
|
60
|
$arg{error}; |
|
121
|
8
|
|
|
|
|
31
|
return $rslt; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Unquantified number of characters matched. |
|
126
|
|
|
|
|
|
|
sub raw_width { |
|
127
|
527
|
|
|
527
|
1
|
1093
|
return ( 1, 1 ); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub __to_ordinal_en { |
|
131
|
1
|
|
|
1
|
|
2
|
my ( $num ) = @_; |
|
132
|
1
|
|
|
|
|
2
|
$num += 0; |
|
133
|
1
|
50
|
|
|
|
8
|
1 == int( ( $num % 100 ) / 10 ) # teens |
|
134
|
|
|
|
|
|
|
and return "${num}th"; |
|
135
|
1
|
50
|
|
|
|
14
|
1 == $num % 10 |
|
136
|
|
|
|
|
|
|
and return "${num}st"; |
|
137
|
0
|
0
|
|
|
|
0
|
2 == $num % 10 |
|
138
|
|
|
|
|
|
|
and return "${num}nd"; |
|
139
|
0
|
0
|
|
|
|
0
|
3 == $num % 10 |
|
140
|
|
|
|
|
|
|
and return "${num}rd"; |
|
141
|
0
|
|
|
|
|
0
|
return "${num}th"; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub width { |
|
145
|
727
|
|
|
727
|
1
|
1242
|
my ( $self ) = @_; |
|
146
|
727
|
|
|
|
|
1579
|
my @raw_width = $self->raw_width(); |
|
147
|
727
|
|
|
|
|
1168
|
my ( $code, $next_sib ); |
|
148
|
727
|
100
|
100
|
|
|
1759
|
$next_sib = $self->snext_sibling() |
|
149
|
|
|
|
|
|
|
and $code = $next_sib->can( '__quantified_width' ) |
|
150
|
|
|
|
|
|
|
or return @raw_width; |
|
151
|
91
|
|
|
|
|
344
|
return $code->( $next_sib, @raw_width ); |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
__END__ |