line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
769
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
47
|
|
2
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
79
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package CPAN::Meta::Merge; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.150008'; # TRIAL |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
6
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
81
|
|
9
|
2
|
|
|
2
|
|
6
|
use Scalar::Util qw/blessed/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
79
|
|
10
|
2
|
|
|
2
|
|
55
|
use CPAN::Meta::Converter 2.141170; |
|
2
|
|
|
|
|
32
|
|
|
2
|
|
|
|
|
987
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _is_identical { |
13
|
38
|
|
|
38
|
|
26
|
my ($left, $right) = @_; |
14
|
|
|
|
|
|
|
return |
15
|
38
|
|
33
|
|
|
263
|
(not defined $left and not defined $right) |
16
|
|
|
|
|
|
|
# if either of these are references, we compare the serialized value |
17
|
|
|
|
|
|
|
|| (defined $left and defined $right and $left eq $right); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _identical { |
21
|
33
|
|
|
33
|
|
32
|
my ($left, $right, $path) = @_; |
22
|
33
|
100
|
|
|
|
34
|
croak sprintf "Can't merge attribute %s: '%s' does not equal '%s'", join('.', @{$path}), $left, $right |
|
1
|
|
|
|
|
138
|
|
23
|
|
|
|
|
|
|
unless _is_identical($left, $right); |
24
|
32
|
|
|
|
|
59
|
return $left; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _merge { |
28
|
50
|
|
|
50
|
|
50
|
my ($current, $next, $mergers, $path) = @_; |
29
|
50
|
|
|
|
|
34
|
for my $key (keys %{$next}) { |
|
50
|
|
|
|
|
75
|
|
30
|
208
|
100
|
|
|
|
282
|
if (not exists $current->{$key}) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
31
|
131
|
|
|
|
|
131
|
$current->{$key} = $next->{$key}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif (my $merger = $mergers->{$key}) { |
34
|
77
|
|
|
|
|
61
|
$current->{$key} = $merger->($current->{$key}, $next->{$key}, [ @{$path}, $key ]); |
|
77
|
|
|
|
|
126
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif ($merger = $mergers->{':default'}) { |
37
|
0
|
|
|
|
|
0
|
$current->{$key} = $merger->($current->{$key}, $next->{$key}, [ @{$path}, $key ]); |
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
0
|
|
|
|
|
0
|
croak sprintf "Can't merge unknown attribute '%s'", join '.', @{$path}, $key; |
|
0
|
|
|
|
|
0
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
43
|
|
|
|
|
74
|
return $current; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _uniq { |
47
|
10
|
|
|
10
|
|
12
|
my %seen = (); |
48
|
10
|
|
|
|
|
9
|
return grep { not $seen{$_}++ } @_; |
|
20
|
|
|
|
|
54
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _set_addition { |
52
|
8
|
|
|
8
|
|
8
|
my ($left, $right) = @_; |
53
|
8
|
|
|
|
|
6
|
return [ +_uniq(@{$left}, @{$right}) ]; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
15
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _uniq_map { |
57
|
7
|
|
|
7
|
|
9
|
my ($left, $right, $path) = @_; |
58
|
7
|
|
|
|
|
5
|
for my $key (keys %{$right}) { |
|
7
|
|
|
|
|
11
|
|
59
|
8
|
100
|
66
|
|
|
15
|
if (not exists $left->{$key}) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
60
|
3
|
|
|
|
|
5
|
$left->{$key} = $right->{$key}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
# identical strings or references are merged identically |
63
|
|
|
|
|
|
|
elsif (_is_identical($left->{$key}, $right->{$key})) { |
64
|
1
|
|
|
|
|
2
|
1; # do nothing - keep left |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif (ref $left->{$key} eq 'HASH' and ref $right->{$key} eq 'HASH') { |
67
|
2
|
|
|
|
|
3
|
$left->{$key} = _uniq_map($left->{$key}, $right->{$key}, [ @{$path}, $key ]); |
|
2
|
|
|
|
|
6
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
2
|
|
|
|
|
3
|
croak 'Duplication of element ' . join '.', @{$path}, $key; |
|
2
|
|
|
|
|
163
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
4
|
|
|
|
|
6
|
return $left; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _improvise { |
77
|
0
|
|
|
0
|
|
0
|
my ($left, $right, $path) = @_; |
78
|
0
|
|
|
|
|
0
|
my ($name) = reverse @{$path}; |
|
0
|
|
|
|
|
0
|
|
79
|
0
|
0
|
|
|
|
0
|
if ($name =~ /^x_/) { |
80
|
0
|
0
|
|
|
|
0
|
if (ref($left) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
return _set_addition($left, $right, $path); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif (ref($left) eq 'HASH') { |
84
|
0
|
|
|
|
|
0
|
return _uniq_map($left, $right, $path); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
0
|
|
|
|
|
0
|
return _identical($left, $right, $path); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
0
|
croak sprintf "Can't merge '%s'", join '.', @{$path}; |
|
0
|
|
|
|
|
0
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _optional_features { |
94
|
4
|
|
|
4
|
|
6
|
my ($left, $right, $path) = @_; |
95
|
|
|
|
|
|
|
|
96
|
4
|
|
|
|
|
4
|
for my $key (keys %{$right}) { |
|
4
|
|
|
|
|
5
|
|
97
|
4
|
100
|
|
|
|
7
|
if (not exists $left->{$key}) { |
98
|
1
|
|
|
|
|
2
|
$left->{$key} = $right->{$key}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
3
|
|
|
|
|
4
|
for my $subkey (keys %{ $right->{$key} }) { |
|
3
|
|
|
|
|
6
|
|
102
|
5
|
100
|
|
|
|
8
|
next if $subkey eq 'prereqs'; |
103
|
3
|
50
|
|
|
|
5
|
if (not exists $left->{$key}{$subkey}) { |
104
|
0
|
|
|
|
|
0
|
$left->{$key}{$subkey} = $right->{$key}{$subkey}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
|
|
|
|
|
|
Carp::croak "Cannot merge two optional_features named '$key' with different '$subkey' values" |
108
|
2
|
100
|
|
2
|
|
8
|
if do { no warnings 'uninitialized'; $left->{$key}{$subkey} ne $right->{$key}{$subkey} }; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1315
|
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
239
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
8
|
require CPAN::Meta::Prereqs; |
113
|
|
|
|
|
|
|
$left->{$key}{prereqs} = |
114
|
|
|
|
|
|
|
CPAN::Meta::Prereqs->new($left->{$key}{prereqs}) |
115
|
1
|
|
|
|
|
7
|
->with_merged_prereqs(CPAN::Meta::Prereqs->new($right->{$key}{prereqs})) |
116
|
|
|
|
|
|
|
->as_string_hash; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
2
|
|
|
|
|
5
|
return $left; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my %default = ( |
124
|
|
|
|
|
|
|
abstract => \&_identical, |
125
|
|
|
|
|
|
|
author => \&_set_addition, |
126
|
|
|
|
|
|
|
dynamic_config => sub { |
127
|
|
|
|
|
|
|
my ($left, $right) = @_; |
128
|
|
|
|
|
|
|
return $left || $right; |
129
|
|
|
|
|
|
|
}, |
130
|
|
|
|
|
|
|
generated_by => sub { |
131
|
|
|
|
|
|
|
my ($left, $right) = @_; |
132
|
|
|
|
|
|
|
return join ', ', _uniq(split(/, /, $left), split(/, /, $right)); |
133
|
|
|
|
|
|
|
}, |
134
|
|
|
|
|
|
|
license => \&_set_addition, |
135
|
|
|
|
|
|
|
'meta-spec' => { |
136
|
|
|
|
|
|
|
version => \&_identical, |
137
|
|
|
|
|
|
|
url => \&_identical |
138
|
|
|
|
|
|
|
}, |
139
|
|
|
|
|
|
|
name => \&_identical, |
140
|
|
|
|
|
|
|
release_status => \&_identical, |
141
|
|
|
|
|
|
|
version => \&_identical, |
142
|
|
|
|
|
|
|
description => \&_identical, |
143
|
|
|
|
|
|
|
keywords => \&_set_addition, |
144
|
|
|
|
|
|
|
no_index => { map { ($_ => \&_set_addition) } qw/file directory package namespace/ }, |
145
|
|
|
|
|
|
|
optional_features => \&_optional_features, |
146
|
|
|
|
|
|
|
prereqs => sub { |
147
|
|
|
|
|
|
|
require CPAN::Meta::Prereqs; |
148
|
|
|
|
|
|
|
my ($left, $right) = map { CPAN::Meta::Prereqs->new($_) } @_[0,1]; |
149
|
|
|
|
|
|
|
return $left->with_merged_prereqs($right)->as_string_hash; |
150
|
|
|
|
|
|
|
}, |
151
|
|
|
|
|
|
|
provides => \&_uniq_map, |
152
|
|
|
|
|
|
|
resources => { |
153
|
|
|
|
|
|
|
license => \&_set_addition, |
154
|
|
|
|
|
|
|
homepage => \&_identical, |
155
|
|
|
|
|
|
|
bugtracker => \&_uniq_map, |
156
|
|
|
|
|
|
|
repository => \&_uniq_map, |
157
|
|
|
|
|
|
|
':default' => \&_improvise, |
158
|
|
|
|
|
|
|
}, |
159
|
|
|
|
|
|
|
':default' => \&_improvise, |
160
|
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub new { |
163
|
4
|
|
|
4
|
1
|
2395
|
my ($class, %arguments) = @_; |
164
|
4
|
50
|
|
|
|
16
|
croak 'default version required' if not exists $arguments{default_version}; |
165
|
4
|
|
|
|
|
36
|
my %mapping = %default; |
166
|
4
|
100
|
|
|
|
6
|
my %extra = %{ $arguments{extra_mappings} || {} }; |
|
4
|
|
|
|
|
22
|
|
167
|
4
|
|
|
|
|
9
|
for my $key (keys %extra) { |
168
|
3
|
50
|
|
|
|
7
|
if (ref($mapping{$key}) eq 'HASH') { |
169
|
0
|
|
|
|
|
0
|
$mapping{$key} = { %{ $mapping{$key} }, %{ $extra{$key} } }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { |
172
|
3
|
|
|
|
|
5
|
$mapping{$key} = $extra{$key}; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
return bless { |
176
|
|
|
|
|
|
|
default_version => $arguments{default_version}, |
177
|
4
|
|
|
|
|
13
|
mapping => _coerce_mapping(\%mapping, []), |
178
|
|
|
|
|
|
|
}, $class; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my %coderef_for = ( |
182
|
|
|
|
|
|
|
set_addition => \&_set_addition, |
183
|
|
|
|
|
|
|
uniq_map => \&_uniq_map, |
184
|
|
|
|
|
|
|
identical => \&_identical, |
185
|
|
|
|
|
|
|
improvise => \&_improvise, |
186
|
|
|
|
|
|
|
improvize => \&_improvise, # [sic] for backwards compatibility |
187
|
|
|
|
|
|
|
); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub _coerce_mapping { |
190
|
17
|
|
|
17
|
|
17
|
my ($orig, $map_path) = @_; |
191
|
17
|
|
|
|
|
9
|
my %ret; |
192
|
17
|
|
|
|
|
15
|
for my $key (keys %{$orig}) { |
|
17
|
|
|
|
|
33
|
|
193
|
116
|
|
|
|
|
83
|
my $value = $orig->{$key}; |
194
|
116
|
100
|
|
|
|
130
|
if (ref($orig->{$key}) eq 'CODE') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
195
|
100
|
|
|
|
|
107
|
$ret{$key} = $value; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
elsif (ref($value) eq 'HASH') { |
198
|
13
|
|
|
|
|
13
|
my $mapping = _coerce_mapping($value, [ @{$map_path}, $key ]); |
|
13
|
|
|
|
|
28
|
|
199
|
|
|
|
|
|
|
$ret{$key} = sub { |
200
|
19
|
|
|
19
|
|
20
|
my ($left, $right, $path) = @_; |
201
|
19
|
|
|
|
|
15
|
return _merge($left, $right, $mapping, [ @{$path} ]); |
|
19
|
|
|
|
|
31
|
|
202
|
13
|
|
|
|
|
45
|
}; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
elsif ($coderef_for{$value}) { |
205
|
3
|
|
|
|
|
5
|
$ret{$key} = $coderef_for{$value}; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
else { |
208
|
0
|
|
|
|
|
0
|
croak "Don't know what to do with " . join '.', @{$map_path}, $key; |
|
0
|
|
|
|
|
0
|
|
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
} |
211
|
17
|
|
|
|
|
38
|
return \%ret; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub merge { |
215
|
15
|
|
|
15
|
1
|
9742
|
my ($self, @items) = @_; |
216
|
15
|
|
|
|
|
21
|
my $current = {}; |
217
|
15
|
|
|
|
|
21
|
for my $next (@items) { |
218
|
31
|
100
|
66
|
|
|
138
|
if ( blessed($next) && $next->isa('CPAN::Meta') ) { |
|
|
50
|
|
|
|
|
|
219
|
1
|
|
|
|
|
4
|
$next = $next->as_struct; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
elsif ( ref($next) eq 'HASH' ) { |
222
|
|
|
|
|
|
|
my $cmc = CPAN::Meta::Converter->new( |
223
|
|
|
|
|
|
|
$next, default_version => $self->{default_version} |
224
|
30
|
|
|
|
|
92
|
); |
225
|
30
|
|
|
|
|
58
|
$next = $cmc->upgrade_fragment; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
else { |
228
|
0
|
|
|
|
|
0
|
croak "Don't know how to merge '$next'"; |
229
|
|
|
|
|
|
|
} |
230
|
31
|
|
|
|
|
60
|
$current = _merge($current, $next, $self->{mapping}, []); |
231
|
|
|
|
|
|
|
} |
232
|
9
|
|
|
|
|
47
|
return $current; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
1; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# ABSTRACT: Merging CPAN Meta fragments |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# vim: ts=2 sts=2 sw=2 et : |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
__END__ |