Catmandu/Util/Regex.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 28 / 28 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
_escape_regex
1.0
CRAP 1.0
« Catmandu/Transactional.pm ↑ Summary
1 package Catmandu::Util::Regex;
2  
3 10 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 our $VERSION = '1.2025';
6  
7 10 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 our @EXPORT_OK = qw(
10 escape_regex
11 as_regex
12 substituter
13 );
14  
15 10 our %EXPORT_TAGS = (all => \@EXPORT_OK,);
16  
17 24 ▶sub _escape_regex {
Subroutine _escape_regex: called CC=1 SCAR=0.0
18 24 my ($str) = @_;
19 24 $str =~ s/\//\\\//g;
20 24 $str =~ s/\\$/\\\\/; # pattern can't end with an escape
21 24 $str;
22 }
23  
24 21 ▶sub as_regex {
Subroutine as_regex: called CC=1 SCAR=0.0
Pod documented
25 21 my ($str) = @_;
26 21 $str = _escape_regex($str);
27 21 qr/$str/;
28 }
29  
30 3 ▶sub substituter {
Subroutine substituter: called CC=1 SCAR=0.0
Pod documented
31 3 my ($search, $replace) = @_;
32 3 $search = as_regex($search);
33 3 $replace = _escape_regex($replace);
34 eval
35 3 qq|sub {my \$str = \$_[0]; utf8::upgrade(\$str); \$str =~ s/$search/$replace/g; \$str}|;
36 }
37  
38 10 1;
39  
40 __END__
« Catmandu/Transactional.pm ↑ Summary