line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Util::Merge; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
126905
|
use v5.10.1; |
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Exporter (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
445
|
use Sub::Util 1.40 qw( set_prototype ); |
|
1
|
|
|
|
|
326
|
|
|
1
|
|
|
|
|
93
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 'v0.1.2'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: utility functions for merging hashes |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ mergemap /; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# This borrows a technique from List::Util that exports symbols $a |
21
|
|
|
|
|
|
|
# and $b to the callers namespace, so that function arguments can |
22
|
|
|
|
|
|
|
# simply use $a and $b, akin to how function arguments for sort |
23
|
|
|
|
|
|
|
# works. |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
10
|
my $pkg = caller; |
26
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
118
|
|
27
|
1
|
|
|
|
|
20
|
${"${pkg}::a"} = ${"${pkg}::a"}; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
28
|
1
|
|
|
|
|
2
|
${"${pkg}::b"} = ${"${pkg}::b"}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
29
|
1
|
|
|
|
|
1884
|
goto &Exporter::import; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub mergemap { |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
4
|
1
|
2042
|
my $pkg = caller; |
36
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
184
|
|
37
|
4
|
|
|
|
|
81
|
my $glob_a = \ *{"${pkg}::a"}; |
|
4
|
|
|
|
|
14
|
|
38
|
4
|
|
|
|
|
7
|
my $glob_b = \ *{"${pkg}::b"}; |
|
4
|
|
|
|
|
16
|
|
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
10
|
my ($f, $x, $y) = @_; |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
6
|
my %r; |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
14
|
for my $k (keys %$x, keys %$y) { |
45
|
15
|
100
|
|
|
|
54
|
next if exists $r{$k}; |
46
|
8
|
|
|
|
|
16
|
local *$glob_a = \ $x->{$k}; |
47
|
8
|
|
|
|
|
14
|
local *$glob_b = \ $y->{$k}; |
48
|
8
|
|
|
|
|
16
|
$r{$k} = $f->(); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
12
|
return \%r; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
BEGIN { |
55
|
1
|
|
|
1
|
|
31
|
set_prototype '&$$' => \&mergemap; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |