line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Regexp::From::String; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
72045
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
452
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
9
|
|
|
|
|
|
|
our $DATE = '2022-11-03'; # DATE |
10
|
|
|
|
|
|
|
our $DIST = 'Regexp-From-String'; # DIST |
11
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(str_maybe_to_re str_to_re); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub str_maybe_to_re { |
16
|
8
|
|
|
8
|
1
|
1255
|
my $str = shift; |
17
|
8
|
100
|
|
|
|
54
|
if ($str =~ m!\A(?:/.*/|qr\(.*\))(?:[ims]*)\z!s) { |
18
|
3
|
100
|
|
|
|
178
|
my $re = eval(substr($str, 0, 2) eq 'qr' ? $str : "qr$str"); ## no critic: BuiltinFunctions::ProhibitStringyEval |
19
|
3
|
100
|
|
|
|
22
|
die if $@; |
20
|
2
|
|
|
|
|
12
|
return $re; |
21
|
|
|
|
|
|
|
} |
22
|
5
|
|
|
|
|
25
|
$str; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub str_to_re { |
26
|
9
|
100
|
|
9
|
1
|
2614
|
my $opts = ref $_[0] eq 'HASH' ? shift : {}; |
27
|
9
|
|
|
|
|
21
|
my $str = shift; |
28
|
9
|
100
|
100
|
|
|
63
|
if (!$opts->{always_quote} && $str =~ m!\A(?:/.*/|qr\(.*\))(?:[ims]*)\z!s) { |
29
|
3
|
100
|
|
|
|
163
|
my $re = eval(substr($str, 0, 2) eq 'qr' ? $str : "qr$str"); ## no critic: BuiltinFunctions::ProhibitStringyEval |
30
|
3
|
100
|
|
|
|
23
|
die if $@; |
31
|
2
|
|
|
|
|
12
|
return $re; |
32
|
|
|
|
|
|
|
} else { |
33
|
6
|
|
|
|
|
14
|
$str = quotemeta($str); |
34
|
6
|
100
|
|
|
|
27
|
if ($opts->{anchored}) { |
35
|
1
|
50
|
|
|
|
4
|
if ($opts->{case_insensitive}) { return qr/\A$str\z/i } else { return qr/\A$str\z/ } |
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
19
|
|
36
|
|
|
|
|
|
|
} else { |
37
|
5
|
100
|
|
|
|
11
|
if ($opts->{case_insensitive}) { return qr/$str/i } else { return qr/$str/ } |
|
1
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
78
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
$str; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
# ABSTRACT: Convert '/.../' or 'qr(...)' into Regexp object |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |