line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
29917
|
use 5.010000; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
30
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
627
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Regexp::Util; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require XSLoader; |
11
|
|
|
|
|
|
|
XSLoader::load(__PACKAGE__, $VERSION); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
eval 'require re'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
17
|
|
|
|
|
|
|
our @EXPORT; |
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
19
|
|
|
|
|
|
|
is_regexp |
20
|
|
|
|
|
|
|
regexp_seen_evals |
21
|
|
|
|
|
|
|
regexp_is_foreign |
22
|
|
|
|
|
|
|
serialize_regexp |
23
|
|
|
|
|
|
|
deserialize_regexp |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
26
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
27
|
|
|
|
|
|
|
default => \@EXPORT, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub regexp_is_foreign |
31
|
|
|
|
|
|
|
{ |
32
|
1
|
|
|
1
|
1
|
12
|
_regexp_engine_id($_[0]) != _regexp_engine_id(qr//); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub serialize_regexp |
36
|
|
|
|
|
|
|
{ |
37
|
1
|
|
|
1
|
1
|
13
|
my $re = shift; |
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
8
|
if (not is_regexp($re)) |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
|
|
0
|
require Carp; |
42
|
0
|
|
|
|
|
0
|
Carp::croak("Cannot serialize non-regexp"); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
9
|
if (regexp_seen_evals($re)) |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
0
|
require Carp; |
48
|
0
|
|
|
|
|
0
|
Carp::croak("Cannot serialize regexp containing evals"); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
1
|
50
|
|
|
|
5
|
if (regexp_is_foreign($re)) |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
0
|
require Carp; |
54
|
0
|
|
|
|
|
0
|
Carp::croak("Cannot serialize regexp using plugin re engine"); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
9
|
my $str = re::regexp_pattern($re); |
58
|
1
|
50
|
|
|
|
13
|
return "qr/$str/" if $str !~ m{\/}; |
59
|
0
|
0
|
|
|
|
0
|
return "qr!$str!" if $str !~ m{\!}; |
60
|
0
|
0
|
|
|
|
0
|
return "qr#$str#" if $str !~ m{\#}; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
require B; |
63
|
0
|
|
|
|
|
0
|
sprintf('do { my $re = %s; qr/$re/ }', B::perlstring($str)); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $safe; |
67
|
|
|
|
|
|
|
sub deserialize_regexp |
68
|
|
|
|
|
|
|
{ |
69
|
1
|
|
|
1
|
1
|
2
|
my $str = shift; |
70
|
|
|
|
|
|
|
|
71
|
1
|
50
|
33
|
|
|
11
|
if (!defined $str or ref $str) |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
|
|
0
|
require Carp; |
74
|
0
|
|
|
|
|
0
|
Carp::croak("Cannot deserialize regexp"); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
33
|
|
|
6
|
$safe ||= do { |
78
|
1
|
|
|
|
|
1734
|
require Safe; |
79
|
1
|
|
|
|
|
44723
|
my $cpt = Safe->new; |
80
|
1
|
|
|
|
|
2212
|
$cpt->permit(qw/ :base_core :base_mem sprintf qr /); |
81
|
1
|
|
|
|
|
17
|
$cpt; |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
|
84
|
1
|
50
|
|
|
|
6
|
my $re = $safe->reval($str) or do { |
85
|
1
|
|
|
|
|
589
|
(my $e = $@) =~ |
86
|
|
|
|
|
|
|
s/ at \(eval \d+\) .+//; |
87
|
1
|
|
|
|
|
2
|
chomp $e; |
88
|
1
|
|
|
|
|
8
|
require Carp; |
89
|
1
|
|
|
|
|
402
|
Carp::croak("Cannot deserialize regexp: $e"); |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
return $re if is_regexp($re); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
require Carp; |
95
|
0
|
|
|
|
|
|
Carp::croak("Cannot deserialize regexp: eval returned $re"); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |