line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Merge; |
2
|
|
|
|
|
|
|
# ABSTRACT: internal hash merging |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Merge::VERSION = '0.40067'; |
4
|
143
|
|
|
143
|
|
2507
|
use warnings; |
|
143
|
|
|
|
|
194
|
|
|
143
|
|
|
|
|
4313
|
|
5
|
143
|
|
|
143
|
|
56201
|
use Data::Clone; |
|
143
|
|
|
|
|
76021
|
|
|
143
|
|
|
|
|
6697
|
|
6
|
143
|
|
|
143
|
|
775
|
use base 'Exporter'; |
|
143
|
|
|
|
|
204
|
|
|
143
|
|
|
|
|
59706
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = ( 'merge' ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $matrix = { |
11
|
|
|
|
|
|
|
'SCALAR' => { |
12
|
|
|
|
|
|
|
'SCALAR' => sub { $_[0] }, |
13
|
|
|
|
|
|
|
'ARRAY' => sub { [ $_[0], @{ $_[1] } ] }, |
14
|
|
|
|
|
|
|
'HASH' => sub { $_[1] }, |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
'ARRAY' => { |
17
|
|
|
|
|
|
|
'SCALAR' => sub { [ @{ $_[0] }, $_[1] ] }, |
18
|
|
|
|
|
|
|
'ARRAY' => sub { [ @{ $_[0] }, @{ $_[1] } ] }, |
19
|
|
|
|
|
|
|
'HASH' => sub { $_[1] }, |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
'HASH' => { |
22
|
|
|
|
|
|
|
'SCALAR' => sub { $_[0] }, |
23
|
|
|
|
|
|
|
'ARRAY' => sub { $_[0] }, |
24
|
|
|
|
|
|
|
'HASH' => sub { merge_hashes( $_[0], $_[1] ) }, |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub merge { |
29
|
151
|
|
|
151
|
0
|
560
|
my ( $left, $right ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
151
|
100
|
|
|
|
2273
|
my $lefttype = |
|
|
100
|
|
|
|
|
|
32
|
|
|
|
|
|
|
ref $left eq 'HASH' ? 'HASH' : |
33
|
|
|
|
|
|
|
ref $left eq 'ARRAY' ? 'ARRAY' : |
34
|
|
|
|
|
|
|
'SCALAR'; |
35
|
151
|
100
|
|
|
|
433
|
my $righttype = |
|
|
100
|
|
|
|
|
|
36
|
|
|
|
|
|
|
ref $right eq 'HASH' ? 'HASH' : |
37
|
|
|
|
|
|
|
ref $right eq 'ARRAY' ? 'ARRAY' : |
38
|
|
|
|
|
|
|
'SCALAR'; |
39
|
151
|
|
|
|
|
1307
|
$left = clone($left); |
40
|
151
|
|
|
|
|
740
|
$right = clone($right); |
41
|
151
|
|
|
|
|
10767
|
return $matrix->{$lefttype}{$righttype}->( $left, $right ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub merge_hashes { |
45
|
145
|
|
|
145
|
0
|
201
|
my ( $left, $right ) = @_; |
46
|
145
|
|
|
|
|
180
|
my %newhash; |
47
|
145
|
|
|
|
|
402
|
foreach my $leftkey ( keys %$left ) { |
48
|
380
|
100
|
|
|
|
530
|
if ( exists $right->{$leftkey} ) { |
49
|
12
|
|
|
|
|
48
|
$newhash{$leftkey} = merge( $left->{$leftkey}, $right->{$leftkey} ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
368
|
|
|
|
|
909
|
$newhash{$leftkey} = clone( $left->{$leftkey} ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
145
|
|
|
|
|
371
|
foreach my $rightkey ( keys %$right ) { |
56
|
257
|
100
|
|
|
|
6985
|
if ( !exists $left->{$rightkey} ) { |
57
|
245
|
|
|
|
|
596
|
$newhash{$rightkey} = clone( $right->{$rightkey} ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
145
|
|
|
|
|
3345
|
return \%newhash; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=encoding UTF-8 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
HTML::FormHandler::Merge - internal hash merging |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 0.40067 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 AUTHOR |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
88
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |