InGit/ArchiveTree.pm

filter: Statementstmt 79.5% 191 / 240 Branchbran 50.7% 69 / 136 Conditioncond 30.9% 17 / 55 MC/DCmcdc 8.5% 3 / 35 Subroutinesub 96.5% 28 / 29 Podpod 93.3% 14 / 15 totaltotal 63.1% 322 / 510 CC 107 SCAR 45.2
CC
107
Cov
64%
import_cpanfile_snapshot
462.0
import_modules
66.6
_filter_prereqs
27.6
CRAP 91.5
« InGit.pm ↑ Summary InGit/MirrorTree.pm »
1 package CPAN::InGit::ArchiveTree;
2 5 our $VERSION = '0.003'; # VERSION
3 # ABSTRACT: An object managing a CPAN file structure in a Git Tree
4  
5  
6 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Scalar::Util 'refaddr', 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use POSIX 'strftime';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use IO::Uncompress::Gunzip qw( gunzip $GunzipError );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Log::Any '$log';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 extends 'CPAN::InGit::MutableTree';
17  
18  
19 6 ▶sub BUILD($self, $args, @) {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
20 6 ▶ $self->load_config if $self->config_blob;
Branch: 1 branch
BranchTrueFalseTotal
if $self->config_blob 5 1 6
21 6 ▶ $self->name($self->branch? $self->branch->shorthand : '(anonymous)')
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->name 6 0 6
$self->branch ? : 5 1 6
22 unless defined $self->name;
23 }
24  
25 5 has name => ( is => 'rw' );
26 5 has config => ( is => 'rw' );
27  
28 12 ▶sub config_blob($self) {
Subroutine config_blob: called CC=3 SCAR=11.1
Pod documented
29 12 ▶ my $ent= $self->get_path('cpan_ingit.json')
Branch: 1 branch
BranchTrueFalseTotal
my $ent = $self->get_path("cpan_ingit.json") or return undef 10 2 12
30 or return undef;
31 10 ▶ return $ent->[0]->is_blob? $ent->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ent->[0]->is_blob ? : 10 0 10
32 }
33  
34  
35 5 ▶sub load_config($self) {
Subroutine load_config: called CC=3 SCAR=11.2
Pod documented
36 5 ▶ my $cfg_blob= $self->config_blob
Branch: 1 branch
BranchTrueFalseTotal
my $cfg_blob = $self->config_blob or die "Missing '/cpan_ingit.json'" 5 0 5
37 or die "Missing '/cpan_ingit.json'";
38 5 my $attrs= JSON::PP->new->utf8->relaxed->decode($cfg_blob->content);
39 5 ▶ ref $attrs eq 'HASH' or croak "Configuration file does not contain an object?".$cfg_blob->content;
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs eq "HASH" or croak('Configuration file does not contain an object?' . $cfg_blob->content) 5 0 5
40 5 $self->{config}= $attrs;
41 5 $self->_unpack_config($self->{config});
42 5 $attrs;
43 }
44  
45 5 ▶sub _unpack_config($self, $config) {
Subroutine _unpack_config: called CC=3 SCAR=11.0
46 5 for (qw( default_import_sources corelist_perl_version canonical_url )) {
47 15 ▶ $self->$_($config->{$_}) if defined $config->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{$_} 8 7 15
48 }
49 }
50  
51 1 ▶sub _pack_config($self, $config) {
Subroutine _pack_config: called CC=3 SCAR=11.1
52 1 for (qw( default_import_sources corelist_perl_version canonical_url )) {
53 3 my $val= $self->$_;
54 3 ▶ $val= "$val" if ref $val eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "version" 0 3 3
55 3 $config->{$_}= $val;
56 }
57 }
58  
59 1 ▶sub write_config($self) {
Subroutine write_config: called CC=4 SCAR=15.2
Pod documented
60 1 ▶ my $config= $self->config // {};
Condition50%1/2
$self->config // {}
l!l
01
MC/DC0%0/1
$self->config // {}
$self->config
Truth table50%1/2
A
A= $self->config
Aresult
11
00
61 1 $self->_pack_config($config);
62 1 my $json= JSON::PP->new->utf8->canonical->pretty->encode($config);
63 1 ▶ $self->set_path('cpan_ingit.json', \$json)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config_blob and $self->config_blob->content eq $json 1 0 1
Condition33%1/3
$self->config_blob and $self->config_blob->content eq $json
!ll&&!rl&&r
100
MC/DC0%0/2
$self->config_blob and $self->config_blob->content eq $json
$self->config_blob $self->config_blob->content eq $json
Truth table33%1/3
A and B
A= $self->config_blobB= $self->config_blob->content eq $json
ABresult
0X0
100
111
64 unless $self->config_blob && $self->config_blob->content eq $json;
65 1 $self;
66 }
67  
68  
69 5 has canonical_url => ( is => 'rw' );
70 5 has default_import_sources => ( is => 'rw' );
71 5 has corelist_perl_version => ( is => 'rw', default => '5.008009' );
72  
73  
74 8 ▶sub package_details_blob($self) {
Subroutine package_details_blob: called CC=3 SCAR=11.1
Pod documented
75 8 ▶ my $ent= $self->get_path('modules/02packages.details.txt')
Branch: 1 branch
BranchTrueFalseTotal
my $ent = $self->get_path("modules/02packages.details.txt") or return undef 7 1 8
76 or return undef;
77 7 ▶ return $ent->[0]->is_blob? $ent->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ent->[0]->is_blob ? : 7 0 7
78 }
79  
80 5 has package_details => ( is => 'rw', lazy => 1, builder => 1, clearer => 1 );
81 3 ▶sub _build_package_details($self) {
Subroutine _build_package_details: called CC=1 SCAR=0.0
82 3 $self->parse_package_details($self->package_details_blob->content);
83 }
84  
85  
86 3 ▶sub parse_package_details($self, $content) {
Subroutine parse_package_details: called CC=7 SCAR=19.6
Pod documented
87 3 my %attrs;
88 3 ▶ while ($content =~ /\G([^:\n]+):\s+(.*)\n/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\G([^:\n]+):\s+(.*)\n/cgu) 24 3 27
89 24 $attrs{$1}= $2;
90 }
91 3 ▶ $content =~ /\G\n/gc or croak "missing blank line after headers";
Branch: 1 branch
BranchTrueFalseTotal
$content =~ /\G\n/cgu or croak("missing blank line after headers") 3 0 3
92 3 my %by_mod;
93 my %by_dist;
94 3 ▶ while ($content =~ /\G(\S+)\s+(\S+)\s+(\S+)\n/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\G(\S+)\s+(\S+)\s+(\S+)\n/cgu) 18 3 21
95 18 ▶ my $row= [ $1, ($2 eq 'undef'? undef : $2), $3 ];
Branch: 1 branch
BranchTrueFalseTotal
$2 eq 'undef' ? : 8 10 18
96 18 $by_mod{$1}= $row;
97 18 push @{$by_dist{$3}}, $row;
98 }
99 3 ▶ pos $content == length $content
Branch: 1 branch
BranchTrueFalseTotal
pos $content == length $content or croak(q[Parse error at '] . substr($content, pos $content, 10) . q[']) 3 0 3
100 or croak "Parse error at '".substr($content, pos($content), 10)."'";
101 3 ▶ my $timestamp = $attrs{'Last-Updated'}? Time::Piece->strptime($attrs{'Last-Updated'}, "%a, %d %b %Y %H:%M:%S GMT")
Branch: 1 branch
BranchTrueFalseTotal
$attrs{'Last-Updated'} ? : 3 0 3
102 : undef; # TODO: fall back to date from branch commit
103 return {
104 3 last_update => $timestamp,
105 by_module => \%by_mod,
106 by_dist => \%by_dist,
107 };
108 }
109  
110  
111 3 ▶sub write_package_details($self) {
Subroutine write_package_details: called CC=5 SCAR=16.1
Pod documented
112 3 ▶ my $url= $self->canonical_url // 'cpan_mirror_ingit.local';
Condition50%1/2
$self->canonical_url // "cpan_mirror_ingit.local"
l!l
03
MC/DC0%0/1
$self->canonical_url // "cpan_mirror_ingit.local"
$self->canonical_url
Truth table50%1/2
A
A= $self->canonical_url
Aresult
11
00
113 # on initial creation, need to write an empty package_details without triggering
114 # lazy-build of package_details
115 my @mod_list= !$self->package_details_blob? ()
116 3 ▶ : values %{$self->package_details->{by_module}};
Branch: 1 branch
BranchTrueFalseTotal
!$self->package_details_blob ? : 1 2 3
117 3 my $line_count= @mod_list;
118 3 my $date= strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime);
119 3 my $content= <<~END;
120 File: 02packages.details.txt
121 URL: $url
122 Description: Package names found in directory \$CPAN/authors/id/
123 Columns: package name, version, path
124 Intended-For: Automated fetch routines, namespace documentation.
125 Written-By: PAUSE version 1.005
126 Line-Count: $line_count
127 Last-Updated: $date
128  
129 END
130 # List can be huge, so try to be efficient about stringifying it
131 3 @mod_list= sort { fc $a->[0] cmp fc $b->[0] } @mod_list;
132 3 my @lines;
133 3 for (@mod_list) {
134 3 ▶ push @lines, sprintf("%s %s %s\n", $_->[0], $_->[1] // 'undef', $_->[2]);
Condition100%2/2
$_->[1] // "undef"
l!l
21
MC/DC100%1/1
$_->[1] // "undef"
$_->[1]
Truth table100%2/2
A
A= $_->[1]
Aresult
11
00
135 }
136 3 $self->set_path('modules/02packages.details.txt', \join('', $content, @lines));
137 }
138  
139  
140 7 ▶sub has_module($self, $mod_name, $reqs=undef) {
Subroutine has_module: called CC=5 SCAR=16.1
Pod documented
141 7 my $mod_ver= $self->get_module_version($mod_name);
142 7 ▶ if (defined $mod_ver && defined $reqs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mod_ver and defined $reqs) 4 3 7
Condition100%3/3
defined $mod_ver and defined $reqs
!ll&&!rl&&r
124
MC/DC100%2/2
defined $mod_ver and defined $reqs
defined $mod_ver defined $reqs
Truth table100%3/3
A and B
A= defined $mod_verB= defined $reqs
ABresult
0X0
100
111
143 4 ▶ $reqs= CPAN::Meta::Requirements->from_string_hash({ $mod_name => $reqs })
Branch: 1 branch
BranchTrueFalseTotal
unless ref $reqs 4 0 4
144 unless ref $reqs;
145 4 return !!$reqs->accepts_module($mod_name, $mod_ver);
146 }
147 3 return defined $mod_ver;
148 }
149  
150 14 ▶sub get_module_version($self, $mod_name) {
Subroutine get_module_version: called CC=5 SCAR=16.5
Pod documented
151 14 ▶ if (my $current= $self->package_details->{by_module}{$mod_name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $current = $self->package_details->{'by_module'}{$mod_name}) { } 10 4 14
elsif ($mod_name eq 'perl') { } 0 4 4
152 10 my $mod_ver= $current->[1];
153 # grab the version out of the package filename?
154 10 ▶ if (!defined $mod_ver) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mod_ver) 5 5 10
155 5 ▶ $mod_ver= $current->[2] =~ /-([0-9]+(?:\.[0-9_]+?)*)\./? $1
Branch: 1 branch
BranchTrueFalseTotal
$current->[2] =~ /-([0-9]+(?:\.[0-9_]+?)*)\./u ? : 5 0 5
156 : 0; # return 0 to differentiate from undef=nonexisting
157 }
158 10 return $mod_ver;
159 } elsif ($mod_name eq 'perl') {
160 0 return $self->corelist_perl_version;
161 } else {
162 4 return undef;
163 }
164 }
165  
166 2 ▶sub get_module_dist($self, $mod_name) {
Subroutine get_module_dist: called CC=2 SCAR=7.2
Pod documented
167 2 my $by_name= $self->package_details->{by_module}{$mod_name};
168 2 ▶ return $by_name? $by_name->[2] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$by_name ? : 2 0 2
169 }
170  
171  
172 4 ▶sub meta_path_for_dist($self, $author_path) {
Subroutine meta_path_for_dist: called CC=1 SCAR=0.0
Pod documented
173 # replace archive extension with '.meta.json'
174 4 $author_path =~ s/\.(zip|tar\.gz|tgz|tar\.bz2|tbz2)\z//;
175 4 return "authors/id/$author_path.meta";
176 }
177  
178  
179 2 ▶sub import_dist($self, $peer, $author_path, %options) {
Subroutine import_dist: called CC=7 SCAR=20.1
Pod documented
180 2 my $dist_path= "authors/id/$author_path";
181 2 ▶ my $distfile_ent= $peer->get_path($dist_path)
Branch: 1 branch
BranchTrueFalseTotal
my $distfile_ent = $peer->get_path($dist_path) or croak(q[Import source branch '] . $peer->name . "' does not contain $dist_path") 2 0 2
182 or croak "Import source branch '".$peer->name."' does not contain $dist_path";
183 2 $log->info("Importing $author_path from ".$peer->name." to ".$self->name);
184 2 my $existing_ent= $self->get_path($dist_path);
185 # If exists, must be same gitobj as before or this is an error
186 2 ▶ if ($existing_ent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($existing_ent) 0 2 2
187 0 ▶ croak "$dist_path already exists with different content"
Branch: 1 branch
BranchTrueFalseTotal
unless $existing_ent->[0]->id eq $distfile_ent->[0]->id 0 0 0
188 unless $existing_ent->[0]->id eq $distfile_ent->[0]->id;
189 }
190 2 $self->set_path($dist_path, $distfile_ent->[0], mode => $distfile_ent->[1]);
191 2 my $modules_registered= $peer->package_details->{by_dist}{$author_path};
192 2 ▶ if ($modules_registered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modules_registered) 2 0 2
193 2 $self->package_details->{by_dist}{$author_path}= [ @$modules_registered ];
194 $self->package_details->{by_module}{$_->[0]}= $_
195 2 for @$modules_registered;
196 2 $self->write_package_details;
197 }
198 2 my $meta_path= $self->meta_path_for_dist($author_path);
199 2 my $meta_ent= $peer->get_path($meta_path);
200 2 ▶ if ($meta_ent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_ent) { } 1 1 2
201 1 $self->set_path($meta_path, $meta_ent->[0], mode => $meta_ent->[1]);
202 } else {
203 # TODO: parse module for META.json and dependnecies
204 1 $log->warn("No META for $author_path");
205 }
206 2 return $self;
207 }
208  
209  
210 2 ▶sub get_dist_meta($self, $author_path, %options) {
Subroutine get_dist_meta: called CC=2 SCAR=6.9
Pod documented
211 2 my $meta_path= $self->meta_path_for_dist($author_path);
212 2 my $meta_ent= $self->get_path($meta_path);
213 2 ▶ return CPAN::Meta->load_string($meta_ent->[0]->content)
Branch: 1 branch
BranchTrueFalseTotal
if $meta_ent 1 1 2
214 if $meta_ent;
215 # TODO: process the tar file to generate the meta
216 }
217  
218  
219 3 ▶sub _filter_prereqs($self, $reqs, $corelist={}, $log_prefix='') {
Subroutine _filter_prereqs: called CC=10 SCAR=33.2
220 3 for my $mod (sort $reqs->required_modules) {
221 2 my $req_version= $reqs->requirements_for_module($mod);
222 2 my $have_ver= $self->get_module_version($mod);
223 # Is this requirement already in the tree?
224 2 ▶ if (defined $have_ver && $reqs->accepts_module($mod, $have_ver)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $have_ver and $reqs->accepts_module($mod, $have_ver)) { } 0 2 2
elsif (defined $corelist->{$mod} and $reqs->accepts_module($mod, $corelist->{$mod})) { } 0 4 4
Condition33%1/3
defined $have_ver and $reqs->accepts_module($mod, $have_ver)
!ll&&!rl&&r
200
MC/DC0%0/2
defined $have_ver and $reqs->accepts_module($mod, $have_ver)
defined $have_ver $reqs->accepts_module($mod, $have_ver)
Truth table33%1/3
A and B
A= defined $have_verB= $reqs->accepts_module($mod, $have_ver)
ABresult
0X0
100
111
225 0 ▶ $log->debugf($log_prefix.'(requirement %s %s already satisfied by %s from %s)',
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::InGit::ArchiveTree::log->is_info 0 0 0
$mod eq 'perl' ? : 0 0 0
226 $mod, $req_version, $have_ver,
227 ($mod eq 'perl'? 'corelist_perl_version' : $self->get_module_dist($mod)))
228 if $log->is_info;
229 0 $reqs->clear_requirement($mod);
230 }
231 # Is the requirement satisfied by a core perl module in the version of perl
232 # the app will be running under?
233 ▶ elsif (defined $corelist->{$mod} && $reqs->accepts_module($mod, $corelist->{$mod})) {
Condition33%1/3
defined $corelist->{$mod} and $reqs->accepts_module($mod, $corelist->{$mod})
!ll&&!rl&&r
200
MC/DC0%0/2
defined $corelist->{$mod} and $reqs->accepts_module($mod, $corelist->{$mod})
defined $corelist->{$mod} $reqs->accepts_module($mod, $corelist->{$mod})
Truth table33%1/3
A and B
A= defined $corelist->{$mod}B= $reqs->accepts_module($mod, $corelist->{$mod})
ABresult
0X0
100
111
234 0 $log->debugf($log_prefix.'(requirement %s %s satisfied by corelist)', $mod, $req_version);
235 0 $reqs->clear_requirement($mod);
236 }
237 }
238 3 return $reqs;
239 }
240  
241 # merges new requirements into existing, and returns a list of anything that changed
242 1 ▶sub _merge_prereqs($self, $reqs, $new_reqs) {
Subroutine _merge_prereqs: called CC=6 SCAR=18.7
243 1 my $before= $reqs->as_string_hash;
244 1 $reqs->add_requirements($new_reqs);
245 1 my $after= $reqs->as_string_hash;
246 1 my @changed;
247 1 for my $mod (sort $new_reqs->required_modules) {
248 1 ▶ if (($before->{$mod} // '') ne ($after->{$mod} // 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (($before->{$mod} // "") ne ($after->{$mod} // 0)) 1 0 1
Condition50%2/4
$before->{$mod} // ""
l!l
01
$after->{$mod} // 0
l!l
10
MC/DC0%0/1
$before->{$mod} // ""
$before->{$mod}
MC/DC0%0/1
$after->{$mod} // 0
$after->{$mod}
Truth table50%1/2
A
A= $before->{$mod}
Aresult
11
00
Truth table50%1/2
A
A= $after->{$mod}
Aresult
11
00
249 1 push @changed, $mod;
250 1 ▶ $log->infof(' requires %s%s', $mod, $after->{$mod}? " $after->{$mod}" : '');
Branch: 1 branch
BranchTrueFalseTotal
$after->{$mod} ? : 1 0 1
251 }
252 }
253 1 return @changed;
254 }
255  
256 1 ▶sub import_modules($self, $reqs, %options) {
Subroutine import_modules: called CC=31 SCAR=42.0
Pod documented
257 1 my %imported_dists;
258  
259 # Build list of source trees
260 1 ▶ my $sources= $options{sources} // $self->default_import_sources;
Condition33%1/3
$options{"sources"} // $self->default_import_sources
l!l&&r!l&&!r
010
MC/DC0%0/2
$options{"sources"} // $self->default_import_sources
$options{"sources"} $self->default_import_sources
Truth table33%1/3
A // B
A= $options{"sources"}B= $self->default_import_sources
ABresult
1X1
011
000
261 1 ▶ $sources && @$sources
Branch: 1 branch
BranchTrueFalseTotal
$sources and @$sources or croak("No import sources specified") 1 0 1
Condition33%1/3
$sources and @$sources
!ll&&!rl&&r
001
MC/DC0%0/2
$sources and @$sources
$sources @$sources
Truth table33%1/3
A and B
A= $sourcesB= @$sources
ABresult
0X0
100
111
262 or croak "No import sources specified";
263 # coerce every source name to an ArchiveTree object
264 1 my @autocommit;
265 1 for (@$sources) {
266 1 ▶ unless (ref $_ and $_->can('package_details')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ and $_->can("package_details")) 1 0 1
Condition33%1/3
ref $_ and $_->can("package_details")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $_ and $_->can("package_details")
ref $_ $_->can("package_details")
Truth table33%1/3
A and B
A= ref $_B= $_->can("package_details")
ABresult
0X0
100
111
267 1 ▶ my $t= $self->parent->get_archive_tree($_)
Branch: 1 branch
BranchTrueFalseTotal
my $t = $self->parent->get_archive_tree($_) or croak("No such archive tree $_") 1 0 1
268 or croak "No such archive tree $_";
269 # If we've created new objects for MirrorTree and the MirrorTree has autofetch
270 # enabled, then we also need to commit those changes before returning.
271 1 ▶ push @autocommit, $t if $t->can('autofetch') && $t->autofetch;
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("autofetch") and $t->autofetch 0 1 1
Condition33%1/3
$t->can("autofetch") and $t->autofetch
!ll&&!rl&&r
100
MC/DC0%0/2
$t->can("autofetch") and $t->autofetch
$t->can("autofetch") $t->autofetch
Truth table33%1/3
A and B
A= $t->can("autofetch")B= $t->autofetch
ABresult
0X0
100
111
272 1 $_= $t;
273 }
274 }
275  
276 # Coerce the argument to a Requirements object
277 1 require CPAN::Meta::Requirements;
278 1 my $prereq_phases= [qw( configure build runtime test )];
279 1 my $prereq_types= [qw( requires )];
280 1 my $log_recommends= !grep $_ eq 'recommends', @$prereq_types;
281 1 my $recommended= CPAN::Meta::Requirements->new;
282 # coerce the requirements into a CPAN::Meta::Requirements object
283 1 ▶ $reqs= ref $reqs eq 'HASH'? CPAN::Meta::Requirements->from_string_hash($reqs)
Branch: 3 branches
BranchTrueFalseTotal
ref $reqs eq 'HASH' ? : 1 0 1
builtin::blessed($reqs) && $reqs->isa('CPAN::Meta::Requirements') ? : 0 0 0
builtin::blessed($reqs) && $reqs->isa('CPAN::Meta::Prereqs') ? : 0 0 0
Condition0%0/6
builtin::blessed($reqs) and $reqs->isa("CPAN::Meta::Requirements")
!ll&&!rl&&r
000
builtin::blessed($reqs) and $reqs->isa("CPAN::Meta::Prereqs")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($reqs) and $reqs->isa("CPAN::Meta::Requirements")
builtin::blessed($reqs) $reqs->isa("CPAN::Meta::Requirements")
MC/DC0%0/2
builtin::blessed($reqs) and $reqs->isa("CPAN::Meta::Prereqs")
builtin::blessed($reqs) $reqs->isa("CPAN::Meta::Prereqs")
Truth table0%0/3
A and B
A= builtin::blessed($reqs)B= $reqs->isa("CPAN::Meta::Requirements")
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= builtin::blessed($reqs)B= $reqs->isa("CPAN::Meta::Prereqs")
ABresult
0X0
100
111
284 : blessed($reqs) && $reqs->isa('CPAN::Meta::Requirements')? $reqs
285 : blessed($reqs) && $reqs->isa('CPAN::Meta::Prereqs')? $reqs->merged_requirements($prereq_phases, $prereq_types)
286 : croak "Expected CPAN::Meta::Requirements object, ::Prereqs object, or HASH ref";
287  
288 # Determine what module versions were available for the app's version of perl.
289 1 require Module::CoreList;
290 1 ▶ my $perl_v= $options{corelist_perl_version} // $self->corelist_perl_version;
Condition33%1/3
$options{"corelist_perl_version"} // $self->corelist_perl_version
l!l&&r!l&&!r
010
MC/DC0%0/2
$options{"corelist_perl_version"} // $self->corelist_perl_version
$options{"corelist_perl_version"} $self->corelist_perl_version
Truth table33%1/3
A // B
A= $options{"corelist_perl_version"}B= $self->corelist_perl_version
ABresult
1X1
011
000
291 1 $perl_v= version->parse($perl_v)->numify;
292 1 ▶ my $corelist= Module::CoreList::find_version($perl_v)
Branch: 1 branch
BranchTrueFalseTotal
my $corelist = Module::CoreList::find_version($perl_v) or carp("No corelist for $perl_v") 1 0 1
293 or carp "No corelist for $perl_v";
294  
295 # Filter out the prereqs we already have, or which are in the corelist
296 1 $log->tracef('todo reqs: %s', $reqs->as_string_hash);
297 1 $self->_filter_prereqs($reqs, $corelist);
298 1 my @initial_list= $reqs->required_modules;
299 1 my @todo= @initial_list;
300 1 ▶ while (@todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todo) 2 1 3
301 2 my $mod= shift @todo;
302 2 my $req_version= $reqs->requirements_for_module($mod);
303 2 $log->infof('Add %s %s', $mod, $req_version);
304 # Walk through the list of import sources looking for a version that works
305 2 my ($author_path, $prereqs);
306 2 for my $peer (@$sources) {
307 2 my $peer_ver= $peer->get_module_version($mod);
308 2 ▶ if (!defined $peer_ver) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $peer_ver) { } 0 2 2
elsif (not $reqs->accepts_module($mod, $peer_ver)) { } 0 2 2
309 0 $log->debugf(' branch %s does not have module %s', $peer->name, $mod);
310 }
311 elsif (!$reqs->accepts_module($mod, $peer_ver)) {
312 0 $log->debugf(' branch %s module %s version %s does not match %s', $peer->name, $mod, $peer_ver, $req_version);
313 }
314 else {
315 2 $log->debugf(' branch %s has %s %s, matching %s', $peer->name, $mod, $peer_ver, $req_version);
316 2 $author_path= $peer->get_module_dist($mod);
317 2 $self->import_dist($peer, $author_path);
318 2 my $meta= $self->get_dist_meta($author_path);
319 2 ▶ $prereqs= $meta->effective_prereqs if $meta;
Branch: 1 branch
BranchTrueFalseTotal
if $meta 1 1 2
320 2 $imported_dists{$author_path}= $peer;
321 2 last;
322 }
323 }
324 2 ▶ croak("No import_sources branch had module $mod with version $req_version")
Branch: 1 branch
BranchTrueFalseTotal
unless length $author_path 0 2 2
325 unless length $author_path;
326 # Push things into the TODO list if they aren't already in %$reqs or if they have a higher
327 # version requirement.
328 2 ▶ if ($prereqs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prereqs) 1 1 2
329 1 my $dist_reqs= $prereqs->merged_requirements($prereq_phases, $prereq_types);
330 1 $log->infof('Dist %s:', $author_path);
331 1 my $n= $#todo;
332 1 push @todo, $self->_merge_prereqs($reqs, $self->_filter_prereqs($dist_reqs, $corelist, ' '));
333 1 ▶ $log->infof(' (no additional reqs)') if $#todo == $n;
Branch: 1 branch
BranchTrueFalseTotal
if $#todo == $n 0 1 1
334 # Collect recommendations
335 1 ▶ if ($log_recommends) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log_recommends) 1 0 1
336 1 my $dist_recommends= $prereqs->merged_requirements(['runtime'], ['recommends']);
337 1 $self->_filter_prereqs($dist_recommends, $corelist);
338 1 my @list= sort $dist_recommends->required_modules;
339 1 ▶ $log->noticef('Dist %s recommends %s', $mod, [ sort @list ])
Branch: 1 branch
BranchTrueFalseTotal
if @list 0 1 1
340 if @list;
341 1 $recommended->add_requirements($dist_recommends);
342 }
343 }
344 }
345 1 ▶ if ($log_recommends) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log_recommends) 1 0 1
346 1 ▶ if (my @list= sort $recommended->required_modules) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@list) = sort($recommended->required_modules)) 0 1 1
347 0 $log->notice('Full list of recommended modules:');
348 $log->noticef(' %s %s', $_, $recommended->requirements_for_module($_))
349 0 for @list;
350 }
351 }
352 # If any sources are 'autofetch' and caller didn't supply the MirrorTree object,
353 # commit the changes before returning.
354 1 for my $mirror (grep $_->has_changes, @autocommit) {
355 0 my $message= join "\n",
356 'Auto-commit packages fetched for branch '.$self->name,
357 '',
358 'For $archive_tree->import_modules:',
359 map(" - $_ ".$reqs->requirements_for_module($_), @initial_list),
360 '';
361 0 $mirror->commit($message);
362 }
363 1 return \%imported_dists;
364 }
365  
366  
367 0 ▶sub import_cpanfile_snapshot($self, $snapshot_spec, %options) {
Subroutine import_cpanfile_snapshot: not called CC=21 SCAR=61.4
Pod documented
368 0 my %imported_dists;
369  
370 0 ▶ my $sources= $options{sources} // $self->default_import_sources;
Condition0%0/3
$options{"sources"} // $self->default_import_sources
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"sources"} // $self->default_import_sources
$options{"sources"} $self->default_import_sources
Truth table0%0/3
A // B
A= $options{"sources"}B= $self->default_import_sources
ABresult
1X1
011
000
371 0 ▶ $sources && @$sources
Branch: 1 branch
BranchTrueFalseTotal
$sources and @$sources or croak("No import sources specified") 0 0 0
Condition0%0/3
$sources and @$sources
!ll&&!rl&&r
000
MC/DC0%0/2
$sources and @$sources
$sources @$sources
Truth table0%0/3
A and B
A= $sourcesB= @$sources
ABresult
0X0
100
111
372 or croak "No import sources specified";
373 # coerce every source name to an ArchiveTree object
374 0 my @autocommit;
375 0 for (@$sources) {
376 0 ▶ unless (ref $_ and $_->can('package_details')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ and $_->can("package_details")) 0 0 0
Condition0%0/3
ref $_ and $_->can("package_details")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and $_->can("package_details")
ref $_ $_->can("package_details")
Truth table0%0/3
A and B
A= ref $_B= $_->can("package_details")
ABresult
0X0
100
111
377 0 ▶ my $t= $self->parent->get_archive_tree($_)
Branch: 1 branch
BranchTrueFalseTotal
my $t = $self->parent->get_archive_tree($_) or croak("No such archive tree $_") 0 0 0
378 or croak "No such archive tree $_";
379 # If we've created new objects for MirrorTree and the MirrorTree has autofetch
380 # enabled, then we also need to commit those changes before returning.
381 0 ▶ push @autocommit, $t if $t->can('autofetch') && $t->autofetch;
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("autofetch") and $t->autofetch 0 0 0
Condition0%0/3
$t->can("autofetch") and $t->autofetch
!ll&&!rl&&r
000
MC/DC0%0/2
$t->can("autofetch") and $t->autofetch
$t->can("autofetch") $t->autofetch
Truth table0%0/3
A and B
A= $t->can("autofetch")B= $t->autofetch
ABresult
0X0
100
111
382 0 $_= $t;
383 }
384 }
385  
386 0 dist: for my $dist_name (sort keys %$snapshot_spec) {
387 0 my $dist_info= $snapshot_spec->{$dist_name};
388 # Locate 'pathname'
389 0 my $author_path= $dist_info->{pathname};
390 0 ▶ unless ($author_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($author_path) 0 0 0
391 0 my $msg= "Dist $dist_name lacks 'pathname' attribute";
392 0 ▶ $options{partial}? $log->notice($msg) : croak $msg;
Branch: 1 branch
BranchTrueFalseTotal
$options{'partial'} ? : 0 0 0
393 0 next;
394 }
395 # Which source has this file?
396 0 for my $source (@$sources) {
397 0 $log->debugf("check %s for %s", $source->name, $author_path);
398 0 ▶ my $distfile_ent= $source->get_path("authors/id/$author_path")
Branch: 1 branch
BranchTrueFalseTotal
my $distfile_ent = $source->get_path("authors/id/$author_path") or next 0 0 0
399 or next;
400 0 $self->import_dist($source, $author_path);
401 0 $imported_dists{$author_path}= $source;
402 # Update index with the modules provided by this distribution if it wasn't imported
403 # from $source by import_dist.
404 0 ▶ if (!$source->package_details->{by_dist}{$author_path}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($source->package_details->{"by_dist"}{$author_path}) 0 0 0
405 # Fall back to the 'provides' from the cpanfile.snapshot
406 0 ▶ if (ref $dist_info->{provides} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dist_info->{'provides'} eq 'HASH') { } 0 0 0
407 my @mod_index= map [ $_, $dist_info->{provides}{$_}, $author_path ],
408 0 keys %{$dist_info->{provides}};
409 0 $self->package_details->{by_dist}{$author_path}= \@mod_index;
410 $self->package_details->{by_module}{$_->[0]}= $_
411 0 for @mod_index;
412 0 $self->write_package_details;
413 } else {
414 0 my $msg= "Snapshot lacks 'provides' for $dist_name, and not indexed in ".$source->name." either";
415 0 ▶ $options{partial}? $log->notice($msg) : croak $msg;
Branch: 1 branch
BranchTrueFalseTotal
$options{'partial'} ? : 0 0 0
416 }
417 }
418 0 next dist;
419 }
420 0 my $msg= "No source contains file $author_path";
421 0 ▶ $options{partial}? $log->notice($msg) : croak $msg;
Branch: 1 branch
BranchTrueFalseTotal
$options{'partial'} ? : 0 0 0
422 }
423 # If any sources are 'autofetch' and caller didn't supply the MirrorTree object,
424 # commit the changes before returning.
425 0 for my $mirror (grep $_->has_changes, @autocommit) {
426 0 my $message= join "\n",
427 'Auto-commit packages fetched for branch '.$self->name,
428 '',
429 'For $archive_tree->import_cpanfile_snapshot',
430 '';
431 0 $mirror->commit($message);
432 }
433 0 return \%imported_dists;
434 }
435  
436 5 1;
437  
438 __END__
« InGit.pm ↑ Summary InGit/MirrorTree.pm »