lib/Module/Install/Admin/Metadata.pm

filter: Statementstmt 67.5% 75 / 111 Branchbran 47.9% 23 / 48 Conditioncond 44.4% 8 / 18 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 63.6% 7 / 11 Podpod 0.0% 0 / 6 totaltotal 56.8% 116 / 204 CC 38 SCAR 37.3
CC
38
Cov
60%
dump_meta
58.5
remove_meta
30.0
meta_generated_by_us
6.0
CRAP 41.5
« lib/Module/Install/AutoInstall.pm ↑ Summary lib/Module/Install/Makefile.pm »
1 package Module::Install::Admin::Metadata;
2  
3 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use YAML::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use Module::Install::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 46 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 46 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 46 $VERSION = '1.21';
10 46 @ISA = 'Module::Install::Base';
11 }
12  
13 0 ▶sub read_meta {
Subroutine read_meta: not called CC=1 SCAR=6.9
Pod undocumented
14 0 (YAML::Tiny::LoadFile('META.yml'))[0];
15 }
16  
17 0 ▶sub meta_generated_by_us {
Subroutine meta_generated_by_us: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my $meta = $_[0]->read_meta;
19 0 my $want = ref($_[0]->_top);
20 0 ▶ if ( defined $_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
21 0 $want .= " version $_[1]";
22 }
23 0 return $meta->{generated_by} =~ /^\Q$want\E/;
24 }
25  
26 0 ▶sub remove_meta {
Subroutine remove_meta: not called CC=5 SCAR=34.0
Pod undocumented
27 0 my $self = shift;
28 0 my $ver = $self->_top->VERSION;
29 0 ▶ return unless -f 'META.yml';
Branch: 1 branch
BranchTrueFalseTotal
unless -f "META.yml" 0 0 0
30 0 ▶ return unless $self->meta_generated_by_us($ver);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->meta_generated_by_us($ver) 0 0 0
31 0 ▶ unless ( -w 'META.yml' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w "META.yml") 0 0 0
32 0 warn "Can't remove META.yml file. Not writable.\n";
33 0 return;
34 }
35 # warn "Removing auto-generated META.yml\n";
36 0 ▶ unless ( unlink 'META.yml' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink "META.yml") 0 0 0
37 0 die "Couldn't unlink META.yml:\n$!";
38 }
39 0 return;
40 }
41  
42 39 ▶sub write_meta {
Subroutine write_meta: called CC=3 SCAR=12.3
Pod undocumented
43 39 my $self = shift;
44 39 ▶ if ( -f "META.yml" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f 'META.yml') { } 0 39 39
45 0 ▶ return unless $self->meta_generated_by_us();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->meta_generated_by_us 0 0 0
46 } else {
47 39 $self->clean_files('META.yml');
48 }
49 39 print "Writing META.yml\n";
50 39 Module::Install::_write("META.yml", $self->dump_meta);
51 39 return;
52 }
53  
54 39 ▶sub dump_meta {
Subroutine dump_meta: called CC=31 SCAR=40.7
Pod undocumented
55 39 my $self = shift;
56 39 my $pkg = ref( $self->_top );
57 39 my $ver = $self->_top->VERSION;
58 39 my $val = $self->Meta->{values};
59  
60 39 delete $val->{sign};
61  
62 # Dependencies MUST be assumed to be dynamic unless indicated
63 # otherwise, otherwise a negligent author who accidentally forgets
64 # to say which will release modules that break on some platforms.
65 39 ▶ unless ( defined $val->{dynamic_config} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val->{"dynamic_config"}) 39 0 39
66 39 $val->{dynamic_config} = 1;
67 }
68  
69 39 my $perl_version = delete $val->{perl_version};
70 39 ▶ if ( $perl_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_version) 37 2 39
71 37 ▶ $val->{requires} ||= [];
Condition100%2/2
$val->{"requires"} ||= []
l!l
532
MC/DC100%1/1
$val->{"requires"} ||= []
$val->{"requires"}
Truth table100%2/2
A
A= $val->{"requires"}
Aresult
11
00
72 37 my $requires = $val->{requires};
73  
74 # Issue warnings for unversioned core modules that are
75 # already satisfied by the Perl version dependency.
76 37 require Module::CoreList;
77 37 my $corelist = $Module::CoreList::version{$perl_version};
78 37 ▶ if ( $corelist ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($corelist) 37 0 37
79 0 my @bad = grep { exists $corelist->{$_} }
80 0 map { $_->[0] }
81 37 grep { ! $_->[1] }
82 @$requires;
83 37 foreach ( @bad ) {
84 # print "WARNING: Unversioned dependency on '$_' is pointless when Perl minimum version is $perl_version\n";
85 }
86 }
87  
88 # Canonicalize to three-dot version after Perl 5.6
89 37 ▶ if ( $perl_version >= 5.006 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_version >= "5.006") 0 37 37
90 0 ▶ $perl_version =~ 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
91 }
92 37 unshift @$requires, [ perl => $perl_version ];
93 }
94  
95 # Set a default 'unknown' license
96 39 ▶ unless ( $val->{license} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val->{"license"}) 0 39 39
97 0 warn "No license specified, setting license = 'unknown'\n";
98 0 $val->{license} = 'unknown';
99 }
100  
101 # Most distributions are modules
102 39 ▶ $val->{distribution_type} ||= 'module';
Condition50%1/2
$val->{"distribution_type"} ||= "module"
l!l
039
MC/DC0%0/1
$val->{"distribution_type"} ||= "module"
$val->{"distribution_type"}
Truth table50%1/2
A
A= $val->{"distribution_type"}
Aresult
11
00
103  
104 # Check and derive names
105 39 ▶ if ( $val->{name} =~ /::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val->{"name"} =~ /::/) 0 39 39
106 0 my $name = $val->{name};
107 0 $name =~ s/::/-/g;
108 0 die "Error in name(): '$val->{name}' should be '$name'!\n";
109 }
110 39 ▶ if ( $val->{module_name} and ! $val->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val->{"module_name"} and not $val->{"name"}) 0 39 39
Condition33%1/3
$val->{"module_name"} and not $val->{"name"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$val->{"module_name"} and not $val->{"name"}
$val->{"module_name"} not $val->{"name"}
Truth table33%1/3
A and not(B)
A= $val->{"module_name"}B= not $val->{"name"}
ABresult
0X0
100
111
111 0 $val->{name} = $val->{module_name};
112 0 $val->{name} =~ s/::/-/g;
113 }
114  
115 # Apply default no_index entries
116 39 ▶ $val->{no_index} ||= {};
Condition100%2/2
$val->{"no_index"} ||= {}
l!l
435
MC/DC100%1/1
$val->{"no_index"} ||= {}
$val->{"no_index"}
Truth table100%2/2
A
A= $val->{"no_index"}
Aresult
11
00
117 39 ▶ $val->{no_index}->{directory} ||= [];
Condition100%2/2
$val->{"no_index"}{"directory"} ||= []
l!l
435
MC/DC100%1/1
$val->{"no_index"}{"directory"} ||= []
$val->{"no_index"}{"directory"}
Truth table100%2/2
A
A= $val->{"no_index"}{"directory"}
Aresult
11
00
118 SCOPE: {
119 39 my %seen = ();
120 $val->{no_index}->{directory} = [
121 sort
122 51 grep { not $seen{$_}++ }
123 320 grep { -d $_ } (
124 39 @{$val->{no_index}->{directory}},
125 qw{
126 share inc t xt test
127 example examples demo
128 },
129 )
130 ];
131 }
132  
133 # Generate the structure we'll be dumping
134 my $meta = {
135 resources => {},
136 license => $val->{license},
137 dynamic_config => $val->{dynamic_config},
138 39 };
139 39 foreach my $key ( $self->Meta_ScalarKeys ) {
140 273 ▶ next if $key eq 'installdirs';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "installdirs" 39 234 273
141 234 ▶ next if $key eq 'tests';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "tests" 39 195 234
142 195 ▶ $meta->{$key} = $val->{$key} if exists $val->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $val->{$key} 146 49 195
143 }
144 39 foreach my $key ( $self->Meta_ArrayKeys ) {
145 78 ▶ $meta->{$key} = $val->{$key} if exists $val->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $val->{$key} 34 44 78
146 }
147 39 foreach my $key ( $self->Meta_TupleKeys ) {
148 234 ▶ next unless exists $val->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $val->{$key} 78 156 234
149 156 $meta->{$key} = { map { @$_ } @{ $val->{$key} } };
150 }
151  
152 39 ▶ if ( $self->_cmp( $meta->{configure_requires}->{'ExtUtils::MakeMaker'}, '6.36' ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_cmp($meta->{"configure_requires"}{"ExtUtils::MakeMaker"}, "6.36") > 0) 0 39 39
153 # After this version ExtUtils::MakeMaker requires perl 5.6
154 0 ▶ unless ( $perl_version && $self->perl_version($perl_version) >= 5.006 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($perl_version and $self->perl_version($perl_version) >= "5.006") 0 0 0
Condition0%0/3
$perl_version and $self->perl_version($perl_version) >= "5.006"
!ll&&!rl&&r
000
MC/DC0%0/2
$perl_version and $self->perl_version($perl_version) >= "5.006"
$perl_version $self->perl_version($perl_version) >= "5.006"
Truth table0%0/3
A and B
A= $perl_versionB= $self->perl_version($perl_version) >= "5.006"
ABresult
0X0
100
111
155 0 $meta->{requires}->{perl} = '5.006';
156 }
157 }
158  
159 39 ▶ $meta->{provides} = $val->{provides} if $val->{provides};
Branch: 1 branch
BranchTrueFalseTotal
if $val->{"provides"} 0 39 39
160 39 $meta->{no_index} = $val->{no_index};
161 39 $meta->{generated_by} = "$pkg version $ver";
162 39 $meta->{'meta-spec'} = {
163 version => 1.4,
164 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
165 };
166 39 ▶ unless ( scalar keys %{$meta->{resources}} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %{$$meta{"resources"};}) 0 39 39
167 0 delete $meta->{resources};
168 }
169  
170 # Support version.pm versions
171 39 ▶ if ( UNIVERSAL::isa($meta->{version}, 'version') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($meta->{"version"}, "version")) 0 39 39
172 0 $meta->{version} = $meta->{version}->numify;
173 }
174  
175 # extra metadata
176 39 foreach my $key (grep /^x_/, keys %$val) {
177 1 $meta->{$key} = $val->{$key};
178 }
179  
180 39 YAML::Tiny::Dump($meta);
181 }
182  
183  
184  
185  
186  
187 ######################################################################
188 # MYMETA.yml Support
189  
190 0 ▶sub WriteMyMeta {
Subroutine WriteMyMeta: not called CC=1 SCAR=6.9
Pod undocumented
191 0 my $self = shift;
192 0 $self->configure_requires( 'YAML::Tiny' => 1.36 );
193 0 $self->write_mymeta;
194 0 return 1;
195 }
196  
197 46 1;
« lib/Module/Install/AutoInstall.pm ↑ Summary lib/Module/Install/Makefile.pm »