blib/lib/CPAN/InGit/ArchiveTree.pm

filter: Statementstmt 79.5% 191 / 240 Branchbran 52.9% 72 / 136 Conditioncond 32.7% 18 / 55 MC/DCmcdc 8.5% 3 / 35 Subroutinesub 96.5% 28 / 29 Podpod 93.3% 14 / 15 totaltotal 63.9% 326 / 510 CC 107 SCAR 45.0
CC
107
Cov
65%
import_cpanfile_snapshot
462.0
import_modules
59.2
_filter_prereqs
27.6
CRAP 89.8
« blib/lib/CPAN/InGit.pm ↑ Summary blib/lib/CPAN/InGit/MirrorTree.pm »
1 package CPAN::InGit::ArchiveTree;
2 11 our $VERSION = '0.005'; # VERSION
3 # ABSTRACT: An object managing a CPAN file structure in a Git Tree
4  
5  
6 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Scalar::Util 'refaddr', 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use POSIX 'strftime';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use IO::Uncompress::Gunzip qw( gunzip $GunzipError );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Log::Any '$log';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 extends 'CPAN::InGit::MutableTree';
17  
18  
19 41 ▶sub BUILD($self, $args, @) {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
20 41 ▶ $self->load_config if $self->config_blob;
Branch: 1 branch
BranchTrueFalseTotal
if $self->config_blob 26 15 41
21 41 ▶ $self->name($self->branch? $self->branch->shorthand : '(anonymous)')
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->name 16 25 41
$self->branch ? : 1 15 16
22 unless defined $self->name;
23 }
24  
25 11 has name => ( is => 'rw' );
26 11 has config => ( is => 'rw' );
27  
28 82 ▶sub config_blob($self) {
Subroutine config_blob: called CC=3 SCAR=11.1
Pod documented
29 82 ▶ my $ent= $self->get_path('cpan_ingit.json')
Branch: 1 branch
BranchTrueFalseTotal
my $ent = $self->get_path("cpan_ingit.json") or return undef 52 30 82
30 or return undef;
31 52 ▶ return $ent->[0]->is_blob? $ent->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ent->[0]->is_blob ? : 52 0 52
32 }
33  
34  
35 26 ▶sub load_config($self) {
Subroutine load_config: called CC=3 SCAR=11.2
Pod documented
36 26 ▶ my $cfg_blob= $self->config_blob
Branch: 1 branch
BranchTrueFalseTotal
my $cfg_blob = $self->config_blob or die "Missing '/cpan_ingit.json'" 26 0 26
37 or die "Missing '/cpan_ingit.json'";
38 26 my $attrs= JSON::PP->new->utf8->relaxed->decode($cfg_blob->content);
39 26 ▶ 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) 26 0 26
40 26 $self->{config}= $attrs;
41 26 $self->_unpack_config($self->{config});
42 26 $attrs;
43 }
44  
45 26 ▶sub _unpack_config($self, $config) {
Subroutine _unpack_config: called CC=3 SCAR=11.0
46 26 for (qw( default_import_sources corelist_perl_version canonical_url )) {
47 78 ▶ $self->$_($config->{$_}) if defined $config->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{$_} 26 52 78
48 }
49 }
50  
51 15 ▶sub _pack_config($self, $config) {
Subroutine _pack_config: called CC=3 SCAR=11.1
52 15 for (qw( default_import_sources corelist_perl_version canonical_url )) {
53 45 my $val= $self->$_;
54 45 ▶ $val= "$val" if ref $val eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "version" 0 45 45
55 45 $config->{$_}= $val;
56 }
57 }
58  
59 15 ▶sub write_config($self) {
Subroutine write_config: called CC=4 SCAR=15.2
Pod documented
60 15 ▶ my $config= $self->config // {};
Condition50%1/2
$self->config // {}
l!l
015
MC/DC0%0/1
$self->config // {}
$self->config
Truth table50%1/2
A
A= $self->config
Aresult
11
00
61 15 $self->_pack_config($config);
62 15 my $json= JSON::PP->new->utf8->canonical->pretty->encode($config);
63 15 ▶ $self->set_path('cpan_ingit.json', \$json)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config_blob and $self->config_blob->content eq $json 15 0 15
Condition33%1/3
$self->config_blob and $self->config_blob->content eq $json
!ll&&!rl&&r
1500
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 15 $self;
66 }
67  
68  
69 11 has canonical_url => ( is => 'rw' );
70 11 has default_import_sources => ( is => 'rw' );
71 11 has corelist_perl_version => ( is => 'rw', default => '5.008009' );
72  
73  
74 77 ▶sub package_details_blob($self) {
Subroutine package_details_blob: called CC=3 SCAR=11.1
Pod documented
75 77 ▶ 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 60 17 77
76 or return undef;
77 60 ▶ return $ent->[0]->is_blob? $ent->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ent->[0]->is_blob ? : 60 0 60
78 }
79  
80 11 has package_details => ( is => 'rw', lazy => 1, builder => 1, clearer => 1 );
81 12 ▶sub _build_package_details($self) {
Subroutine _build_package_details: called CC=1 SCAR=0.0
82 12 $self->parse_package_details($self->package_details_blob->content);
83 }
84  
85  
86 12 ▶sub parse_package_details($self, $content) {
Subroutine parse_package_details: called CC=7 SCAR=19.6
Pod documented
87 12 my %attrs;
88 12 ▶ while ($content =~ /\G([^:\n]+):\s+(.*)\n/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\G([^:\n]+):\s+(.*)\n/cgu) 96 12 108
89 96 $attrs{$1}= $2;
90 }
91 12 ▶ $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") 12 0 12
92 12 my %by_mod;
93 my %by_dist;
94 12 ▶ while ($content =~ /\G(\S+)\s+(\S+)\s+(\S+)\n/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\G(\S+)\s+(\S+)\s+(\S+)\n/cgu) 21 12 33
95 21 ▶ my $row= [ $1, ($2 eq 'undef'? undef : $2), $3 ];
Branch: 1 branch
BranchTrueFalseTotal
$2 eq 'undef' ? : 8 13 21
96 21 $by_mod{$1}= $row;
97 21 push @{$by_dist{$3}}, $row;
98 }
99 12 ▶ pos $content == length $content
Branch: 1 branch
BranchTrueFalseTotal
pos $content == length $content or croak(q[Parse error at '] . substr($content, pos $content, 10) . q[']) 12 0 12
100 or croak "Parse error at '".substr($content, pos($content), 10)."'";
101 12 ▶ 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'} ? : 12 0 12
102 : undef; # TODO: fall back to date from branch commit
103 return {
104 12 last_update => $timestamp,
105 by_module => \%by_mod,
106 by_dist => \%by_dist,
107 };
108 }
109  
110  
111 23 ▶sub write_package_details($self) {
Subroutine write_package_details: called CC=5 SCAR=16.1
Pod documented
112 23 ▶ my $url= $self->canonical_url // 'cpan_mirror_ingit.local';
Condition50%1/2
$self->canonical_url // "cpan_mirror_ingit.local"
l!l
023
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 23 ▶ : values %{$self->package_details->{by_module}};
Branch: 1 branch
BranchTrueFalseTotal
!$self->package_details_blob ? : 15 8 23
117 23 my $line_count= @mod_list;
118 23 my $date= strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime);
119 23 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 23 @mod_list= sort { fc $a->[0] cmp fc $b->[0] } @mod_list;
132 23 my @lines;
133 23 for (@mod_list) {
134 9 ▶ push @lines, sprintf("%s %s %s\n", $_->[0], $_->[1] // 'undef', $_->[2]);
Condition100%2/2
$_->[1] // "undef"
l!l
81
MC/DC100%1/1
$_->[1] // "undef"
$_->[1]
Truth table100%2/2
A
A= $_->[1]
Aresult
11
00
135 }
136 23 $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 20 ▶sub get_module_version($self, $mod_name) {
Subroutine get_module_version: called CC=5 SCAR=16.5
Pod documented
151 20 ▶ if (my $current= $self->package_details->{by_module}{$mod_name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $current = $self->package_details->{'by_module'}{$mod_name}) { } 13 7 20
elsif ($mod_name eq 'perl') { } 0 7 7
152 13 my $mod_ver= $current->[1];
153 # grab the version out of the package filename?
154 13 ▶ if (!defined $mod_ver) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mod_ver) 5 8 13
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 13 return $mod_ver;
159 } elsif ($mod_name eq 'perl') {
160 0 return $self->corelist_perl_version;
161 } else {
162 7 return undef;
163 }
164 }
165  
166 5 ▶sub get_module_dist($self, $mod_name) {
Subroutine get_module_dist: called CC=2 SCAR=7.2
Pod documented
167 5 my $by_name= $self->package_details->{by_module}{$mod_name};
168 5 ▶ return $by_name? $by_name->[2] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$by_name ? : 5 0 5
169 }
170  
171  
172 10 ▶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 10 $author_path =~ s/\.(zip|tar\.gz|tgz|tar\.bz2|tbz2)\z//;
175 10 return "authors/id/$author_path.meta";
176 }
177  
178  
179 5 ▶sub import_dist($self, $peer, $author_path, %options) {
Subroutine import_dist: called CC=7 SCAR=20.1
Pod documented
180 5 my $dist_path= "authors/id/$author_path";
181 5 ▶ 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") 5 0 5
182 or croak "Import source branch '".$peer->name."' does not contain $dist_path";
183 5 $log->info("Importing $author_path from ".$peer->name." to ".$self->name);
184 5 my $existing_ent= $self->get_path($dist_path);
185 # If exists, must be same gitobj as before or this is an error
186 5 ▶ if ($existing_ent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($existing_ent) 0 5 5
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 5 $self->set_path($dist_path, $distfile_ent->[0], mode => $distfile_ent->[1]);
191 5 my $modules_registered= $peer->package_details->{by_dist}{$author_path};
192 5 ▶ if ($modules_registered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modules_registered) 5 0 5
193 5 $self->package_details->{by_dist}{$author_path}= [ @$modules_registered ];
194 $self->package_details->{by_module}{$_->[0]}= $_
195 5 for @$modules_registered;
196 5 $self->write_package_details;
197 }
198 5 my $meta_path= $self->meta_path_for_dist($author_path);
199 5 my $meta_ent= $peer->get_path($meta_path);
200 5 ▶ if ($meta_ent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_ent) { } 1 4 5
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 4 $log->warn("No META for $author_path");
205 }
206 5 return $self;
207 }
208  
209  
210 5 ▶sub get_dist_meta($self, $author_path, %options) {
Subroutine get_dist_meta: called CC=2 SCAR=6.9
Pod documented
211 5 my $meta_path= $self->meta_path_for_dist($author_path);
212 5 my $meta_ent= $self->get_path($meta_path);
213 5 ▶ return CPAN::Meta->load_string($meta_ent->[0]->content)
Branch: 1 branch
BranchTrueFalseTotal
if $meta_ent 1 4 5
214 if $meta_ent;
215 # TODO: process the tar file to generate the meta
216 }
217  
218  
219 6 ▶sub _filter_prereqs($self, $reqs, $corelist={}, $log_prefix='') {
Subroutine _filter_prereqs: called CC=10 SCAR=33.2
220 6 for my $mod (sort $reqs->required_modules) {
221 5 my $req_version= $reqs->requirements_for_module($mod);
222 5 my $have_ver= $self->get_module_version($mod);
223 # Is this requirement already in the tree?
224 5 ▶ 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 5 5
elsif (defined $corelist->{$mod} and $reqs->accepts_module($mod, $corelist->{$mod})) { } 0 10 10
Condition33%1/3
defined $have_ver and $reqs->accepts_module($mod, $have_ver)
!ll&&!rl&&r
500
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
500
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 6 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 4 ▶sub import_modules($self, $reqs, %options) {
Subroutine import_modules: called CC=31 SCAR=40.8
Pod documented
257 4 my %imported_dists;
258  
259 # Build list of source trees
260 4 ▶ my $sources= $options{sources} // $self->default_import_sources;
Condition33%1/3
$options{"sources"} // $self->default_import_sources
l!l&&r!l&&!r
040
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 4 ▶ $sources && @$sources
Branch: 1 branch
BranchTrueFalseTotal
$sources and @$sources or croak("No import sources specified") 4 0 4
Condition33%1/3
$sources and @$sources
!ll&&!rl&&r
004
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 4 my @autocommit;
265 4 for (@$sources) {
266 4 ▶ unless (ref $_ and $_->can('package_details')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ and $_->can("package_details")) 4 0 4
Condition33%1/3
ref $_ and $_->can("package_details")
!ll&&!rl&&r
400
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 4 ▶ my $t= $self->parent->get_archive_tree($_)
Branch: 1 branch
BranchTrueFalseTotal
my $t = $self->parent->get_archive_tree($_) or croak("No such archive tree $_") 4 0 4
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 4 ▶ push @autocommit, $t if $t->can('autofetch') && $t->autofetch;
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("autofetch") and $t->autofetch 0 4 4
Condition33%1/3
$t->can("autofetch") and $t->autofetch
!ll&&!rl&&r
400
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 4 $_= $t;
273 }
274 }
275  
276 # Coerce the argument to a Requirements object
277 4 require CPAN::Meta::Requirements;
278 4 my $prereq_phases= [qw( configure build runtime test )];
279 4 my $prereq_types= [qw( requires )];
280 4 my $log_recommends= !grep $_ eq 'recommends', @$prereq_types;
281 4 my $recommended= CPAN::Meta::Requirements->new;
282 # coerce the requirements into a CPAN::Meta::Requirements object
283 4 ▶ $reqs= ref $reqs eq 'HASH'? CPAN::Meta::Requirements->from_string_hash($reqs)
Branch: 3 branches
BranchTrueFalseTotal
ref $reqs eq 'HASH' ? : 1 3 4
builtin::blessed($reqs) && $reqs->isa('CPAN::Meta::Requirements') ? : 3 0 3
builtin::blessed($reqs) && $reqs->isa('CPAN::Meta::Prereqs') ? : 0 0 0
Condition16%1/6
builtin::blessed($reqs) and $reqs->isa("CPAN::Meta::Requirements")
!ll&&!rl&&r
003
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 table33%1/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 4 require Module::CoreList;
290 4 ▶ 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
040
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 4 $perl_v= version->parse($perl_v)->numify;
292 4 ▶ 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") 4 0 4
293 or carp "No corelist for $perl_v";
294  
295 # Filter out the prereqs we already have, or which are in the corelist
296 4 $log->tracef('todo reqs: %s', $reqs->as_string_hash);
297 4 $self->_filter_prereqs($reqs, $corelist);
298 4 my @initial_list= $reqs->required_modules;
299 4 my @todo= @initial_list;
300 4 ▶ while (@todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todo) 5 4 9
301 5 my $mod= shift @todo;
302 5 my $req_version= $reqs->requirements_for_module($mod);
303 5 $log->infof('Add %s %s', $mod, $req_version);
304 # Walk through the list of import sources looking for a version that works
305 5 my ($author_path, $prereqs);
306 5 for my $peer (@$sources) {
307 5 my $peer_ver= $peer->get_module_version($mod);
308 5 ▶ if (!defined $peer_ver) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $peer_ver) { } 0 5 5
elsif (not $reqs->accepts_module($mod, $peer_ver)) { } 0 5 5
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 5 $log->debugf(' branch %s has %s %s, matching %s', $peer->name, $mod, $peer_ver, $req_version);
316 5 $author_path= $peer->get_module_dist($mod);
317 5 $self->import_dist($peer, $author_path);
318 5 my $meta= $self->get_dist_meta($author_path);
319 5 ▶ $prereqs= $meta->effective_prereqs if $meta;
Branch: 1 branch
BranchTrueFalseTotal
if $meta 1 4 5
320 5 $imported_dists{$author_path}= $peer;
321 5 last;
322 }
323 }
324 5 ▶ croak("No import_sources branch had module $mod with version $req_version")
Branch: 1 branch
BranchTrueFalseTotal
unless length $author_path 0 5 5
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 5 ▶ if ($prereqs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prereqs) 1 4 5
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 4 ▶ if ($log_recommends) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log_recommends) 4 0 4
346 4 ▶ if (my @list= sort $recommended->required_modules) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@list) = sort($recommended->required_modules)) 0 4 4
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 4 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 4 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 11 1;
437  
438 __END__
« blib/lib/CPAN/InGit.pm ↑ Summary blib/lib/CPAN/InGit/MirrorTree.pm »