lib/Module/Install/Metadata.pm

filter: Statementstmt 53.6% 182 / 339 Branchbran 37.2% 61 / 164 Conditioncond 42.8% 21 / 49 MC/DCmcdc 24.1% 7 / 29 Subroutinesub 60.0% 33 / 55 Podpod 0.0% 0 / 38 totaltotal 45.1% 304 / 674 CC 104 SCAR 29.9
CC
104
Cov
48%
_write_mymeta_data
110.0
author_from
48.2
feature
42.0
CRAP 19.8
« lib/Module/Install.pm ↑ Summary lib/Module/Install/Admin/Include.pm »
1 package Module::Install::Metadata;
2  
3 49 ▶use strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 49 ▶use Module::Install::Base ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 49 ▶use vars qw{$VERSION @ISA $ISCORE};
Subroutine BEGIN: called CC=1 SCAR=0.0
7 49 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 49 $VERSION = '1.21';
9 49 @ISA = 'Module::Install::Base';
10 49 $ISCORE = 1;
11 }
12  
13 49 my @boolean_keys = qw{
14 sign
15 };
16  
17 49 my @scalar_keys = qw{
18 name
19 module_name
20 abstract
21 version
22 distribution_type
23 tests
24 installdirs
25 };
26  
27 49 my @tuple_keys = qw{
28 configure_requires
29 build_requires
30 requires
31 recommends
32 bundles
33 resources
34 };
35  
36 49 my @resource_keys = qw{
37 homepage
38 bugtracker
39 repository
40 };
41  
42 49 my @array_keys = qw{
43 keywords
44 author
45 };
46  
47 49 *authors = \&author;
48  
49 79 ▶sub Meta { shift }
Subroutine Meta: called CC=1 SCAR=0.0
Pod undocumented
50 0 ▶sub Meta_BooleanKeys { @boolean_keys }
Subroutine Meta_BooleanKeys: not called CC=1 SCAR=6.9
Pod undocumented
51 39 ▶sub Meta_ScalarKeys { @scalar_keys }
Subroutine Meta_ScalarKeys: called CC=1 SCAR=0.0
Pod undocumented
52 39 ▶sub Meta_TupleKeys { @tuple_keys }
Subroutine Meta_TupleKeys: called CC=1 SCAR=0.0
Pod undocumented
53 0 ▶sub Meta_ResourceKeys { @resource_keys }
Subroutine Meta_ResourceKeys: not called CC=1 SCAR=6.9
Pod undocumented
54 39 ▶sub Meta_ArrayKeys { @array_keys }
Subroutine Meta_ArrayKeys: called CC=1 SCAR=0.0
Pod undocumented
55  
56 49 foreach my $key ( @boolean_keys ) {
57 43 ▶ *$key = sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
58 43 my $self = shift;
59 43 ▶ if ( defined wantarray and not @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray and not @_) 42 1 43
Condition66%2/3
defined wantarray and not @_
!ll&&!rl&&r
1042
MC/DC50%1/2
defined wantarray and not @_
defined wantarray not @_
Truth table66%2/3
A and not(B)
A= defined wantarrayB= not @_
ABresult
0X0
100
111
60 42 return $self->{values}->{$key};
61 }
62 1 ▶ $self->{values}->{$key} = ( @_ ? $_[0] : 1 );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
63 1 return $self;
64 49 };
65 }
66  
67 49 foreach my $key ( @scalar_keys ) {
68 545 ▶ *$key = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
69 545 my $self = shift;
70 545 ▶ return $self->{values}->{$key} if defined wantarray and !@_;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray and not @_ 424 121 545
Condition66%2/3
defined wantarray and not @_
!ll&&!rl&&r
1210424
MC/DC50%1/2
defined wantarray and not @_
defined wantarray not @_
Truth table66%2/3
A and not(B)
A= defined wantarrayB= not @_
ABresult
0X0
100
111
71 121 $self->{values}->{$key} = shift;
72 121 return $self;
73 343 };
74 }
75  
76 49 foreach my $key ( @array_keys ) {
77 113 ▶ *$key = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
78 113 my $self = shift;
79 113 ▶ return $self->{values}->{$key} if defined wantarray and !@_;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray and not @_ 74 39 113
Condition66%2/3
defined wantarray and not @_
!ll&&!rl&&r
39074
MC/DC50%1/2
defined wantarray and not @_
defined wantarray not @_
Truth table66%2/3
A and not(B)
A= defined wantarrayB= not @_
ABresult
0X0
100
111
80 39 ▶ $self->{values}->{$key} ||= [];
Condition100%2/2
$self->{"values"}{$key} ||= []
l!l
237
MC/DC100%1/1
$self->{"values"}{$key} ||= []
$self->{"values"}{$key}
Truth table100%2/2
A
A= $self->{"values"}{$key}
Aresult
11
00
81 39 push @{$self->{values}->{$key}}, @_;
82 39 return $self;
83 98 };
84 }
85  
86 49 foreach my $key ( @resource_keys ) {
87 0 ▶ *$key = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
88 0 my $self = shift;
89 0 ▶ unless ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
90 0 ▶ return () unless $self->{values}->{resources};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"values"}{"resources"} 0 0 0
91 0 return map { $_->[1] }
92 0 grep { $_->[0] eq $key }
93 0 @{ $self->{values}->{resources} };
94 }
95 0 ▶ return $self->{values}->{resources}->{$key} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
96 0 ▶ my $uri = shift or die(
Branch: 1 branch
BranchTrueFalseTotal
my $uri = shift() or die "Did not provide a value to $key()" 0 0 0
97 "Did not provide a value to $key()"
98 );
99 0 $self->resources( $key => $uri );
100 0 return 1;
101 147 };
102 }
103  
104 49 foreach my $key ( grep { $_ ne "resources" } @tuple_keys) {
105 273 ▶ *$key = sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
106 273 my $self = shift;
107 273 ▶ return $self->{values}->{$key} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 169 104 273
108 104 my @added;
109 104 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 104 104 208
110 104 ▶ my $module = shift or last;
Branch: 1 branch
BranchTrueFalseTotal
my $module = shift() or last 104 0 104
111 104 ▶ my $version = shift || 0;
Condition50%1/2
shift() || 0
l!l
1040
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
112 104 push @added, [ $module, $version ];
113 }
114 104 push @{ $self->{values}->{$key} }, @added;
115 104 return map {@$_} @added;
116 245 };
117 }
118  
119 # Resource handling
120 49 my %lc_resource = map { $_ => 1 } qw{
121 homepage
122 license
123 bugtracker
124 repository
125 };
126  
127 44 ▶sub resources {
Subroutine resources: called CC=7 SCAR=20.6
Pod undocumented
128 44 my $self = shift;
129 44 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 44 88
130 44 ▶ my $name = shift or last;
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift() or last 44 0 44
131 44 ▶ my $value = shift or next;
Branch: 1 branch
BranchTrueFalseTotal
my $value = shift() or next 44 0 44
132 44 ▶ if ( $name eq lc $name and ! $lc_resource{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq lc $name and not $lc_resource{$name}) 0 44 44
Condition33%1/3
$name eq lc $name and not $lc_resource{$name}
!ll&&!rl&&r
0440
MC/DC0%0/2
$name eq lc $name and not $lc_resource{$name}
$name eq lc $name not $lc_resource{$name}
Truth table33%1/3
A and not(B)
A= $name eq lc $nameB= not $lc_resource{$name}
ABresult
0X0
100
111
133 0 die("Unsupported reserved lowercase resource '$name'");
134 }
135 44 ▶ $self->{values}->{resources} ||= [];
Condition100%2/2
$self->{"values"}{"resources"} ||= []
l!l
143
MC/DC100%1/1
$self->{"values"}{"resources"} ||= []
$self->{"values"}{"resources"}
Truth table100%2/2
A
A= $self->{"values"}{"resources"}
Aresult
11
00
136 44 push @{ $self->{values}->{resources} }, [ $name, $value ];
137 }
138 44 $self->{values}->{resources};
139 }
140  
141 # Aliases for build_requires that will have alternative
142 # meanings in some future version of META.yml.
143 4 ▶sub test_requires { shift->build_requires(@_) }
Subroutine test_requires: called CC=1 SCAR=0.0
Pod undocumented
144 0 ▶sub install_requires { shift->build_requires(@_) }
Subroutine install_requires: not called CC=1 SCAR=6.9
Pod undocumented
145  
146 # Aliases for installdirs options
147 1 ▶sub install_as_core { $_[0]->installdirs('perl') }
Subroutine install_as_core: called CC=1 SCAR=0.0
Pod undocumented
148 0 ▶sub install_as_cpan { $_[0]->installdirs('site') }
Subroutine install_as_cpan: not called CC=1 SCAR=6.9
Pod undocumented
149 0 ▶sub install_as_site { $_[0]->installdirs('site') }
Subroutine install_as_site: not called CC=1 SCAR=6.9
Pod undocumented
150 0 ▶sub install_as_vendor { $_[0]->installdirs('vendor') }
Subroutine install_as_vendor: not called CC=1 SCAR=6.9
Pod undocumented
151  
152 0 ▶sub dynamic_config {
Subroutine dynamic_config: not called CC=4 SCAR=30.0
Pod undocumented
153 0 my $self = shift;
154 0 ▶ my $value = @_ ? shift : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
155 0 ▶ if ( $self->{values}->{dynamic_config} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"values"}{"dynamic_config"}) 0 0 0
156 # Once dynamic we never change to static, for safety
157 0 return 0;
158 }
159 0 ▶ $self->{values}->{dynamic_config} = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
160 0 return 1;
161 }
162  
163 # Convenience command
164 0 ▶sub static_config {
Subroutine static_config: not called CC=1 SCAR=6.9
Pod undocumented
165 0 shift->dynamic_config(0);
166 }
167  
168 167 ▶sub perl_version {
Subroutine perl_version: called CC=4 SCAR=14.3
Pod undocumented
169 167 my $self = shift;
170 167 ▶ return $self->{values}->{perl_version} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 121 46 167
171 46 ▶ my $version = shift or die(
Branch: 1 branch
BranchTrueFalseTotal
my $version = shift() or die "Did not provide a value to perl_version()" 46 0 46
172 "Did not provide a value to perl_version()"
173 );
174  
175 # Normalize the version
176 46 $version = $self->_perl_version($version);
177  
178 # We don't support the really old versions
179 46 ▶ unless ( $version >= 5.005 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($version >= "5.005") 0 46 46
180 0 die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
181 }
182  
183 46 $self->{values}->{perl_version} = $version;
184 }
185  
186 32 ▶sub all_from {
Subroutine all_from: called CC=14 SCAR=30.8
Pod undocumented
187 32 my ( $self, $file ) = @_;
188  
189 32 ▶ unless ( defined($file) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 32 32
190 0 ▶ my $name = $self->name or die(
Branch: 1 branch
BranchTrueFalseTotal
my $name = $self->name or die "all_from called with no args without setting name() first" 0 0 0
191 "all_from called with no args without setting name() first"
192 );
193 0 $file = join('/', 'lib', split(/-/, $name)) . '.pm';
194 0 ▶ $file =~ s{.*/}{} unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
195 0 ▶ unless ( -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
196 0 die("all_from cannot find $file from $name");
197 }
198 }
199 32 ▶ unless ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 0 32 32
200 0 die("The path '$file' does not exist, or is not a file");
201 }
202  
203 32 $self->{values}{all_from} = $file;
204  
205 # Some methods pull from POD instead of code.
206 # If there is a matching .pod, use that instead
207 32 my $pod = $file;
208 32 $pod =~ s/\.pm$/.pod/i;
209 32 ▶ $pod = $file unless -e $pod;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $pod 32 0 32
210  
211 # Pull the different values
212 32 ▶ $self->name_from($file) unless $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name 0 32 32
213 32 ▶ $self->version_from($file) unless $self->version;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->version 28 4 32
214 32 ▶ $self->perl_version_from($file) unless $self->perl_version;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->perl_version 4 28 32
215 32 ▶ $self->author_from($pod) unless @{$self->author || []};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->author or [];} 25 7 32
Condition100%2/2
$self->author || []
l!l
725
MC/DC100%1/1
$self->author || []
$self->author
Truth table100%2/2
A
A= $self->author
Aresult
11
00
216 32 ▶ $self->license_from($pod) unless $self->license;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->license 27 5 32
217 32 ▶ $self->abstract_from($pod) unless $self->abstract;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->abstract 31 1 32
218  
219 32 return 1;
220 }
221  
222 0 ▶sub provides {
Subroutine provides: not called CC=3 SCAR=24.8
Pod undocumented
223 0 my $self = shift;
224 0 ▶ my $provides = ( $self->{values}->{provides} ||= {} );
Condition0%0/2
$self->{"values"}{"provides"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"values"}{"provides"} ||= {}
$self->{"values"}{"provides"}
Truth table0%0/2
A
A= $self->{"values"}{"provides"}
Aresult
11
00
225 0 ▶ %$provides = (%$provides, @_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
226 0 return $provides;
227 }
228  
229 0 ▶sub auto_provides {
Subroutine auto_provides: not called CC=4 SCAR=30.0
Pod undocumented
230 0 my $self = shift;
231 0 ▶ return $self unless $self->is_admin;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_admin 0 0 0
232 0 ▶ unless (-e 'MANIFEST') {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "MANIFEST") 0 0 0
233 0 warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
234 0 return $self;
235 }
236 # Avoid spurious warnings as we are not checking manifest here.
237 0 ▶ local $SIG{__WARN__} = sub {1};
Subroutine __ANON__: not called CC=1 SCAR=6.9
238 0 require ExtUtils::Manifest;
239 0 ▶ local *ExtUtils::Manifest::manicheck = sub { return };
Subroutine __ANON__: not called CC=1 SCAR=6.9
240  
241 0 require Module::Build;
242 0 my $build = Module::Build->new(
243 dist_name => $self->name,
244 dist_version => $self->version,
245 license => $self->license,
246 );
247 0 ▶ $self->provides( %{ $build->find_dist_packages || {} } );
Condition0%0/2
$build->find_dist_packages || {}
l!l
00
MC/DC0%0/1
$build->find_dist_packages || {}
$build->find_dist_packages
Truth table0%0/2
A
A= $build->find_dist_packages
Aresult
11
00
248 }
249  
250 0 ▶sub feature {
Subroutine feature: not called CC=6 SCAR=37.4
Pod undocumented
251 0 my $self = shift;
252 0 my $name = shift;
253 0 ▶ my $features = ( $self->{values}->{features} ||= [] );
Condition0%0/2
$self->{"values"}{"features"} ||= []
l!l
00
MC/DC0%0/1
$self->{"values"}{"features"} ||= []
$self->{"values"}{"features"}
Truth table0%0/2
A
A= $self->{"values"}{"features"}
Aresult
11
00
254 0 my $mods;
255  
256 0 ▶ if ( @_ == 1 and ref( $_[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0]) { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
257 # The user used ->feature like ->features by passing in the second
258 # argument as a reference. Accomodate for that.
259 0 $mods = $_[0];
260 } else {
261 0 $mods = \@_;
262 }
263  
264 0 my $count = 0;
265 push @$features, (
266 $name => [
267 map {
268 0 ▶ ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 0 0 0
ref $_ eq 'HASH' ? : 0 0 0
269 } @$mods
270 ]
271 );
272  
273 0 return @$features;
274 }
275  
276 0 ▶sub features {
Subroutine features: not called CC=3 SCAR=24.8
Pod undocumented
277 0 my $self = shift;
278 0 ▶ while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
279 0 $self->feature( $name, @$mods );
280 }
281 return $self->{values}->{features}
282 0 ▶ ? @{ $self->{values}->{features} }
Branch: 1 branch
BranchTrueFalseTotal
$self->{'values'}{'features'} ? : 0 0 0
283 : ();
284 }
285  
286 5 ▶sub no_index {
Subroutine no_index: called CC=2 SCAR=7.0
Pod undocumented
287 5 my $self = shift;
288 5 my $type = shift;
289 5 ▶ push @{ $self->{values}->{no_index}->{$type} }, @_ if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 5 0 5
290 5 return $self->{values}->{no_index};
291 }
292  
293 0 ▶sub read {
Subroutine read: not called CC=5 SCAR=34.0
Pod undocumented
294 0 my $self = shift;
295 0 $self->include_deps( 'YAML::Tiny', 0 );
296  
297 0 require YAML::Tiny;
298 0 my $data = YAML::Tiny::LoadFile('META.yml');
299  
300 # Call methods explicitly in case user has already set some values.
301 0 ▶ while ( my ( $key, $value ) = each %$data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$data) 0 0 0
302 0 ▶ next unless $self->can($key);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($key) 0 0 0
303 0 ▶ if ( ref $value eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 0 0 0
304 0 ▶ while ( my ( $module, $version ) = each %$value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$value) 0 0 0
305 0 $self->can($key)->($self, $module => $version );
306 }
307 } else {
308 0 $self->can($key)->($self, $value);
309 }
310 }
311 0 return $self;
312 }
313  
314 39 ▶sub write {
Subroutine write: called CC=2 SCAR=7.0
Pod undocumented
315 39 my $self = shift;
316 39 ▶ return $self unless $self->is_admin;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_admin 0 39 39
317 39 $self->admin->write_meta;
318 39 return $self;
319 }
320  
321 28 ▶sub version_from {
Subroutine version_from: called CC=1 SCAR=0.0
Pod undocumented
322 28 require ExtUtils::MM_Unix;
323 28 my ( $self, $file ) = @_;
324 28 $self->version( ExtUtils::MM_Unix->parse_version($file) );
325  
326 # for version integrity check
327 28 $self->makemaker_args( VERSION_FROM => $file );
328 }
329  
330 31 ▶sub abstract_from {
Subroutine abstract_from: called CC=1 SCAR=0.0
Pod undocumented
331 31 require ExtUtils::MM_Unix;
332 31 my ( $self, $file ) = @_;
333 31 $self->abstract(
334 bless(
335 { DISTNAME => $self->name },
336 'ExtUtils::MM_Unix'
337 )->parse_abstract($file)
338 );
339 }
340  
341 # Add both distribution and module name
342 0 ▶sub name_from {
Subroutine name_from: not called CC=3 SCAR=24.8
Pod undocumented
343 0 my ($self, $file) = @_;
344 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (Module::Install::_read($file) =~ / ^ \s* package \s* ([\w:]+) [\s|;]* /imsx) { } 0 0 0
345 Module::Install::_read($file) =~ m/
346 ^ \s*
347 package \s*
348 ([\w:]+)
349 [\s|;]*
350 /ixms
351 ) {
352 0 my ($name, $module_name) = ($1, $1);
353 0 $name =~ s{::}{-}g;
354 0 $self->name($name);
355 0 ▶ unless ( $self->module_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->module_name) 0 0 0
356 0 $self->module_name($module_name);
357 }
358 } else {
359 0 die("Cannot determine name from $file\n");
360 }
361 }
362  
363 11 ▶sub _extract_perl_version {
Subroutine _extract_perl_version: called CC=2 SCAR=6.9
364 11 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ / ^\s* (?:use|require) \s* v? ([\d_\.]+) \s* ; /imsx) { } 10 1 11
365 $_[0] =~ m/
366 ^\s*
367 (?:use|require) \s*
368 v?
369 ([\d_\.]+)
370 \s* ;
371 /ixms
372 ) {
373 10 my $perl_version = $1;
374 10 $perl_version =~ s{_}{}g;
375 10 return $perl_version;
376 } else {
377 1 return;
378 }
379 }
380  
381 8 ▶sub perl_version_from {
Subroutine perl_version_from: called CC=2 SCAR=7.9
Pod undocumented
382 8 my $self = shift;
383 8 my $perl_version=_extract_perl_version(Module::Install::_read($_[0]));
384 8 ▶ if ($perl_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_version) { } 8 0 8
385 8 $self->perl_version($perl_version);
386 } else {
387 0 warn "Cannot determine perl version info from $_[0]\n";
388 0 return;
389 }
390 }
391  
392 25 ▶sub author_from {
Subroutine author_from: called CC=11 SCAR=38.8
Pod undocumented
393 25 my $self = shift;
394 25 my $content = Module::Install::_read($_[0]);
395 25 ▶ if ($content =~ m/
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ / =head \d \s+ (?:authors?)\b \s* ([^\n]*) | =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]*) /imsx) { } 25 0 25
396 =head \d \s+ (?:authors?)\b \s*
397 ([^\n]*)
398 |
399 =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
400 .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
401 ([^\n]*)
402 /ixms) {
403 25 ▶ my $author = $1 || $2;
Condition33%1/3
$1 || $2
l!l&&r!l&&!r
2500
MC/DC0%0/2
$1 || $2
$1 $2
Truth table33%1/3
A || B
A= $1B= $2
ABresult
1X1
011
000
404  
405 # XXX: ugly but should work anyway...
406 25 ▶ if (eval "require Pod::Escapes; 1") {
Branch: 2 branches
BranchTrueFalseTotal
if (eval 'require Pod::Escapes; 1') { } 25 0 25
elsif (eval 'require Pod::Text; 1' and $Pod::Text::VERSION < 3) { } 0 0 0
407 # Pod::Escapes has a mapping table.
408 # It's in core of perl >= 5.9.3, and should be installed
409 # as one of the Pod::Simple's prereqs, which is a prereq
410 # of Pod::Text 3.x (see also below).
411 25 $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
412 {
413 defined $2
414 ? chr($2)
415 : defined $Pod::Escapes::Name2character_number{$1}
416 ? chr($Pod::Escapes::Name2character_number{$1})
417 1 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
defined $2 ? : 0 1 1
defined $Pod::Escapes::Name2character_number{$1} ? : 1 0 1
418 0 warn "Unknown escape: E<$1>";
419 0 "E<$1>";
420 };
421 }gex;
422 }
423 ▶ elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) {
Condition0%0/3
eval "require Pod::Text; 1" and $Pod::Text::VERSION < 3
!ll&&!rl&&r
000
MC/DC0%0/2
eval "require Pod::Text; 1" and $Pod::Text::VERSION < 3
eval "require Pod::Text; 1" $Pod::Text::VERSION < 3
Truth table0%0/3
A and B
A= eval "require Pod::Text; 1"B= $Pod::Text::VERSION < 3
ABresult
0X0
100
111
424 # Pod::Text < 3.0 has yet another mapping table,
425 # though the table name of 2.x and 1.x are different.
426 # (1.x is in core of Perl < 5.6, 2.x is in core of
427 # Perl < 5.9.3)
428 0 ▶ my $mapping = ($Pod::Text::VERSION < 2)
Branch: 1 branch
BranchTrueFalseTotal
$Pod::Text::VERSION < 2 ? : 0 0 0
429 ? \%Pod::Text::HTML_Escapes
430 : \%Pod::Text::ESCAPES;
431 0 $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
432 {
433 defined $2
434 ? chr($2)
435 : defined $mapping->{$1}
436 ? $mapping->{$1}
437 0 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
defined $2 ? : 0 0 0
defined $mapping->{$1} ? : 0 0 0
438 0 warn "Unknown escape: E<$1>";
439 0 "E<$1>";
440 };
441 }gex;
442 }
443 else {
444 0 $author =~ s{E<lt>}{<}g;
445 0 $author =~ s{E<gt>}{>}g;
446 }
447 25 $self->author($author);
448 } else {
449 0 warn "Cannot determine author info from $_[0]\n";
450 }
451 }
452  
453 #Stolen from M::B
454 49 my %license_urls = (
455 perl => 'http://dev.perl.org/licenses/',
456 apache => 'http://apache.org/licenses/LICENSE-2.0',
457 artistic => 'http://opensource.org/licenses/artistic-license.php',
458 lgpl => 'http://opensource.org/licenses/lgpl-license.php',
459 bsd => 'http://opensource.org/licenses/bsd-license.php',
460 gpl => 'http://opensource.org/licenses/gpl-license.php',
461 gpl2 => 'http://opensource.org/licenses/gpl-2.0.php',
462 gpl3 => 'http://opensource.org/licenses/gpl-3.0.html',
463 mit => 'http://opensource.org/licenses/mit-license.php',
464 mozilla => 'http://opensource.org/licenses/mozilla1.1.php',
465 open_source => undef,
466 unrestricted => undef,
467 restrictive => undef,
468 unknown => undef,
469  
470 # these are not actually allowed in meta-spec v1.4 but are left here for compatibility:
471 apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1',
472 artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php',
473 lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php',
474 lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html',
475 );
476  
477 160 ▶sub license {
Subroutine license: called CC=5 SCAR=16.4
Pod undocumented
478 160 my $self = shift;
479 160 ▶ return $self->{values}->{license} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 116 44 160
480 44 ▶ my $license = shift or die(
Branch: 1 branch
BranchTrueFalseTotal
my $license = shift() or die "Did not provide a value to license()" 44 0 44
481 'Did not provide a value to license()'
482 );
483 44 ▶ $license = __extract_license($license) || lc $license;
Condition66%2/3
__extract_license($license) || lc $license
l!l&&r!l&&!r
1430
MC/DC0%0/2
__extract_license($license) || lc $license
__extract_license($license) lc $license
Truth table66%2/3
A || B
A= __extract_license($license)B= lc $license
ABresult
1X1
011
000
484 44 $self->{values}->{license} = $license;
485  
486 # Automatically fill in license URLs
487 44 ▶ if ( $license_urls{$license} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($license_urls{$license}) 44 0 44
488 44 $self->resources( license => $license_urls{$license} );
489 }
490  
491 44 return 1;
492 }
493  
494 36 ▶sub _extract_license {
Subroutine _extract_license: called CC=2 SCAR=7.0
495 36 my $pod = shift;
496 36 my $matched;
497 36 ▶ return __extract_license(
Condition66%2/3
__extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx) || __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
l!l&&r!l&&!r
4320
MC/DC0%0/2
__extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx) || __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
__extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx) __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
Truth table66%2/3
A || B
A= __extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx)B= __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
ABresult
1X1
011
000
498 ($matched) = $pod =~ m/
499 (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?)
500 (=head \d.*|=cut.*|)\z
501 /xms
502 ) || __extract_license(
503 ($matched) = $pod =~ m/
504 (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?)
505 (=head \d.*|=cut.*|)\z
506 /xms
507 );
508 }
509  
510 112 ▶sub __extract_license {
Subroutine __extract_license: called CC=4 SCAR=13.9
511 112 ▶ my $license_text = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $license_text = shift() or return 80 32 112
512 80 my @phrases = (
513 '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1,
514 '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1,
515 'Artistic and GPL' => 'perl', 1,
516 'GNU general public license' => 'gpl', 1,
517 'GNU public license' => 'gpl', 1,
518 'GNU lesser general public license' => 'lgpl', 1,
519 'GNU lesser public license' => 'lgpl', 1,
520 'GNU library general public license' => 'lgpl', 1,
521 'GNU library public license' => 'lgpl', 1,
522 'GNU Free Documentation license' => 'unrestricted', 1,
523 'GNU Affero General Public License' => 'open_source', 1,
524 '(?:Free)?BSD license' => 'bsd', 1,
525 'Artistic license 2\.0' => 'artistic_2', 1,
526 'Artistic license' => 'artistic', 1,
527 'Apache (?:Software )?license' => 'apache', 1,
528 'GPL' => 'gpl', 1,
529 'LGPL' => 'lgpl', 1,
530 'BSD' => 'bsd', 1,
531 'Artistic' => 'artistic', 1,
532 'MIT' => 'mit', 1,
533 'Mozilla Public License' => 'mozilla', 1,
534 'Q Public License' => 'open_source', 1,
535 'OpenSSL License' => 'unrestricted', 1,
536 'SSLeay License' => 'unrestricted', 1,
537 'zlib License' => 'open_source', 1,
538 'proprietary' => 'proprietary', 0,
539 );
540 80 ▶ while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@phrases, 0, 3)) 1203 43 1246
541 1203 $pattern =~ s#\s+#\\s+#gs;
542 1203 ▶ if ( $license_text =~ /\b$pattern\b/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($license_text =~ /\b$pattern\b/i) 37 1166 1203
543 37 return $license;
544 }
545 }
546 43 return '';
547 }
548  
549 27 ▶sub license_from {
Subroutine license_from: called CC=2 SCAR=8.4
Pod undocumented
550 27 my $self = shift;
551 27 ▶ if (my $license=_extract_license(Module::Install::_read($_[0]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $license = _extract_license(Module::Install::_read($_[0]))) { } 27 0 27
552 27 $self->license($license);
553 } else {
554 0 warn "Cannot determine license info from $_[0]\n";
555 0 return 'unknown';
556 }
557 }
558  
559 6 ▶sub _extract_bugtracker {
Subroutine _extract_bugtracker: called CC=1 SCAR=0.0
560 6 my @links = $_[0] =~ m#L<(
561 https?\Q://rt.cpan.org/\E[^>]+|
562 https?\Q://github.com/\E[\w_]+/[\w_]+/issues|
563 https?\Q://code.google.com/p/\E[\w_\-]+/issues/list
564 )>#gx;
565 6 my %links;
566 6 @links{@links}=();
567 6 @links=keys %links;
568 6 return @links;
569 }
570  
571 0 ▶sub bugtracker_from {
Subroutine bugtracker_from: not called CC=3 SCAR=24.8
Pod undocumented
572 0 my $self = shift;
573 0 my $content = Module::Install::_read($_[0]);
574 0 my @links = _extract_bugtracker($content);
575 0 ▶ unless ( @links ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@links) 0 0 0
576 0 warn "Cannot determine bugtracker info from $_[0]\n";
577 0 return 0;
578 }
579 0 ▶ if ( @links > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@links > 1) 0 0 0
580 0 warn "Found more than one bugtracker link in $_[0]\n";
581 0 return 0;
582 }
583  
584 # Set the bugtracker
585 0 bugtracker( $links[0] );
586 0 return 1;
587 }
588  
589 8 ▶sub requires_from {
Subroutine requires_from: called CC=2 SCAR=6.9
Pod undocumented
590 8 my $self = shift;
591 8 my $content = Module::Install::_readperl($_[0]);
592 8 my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg;
593 8 ▶ while ( @requires ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@requires) 8 8 16
594 8 my $module = shift @requires;
595 8 my $version = shift @requires;
596 8 $self->requires( $module => $version );
597 }
598 }
599  
600 1 ▶sub test_requires_from {
Subroutine test_requires_from: called CC=2 SCAR=6.9
Pod undocumented
601 1 my $self = shift;
602 1 my $content = Module::Install::_readperl($_[0]);
603 1 my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg;
604 1 ▶ while ( @requires ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@requires) 1 1 2
605 1 my $module = shift @requires;
606 1 my $version = shift @requires;
607 1 $self->test_requires( $module => $version );
608 }
609 }
610  
611 # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
612 # numbers (eg, 5.006001 or 5.008009).
613 # Also, convert double-part versions (eg, 5.8)
614 54 ▶sub _perl_version {
Subroutine _perl_version: called CC=3 SCAR=11.1
615 54 my $v = $_[-1];
616 54 $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e;
617 54 ▶ $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e;
Condition100%2/2
$3 || 0
l!l
33
MC/DC100%1/1
$3 || 0
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
618 54 $v =~ s/(\.\d\d\d)000$/$1/;
619 54 $v =~ s/_.+$//;
620 54 ▶ if ( ref($v) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) 0 54 54
621 # Numify
622 0 $v = $v + 0;
623 }
624 54 return $v;
625 }
626  
627 1 ▶sub add_metadata {
Subroutine add_metadata: called CC=3 SCAR=11.1
Pod undocumented
628 1 my $self = shift;
629 1 my %hash = @_;
630 1 for my $key (keys %hash) {
631 1 ▶ warn "add_metadata: $key is not prefixed with 'x_'.\n" .
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /^x_/ 0 1 1
632 "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/;
633 1 $self->{values}->{$key} = $hash{$key};
634 }
635 }
636  
637  
638 ######################################################################
639 # MYMETA Support
640  
641 0 ▶sub WriteMyMeta {
Subroutine WriteMyMeta: not called CC=1 SCAR=6.9
Pod undocumented
642 0 die "WriteMyMeta has been deprecated";
643 }
644  
645 0 ▶sub write_mymeta_yaml {
Subroutine write_mymeta_yaml: not called CC=3 SCAR=24.8
Pod undocumented
646 0 my $self = shift;
647  
648 # We need YAML::Tiny to write the MYMETA.yml file
649 0 ▶ unless ( eval { require YAML::Tiny; 1; } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require YAML::Tiny; 1 } }) 0 0 0
650 0 return 1;
651 }
652  
653 # Generate the data
654 0 ▶ my $meta = $self->_write_mymeta_data or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $meta = $self->_write_mymeta_data or return 1 0 0 0
655  
656 # Save as the MYMETA.yml file
657 0 print "Writing MYMETA.yml\n";
658 0 YAML::Tiny::DumpFile('MYMETA.yml', $meta);
659 }
660  
661 0 ▶sub write_mymeta_json {
Subroutine write_mymeta_json: not called CC=3 SCAR=24.8
Pod undocumented
662 0 my $self = shift;
663  
664 # We need JSON to write the MYMETA.json file
665 0 ▶ unless ( eval { require JSON; 1; } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require JSON; 1 } }) 0 0 0
666 0 return 1;
667 }
668  
669 # Generate the data
670 0 ▶ my $meta = $self->_write_mymeta_data or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $meta = $self->_write_mymeta_data or return 1 0 0 0
671  
672 # Save as the MYMETA.yml file
673 0 print "Writing MYMETA.json\n";
674 0 Module::Install::_write(
675 'MYMETA.json',
676 JSON->new->pretty(1)->canonical->encode($meta),
677 );
678 }
679  
680 0 ▶sub _write_mymeta_data {
Subroutine _write_mymeta_data: not called CC=10 SCAR=47.0
681 0 my $self = shift;
682  
683 # If there's no existing META.yml there is nothing we can do
684 0 ▶ return undef unless -f 'META.yml';
Branch: 1 branch
BranchTrueFalseTotal
unless -f "META.yml" 0 0 0
685  
686 # We need Parse::CPAN::Meta to load the file
687 0 ▶ unless ( eval { require Parse::CPAN::Meta; 1; } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Parse::CPAN::Meta; 1 } }) 0 0 0
688 0 return undef;
689 }
690  
691 # Merge the perl version into the dependencies
692 0 my $val = $self->Meta->{values};
693 0 my $perl = delete $val->{perl_version};
694 0 ▶ if ( $perl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl) 0 0 0
695 0 ▶ $val->{requires} ||= [];
Condition0%0/2
$val->{"requires"} ||= []
l!l
00
MC/DC0%0/1
$val->{"requires"} ||= []
$val->{"requires"}
Truth table0%0/2
A
A= $val->{"requires"}
Aresult
11
00
696 0 my $requires = $val->{requires};
697  
698 # Canonize to three-dot version after Perl 5.6
699 0 ▶ if ( $perl >= 5.006 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl >= "5.006") 0 0 0
700 0 ▶ $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e
Condition0%0/4
$2 || 0
l!l
00
$3 || 0
l!l
00
MC/DC0%0/1
$2 || 0
$2
MC/DC0%0/1
$3 || 0
$3
Truth table0%0/2
A
A= $2
Aresult
11
00
Truth table0%0/2
A
A= $3
Aresult
11
00
701 }
702 0 unshift @$requires, [ perl => $perl ];
703 }
704  
705 # Load the advisory META.yml file
706 0 my @yaml = Parse::CPAN::Meta::LoadFile('META.yml');
707 0 my $meta = $yaml[0];
708  
709 # Overwrite the non-configure dependency hashes
710 0 delete $meta->{requires};
711 0 delete $meta->{build_requires};
712 0 delete $meta->{recommends};
713 0 ▶ if ( exists $val->{requires} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $val->{"requires"}) 0 0 0
714 0 $meta->{requires} = { map { @$_ } @{ $val->{requires} } };
715 }
716 0 ▶ if ( exists $val->{build_requires} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $val->{"build_requires"}) 0 0 0
717 0 $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } };
718 }
719  
720 0 return $meta;
721 }
722  
723 49 1;
« lib/Module/Install.pm ↑ Summary lib/Module/Install/Admin/Include.pm »