blib/lib/Regexp/Util.pm

filter: Statementstmt 61.0% 36 / 59 Branchbran 38.8% 7 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 54.5% 6 / 11 Podpod 37.5% 3 / 8 totaltotal 50.9% 54 / 106 CC 12 SCAR 23.0
CC
12
Cov
54%
serialize_regexp
20.0
deserialize_regexp
11.0
regexp_pattern
2.0
CRAP 10.0
↑ Summary const-c.inc »
1 1 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Regexp::Util;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.005';
9  
10 1 require XSLoader;
11 1 XSLoader::load(__PACKAGE__, $VERSION);
12  
13 1 eval 'require re';
14  
15 1 require Exporter::Tiny;
16 1 our @ISA = qw( Exporter::Tiny );
17 1 our @EXPORT;
18 1 our @EXPORT_OK = qw(
19 is_regexp
20 regexp_seen_evals
21 regexp_is_foreign
22 serialize_regexp
23 deserialize_regexp
24
25 regexp_pattern regmust regname regnames regnames_count
26 );
27 1 our %EXPORT_TAGS = (
28 all => \@EXPORT_OK,
29 default => \@EXPORT,
30 );
31  
32 sub regexp_is_foreign
33 1 ▶{
Subroutine regexp_is_foreign: called CC=1 SCAR=0.0
Pod documented
34 1 _regexp_engine_id($_[0]) != _regexp_engine_id(qr//);
35 }
36  
37 sub serialize_regexp
38 1 ▶{
Subroutine serialize_regexp: called CC=7 SCAR=30.0
Pod documented
39 1 my $re = shift;
40
41 1 ▶ if (not is_regexp($re))
Branch: 1 branch
BranchTrueFalseTotal
unless (is_regexp($re)) 0 1 1
42 {
43 0 require Carp;
44 0 Carp::croak("Cannot serialize non-regexp");
45 }
46
47 1 ▶ if (regexp_seen_evals($re))
Branch: 1 branch
BranchTrueFalseTotal
if (regexp_seen_evals($re)) 0 1 1
48 {
49 0 require Carp;
50 0 Carp::croak("Cannot serialize regexp containing evals");
51 }
52
53 1 ▶ if (regexp_is_foreign($re))
Branch: 1 branch
BranchTrueFalseTotal
if (regexp_is_foreign($re)) 0 1 1
54 {
55 0 require Carp;
56 0 Carp::croak("Cannot serialize regexp using plugin re engine");
57 }
58
59 1 my $str = re::regexp_pattern($re);
60 1 ▶ return "qr/$str/" if $str !~ m{\/};
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ m[\/] 1 0 1
61 0 ▶ return "qr!$str!" if $str !~ m{\!};
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /\!/ 0 0 0
62 0 ▶ return "qr#$str#" if $str !~ m{\#};
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /\#/ 0 0 0
63
64 0 require B;
65 0 sprintf('do { my $re = %s; qr/$re/ }', B::perlstring($str));
66 }
67  
68 1 my $safe;
69 sub deserialize_regexp
70 1 ▶{
Subroutine deserialize_regexp: called CC=6 SCAR=24.0
Pod documented
71 1 my $str = shift;
72
73 1 ▶ if (!defined $str or ref $str)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $str or ref $str) 0 1 1
Condition33%1/3
not defined $str or ref $str
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $str or ref $str
not defined $str ref $str
Truth table33%1/3
not(A) or B
A= not defined $strB= ref $str
ABresult
1X1
011
000
74 {
75 0 require Carp;
76 0 Carp::croak("Cannot deserialize regexp");
77 }
78
79 1 ▶ $safe ||= do {
Condition33%1/3
$safe ||= do { require Safe; my $cpt = "Safe"->new; $cpt->permit(":base_core", ":base_mem", "sprintf", "qr"); $cpt }
l!l&&r!l&&!r
010
MC/DC0%0/2
$safe ||= do { require Safe; my $cpt = "Safe"->new; $cpt->permit(":base_core", ":base_mem", "sprintf", "qr"); $cpt }
$safe do { require Safe; my $cpt = "Safe"->new; $cpt->permit(":base_core", ":base_mem", "sprintf", "qr"); $cpt }
Truth table33%1/3
A ||= B
A= $safeB= do { require Safe; my $cpt = "Safe"->new; $cpt->permit(":base_core", ":base_mem", "sprintf", "qr"); $cpt }
ABresult
1X1
011
000
80 1 require Safe;
81 1 my $cpt = Safe->new;
82 1 $cpt->permit(qw/ :base_core :base_mem sprintf qr /);
83 1 $cpt;
84 };
85
86 1 ▶ my $re = $safe->reval($str) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $re = $safe->reval($str) or do { (my $e = $@) =~ s/ at \(eval \d+\) .+//; chomp $e; require Carp; Carp::croak("Cannot deserialize regexp: $e") } 1 0 1
87 0 (my $e = $@) =~
88 s/ at \(eval \d+\) .+//;
89 0 chomp $e;
90 0 require Carp;
91 0 Carp::croak("Cannot deserialize regexp: $e");
92 };
93
94 1 ▶ return $re if is_regexp($re);
Branch: 1 branch
BranchTrueFalseTotal
if is_regexp($re) 1 0 1
95
96 0 require Carp;
97 0 Carp::croak("Cannot deserialize regexp: eval returned $re");
98 }
99  
100 0 ▶sub regexp_pattern {
Subroutine regexp_pattern: not called CC=1 SCAR=6.9
Pod undocumented
101 0 goto \&re::regexp_pattern;
102 }
103  
104 0 ▶sub regmust {
Subroutine regmust: not called CC=1 SCAR=6.9
Pod undocumented
105 0 goto \&re::regmust;
106 }
107  
108 0 ▶sub regname {
Subroutine regname: not called CC=1 SCAR=6.9
Pod undocumented
109 0 goto \&re::regname;
110 }
111  
112 0 ▶sub regnames {
Subroutine regnames: not called CC=1 SCAR=6.9
Pod undocumented
113 0 goto \&re::regnames;
114 }
115  
116 0 ▶sub regnames_count {
Subroutine regnames_count: not called CC=1 SCAR=6.9
Pod undocumented
117 0 goto \&re::regnames_count;
118 }
119  
120 1 1;
121  
122 __END__
↑ Summary const-c.inc »