line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
10
|
|
|
10
|
|
61
|
|
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
56
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Exporter qw(import); |
7
|
10
|
|
|
10
|
|
59
|
|
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
2618
|
|
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
|
|
48
|
$str =~ s/\\$/\\\\/; # pattern can't end with an escape |
19
|
24
|
|
|
|
|
45
|
$str; |
20
|
24
|
|
|
|
|
40
|
} |
21
|
24
|
|
|
|
|
42
|
|
22
|
|
|
|
|
|
|
my ($str) = @_; |
23
|
|
|
|
|
|
|
$str = _escape_regex($str); |
24
|
|
|
|
|
|
|
qr/$str/; |
25
|
21
|
|
|
21
|
1
|
43
|
} |
26
|
21
|
|
|
|
|
52
|
|
27
|
21
|
|
|
|
|
235
|
my ($search, $replace) = @_; |
28
|
|
|
|
|
|
|
$search = as_regex($search); |
29
|
|
|
|
|
|
|
$replace = _escape_regex($replace); |
30
|
|
|
|
|
|
|
eval |
31
|
3
|
|
|
3
|
1
|
941
|
qq|sub {my \$str = \$_[0]; utf8::upgrade(\$str); \$str =~ s/$search/$replace/g; \$str}|; |
32
|
3
|
|
|
|
|
6
|
} |
33
|
3
|
|
|
|
|
5
|
|
34
|
|
|
|
|
|
|
1; |
35
|
3
|
|
|
|
|
352
|
|
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 |