line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Context::BEM::Merge; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2013-11-15 05:13:46 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
65999
|
use Moose; |
|
2
|
|
|
|
|
373802
|
|
|
2
|
|
|
|
|
14
|
|
10
|
2
|
|
|
2
|
|
13754
|
use namespace::autoclean; |
|
2
|
|
|
|
|
1170
|
|
|
2
|
|
|
|
|
18
|
|
11
|
2
|
|
|
2
|
|
534
|
use version; |
|
2
|
|
|
|
|
1426
|
|
|
2
|
|
|
|
|
14
|
|
12
|
2
|
|
|
2
|
|
121
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
158
|
|
13
|
2
|
|
|
2
|
|
11
|
use List::Util qw/max /; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
125
|
|
14
|
2
|
|
|
2
|
|
11
|
use List::MoreUtils qw/uniq pairwise/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
26
|
|
15
|
2
|
|
|
2
|
|
896
|
use Data::Dumper qw/Dumper/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
16
|
2
|
|
|
2
|
|
465
|
use English qw/ -no_match_vars /; |
|
2
|
|
|
|
|
1473
|
|
|
2
|
|
|
|
|
16
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = version->new('0.0.4'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub merge { |
21
|
10
|
|
|
10
|
1
|
37
|
my ($self, $child, $parent) = @_; |
22
|
|
|
|
|
|
|
|
23
|
10
|
100
|
|
|
|
22
|
if ( ! ref $child ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
24
|
3
|
|
|
|
|
9
|
return $child; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ( ref $child eq 'ARRAY' ) { |
27
|
2
|
|
|
|
|
2
|
my $new = []; |
28
|
2
|
|
|
|
|
2
|
my $max_child = @$child - 1; |
29
|
2
|
|
|
|
|
3
|
my $max_parent = @$parent - 1; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
12
|
for my $i ( 0 .. max $max_child, $max_parent ) { |
32
|
4
|
100
|
|
|
|
12
|
$new->[$i] |
33
|
|
|
|
|
|
|
= exists $child->[$i] |
34
|
|
|
|
|
|
|
? $self->merge( $child->[$i], $parent->[$i] ) |
35
|
|
|
|
|
|
|
: $parent->[$i]; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
3
|
return $new; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ( ref $child eq 'HASH' ) { |
41
|
5
|
|
|
|
|
6
|
my $new = {}; |
42
|
|
|
|
|
|
|
|
43
|
5
|
|
|
|
|
22
|
for my $key ( uniq sort +(keys %$child), (keys %$parent) ) { |
44
|
8
|
100
|
|
|
|
14
|
if ( $key eq 'content' ) { |
45
|
2
|
100
|
|
|
|
7
|
$child->{$key} = [ $child->{$key} ] if ref $child->{$key} ne 'ARRAY'; |
46
|
2
|
100
|
|
|
|
5
|
$parent->{$key} = [ $parent->{$key} ] if ref $parent->{$key} ne 'ARRAY'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
8
|
100
|
|
|
|
23
|
$new->{$key} |
50
|
|
|
|
|
|
|
= exists $child->{$key} |
51
|
|
|
|
|
|
|
? $self->merge( $child->{$key}, $parent->{$key} ) |
52
|
|
|
|
|
|
|
: $parent->{$key}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
15
|
return $new; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
|
return $child; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Data::Context::BEM::Merge - Merge algorithm that merges arrays (not appending them) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 VERSION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This documentation refers to Data::Context::BEM::Merge version 0.0.4 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
use Data::Context::BEM::Merge; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $merge = Data::Context::BEM::Merge->new(); |
81
|
|
|
|
|
|
|
my $merged = $merge->merge({a => [1,2]}, {a => [2,3]}); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# $merged = { a => [2,3] } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 C<merge ($ref1, $ref2)> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Merges $ref2 into clone of $ref1. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
There are no known bugs in this module. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Patches are welcome. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Copyright (c) 2013 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
116
|
|
|
|
|
|
|
All rights reserved. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
119
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
120
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
121
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
122
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |