line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
10
|
|
|
10
|
|
63
|
|
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
54
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Exporter qw(import); |
7
|
10
|
|
|
10
|
|
76
|
|
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
2761
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
9
|
|
|
|
|
|
|
escape_regex |
10
|
|
|
|
|
|
|
as_regex |
11
|
|
|
|
|
|
|
substituter |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => \@EXPORT_OK,); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my ($str) = @_; |
17
|
|
|
|
|
|
|
$str =~ s/\//\\\//g; |
18
|
24
|
|
|
24
|
|
44
|
$str =~ s/\\$/\\\\/; # pattern can't end with an escape |
19
|
24
|
|
|
|
|
51
|
$str; |
20
|
24
|
|
|
|
|
37
|
} |
21
|
24
|
|
|
|
|
47
|
|
22
|
|
|
|
|
|
|
my ($str) = @_; |
23
|
|
|
|
|
|
|
$str = _escape_regex($str); |
24
|
|
|
|
|
|
|
qr/$str/; |
25
|
21
|
|
|
21
|
1
|
47
|
} |
26
|
21
|
|
|
|
|
55
|
|
27
|
21
|
|
|
|
|
276
|
my ($search, $replace) = @_; |
28
|
|
|
|
|
|
|
$search = as_regex($search); |
29
|
|
|
|
|
|
|
$replace = _escape_regex($replace); |
30
|
|
|
|
|
|
|
eval |
31
|
3
|
|
|
3
|
1
|
926
|
qq|sub {my \$str = \$_[0]; utf8::upgrade(\$str); \$str =~ s/$search/$replace/g; \$str}|; |
32
|
3
|
|
|
|
|
7
|
} |
33
|
3
|
|
|
|
|
7
|
|
34
|
|
|
|
|
|
|
1; |
35
|
3
|
|
|
|
|
306
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Catmandu::Util::Regex - Regex related utility functions |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 FUNCTIONS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over 4 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item as_regex($str) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Escapes and quotes the given string as a regex. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item substituter($search, $replace) |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Builds a function that performs a regex substitution. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $ltrimmer = substituter('^[\h\v]+', ''); |
56
|
|
|
|
|
|
|
$ltrimmer->(" eek! "); |
57
|
|
|
|
|
|
|
# => "eek! " |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |