line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Util::Regexp; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
57508
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
11
|
use Exporter 'import'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
534
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
9
|
|
|
|
|
|
|
our $DATE = '2022-07-25'; # DATE |
10
|
|
|
|
|
|
|
our $DIST = 'Hash-Util-Regexp'; # DIST |
11
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
has_key_matching |
15
|
|
|
|
|
|
|
keys_matching |
16
|
|
|
|
|
|
|
first_key_matching |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has_key_not_matching |
19
|
|
|
|
|
|
|
keys_not_matching |
20
|
|
|
|
|
|
|
first_key_not_matching |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _keys { |
24
|
8
|
|
|
8
|
|
10
|
my ($hash, $sort) = @_; |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
23
|
my @keys = keys %$hash; |
27
|
8
|
50
|
|
|
|
18
|
if ($sort) { |
28
|
8
|
50
|
|
|
|
17
|
if (ref $sort eq 'CODE') { |
29
|
0
|
|
|
|
|
0
|
@keys = sort $sort @keys; |
30
|
|
|
|
|
|
|
} else { |
31
|
8
|
|
|
|
|
25
|
@keys = sort @keys; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
8
|
|
|
|
|
19
|
\@keys; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub has_key_matching { |
38
|
2
|
|
|
2
|
1
|
88
|
my ($hash, $re) = @_; |
39
|
2
|
|
|
|
|
7
|
for my $key (keys %$hash) { |
40
|
5
|
100
|
|
|
|
23
|
return 1 if $key =~ $re; |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
3
|
0; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub keys_matching { |
46
|
2
|
|
|
2
|
1
|
5
|
my ($hash, $re, $sort) = @_; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
10
|
my @res; |
49
|
2
|
|
|
|
|
6
|
for my $key (@{ _keys($hash, $sort) }) { |
|
2
|
|
|
|
|
5
|
|
50
|
6
|
100
|
|
|
|
22
|
next unless $key =~ $re; |
51
|
2
|
|
|
|
|
5
|
push @res, $key; |
52
|
|
|
|
|
|
|
} |
53
|
2
|
|
|
|
|
10
|
@res; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub first_key_matching { |
57
|
2
|
|
|
2
|
1
|
6
|
my ($hash, $re, $sort) = @_; |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
2
|
my @res; |
60
|
2
|
|
|
|
|
4
|
for my $key (@{ _keys($hash, $sort) }) { |
|
2
|
|
|
|
|
5
|
|
61
|
4
|
100
|
|
|
|
19
|
return $key if $key =~ $re; |
62
|
|
|
|
|
|
|
} |
63
|
1
|
|
|
|
|
4
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub has_key_not_matching { |
67
|
2
|
|
|
2
|
1
|
6
|
my ($hash, $re) = @_; |
68
|
2
|
|
|
|
|
6
|
for my $key (keys %$hash) { |
69
|
4
|
100
|
|
|
|
20
|
return 1 unless $key =~ $re; |
70
|
|
|
|
|
|
|
} |
71
|
1
|
|
|
|
|
4
|
0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub keys_not_matching { |
75
|
2
|
|
|
2
|
1
|
5
|
my ($hash, $re, $sort) = @_; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
3
|
my @res; |
78
|
2
|
|
|
|
|
3
|
for my $key (@{ _keys($hash, $sort) }) { |
|
2
|
|
|
|
|
4
|
|
79
|
6
|
100
|
|
|
|
23
|
next if $key =~ $re; |
80
|
2
|
|
|
|
|
5
|
push @res, $key; |
81
|
|
|
|
|
|
|
} |
82
|
2
|
|
|
|
|
9
|
@res; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub first_key_not_matching { |
86
|
2
|
|
|
2
|
1
|
4
|
my ($hash, $re, $sort) = @_; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
4
|
my @res; |
89
|
2
|
|
|
|
|
3
|
for my $key (@{ _keys($hash, $sort) }) { |
|
2
|
|
|
|
|
3
|
|
90
|
6
|
100
|
|
|
|
26
|
return $key unless $key =~ $re; |
91
|
|
|
|
|
|
|
} |
92
|
1
|
|
|
|
|
5
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
# ABSTRACT: Hash utility routines related to regular expression |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |