Carmel/Repository.pm

filter: Statementstmt 27.5% 22 / 80 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 35.0% 7 / 20 Podpod 0.0% 0 / 11 totaltotal 20.0% 29 / 145 CC 18 SCAR 26.8
CC
18
Cov
20%
load_artifacts
42.0
_find
30.0
find_match
12.0
CRAP 14.6
« Carmel/ProgressBar.pm ↑ Summary Carmel/Runner.pm »
1 package Carmel::Repository;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use DirHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carmel::Artifact;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use CPAN::Meta::Requirements;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Copy::Recursive ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Class::Tiny qw( packages );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
12 0 my($self, $args) = @_;
13 0 $self->path($args->{path});
14 0 $self->packages({});
15 }
16  
17 0 ▶sub path {
Subroutine path: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my $self = shift;
19 0 ▶ if (@_ ){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
20 0 $self->{path} = Path::Tiny->new($_[0]);
21 } else {
22 0 $self->{path};
23 }
24 }
25  
26 0 ▶sub import_artifact {
Subroutine import_artifact: not called CC=2 SCAR=17.9
Pod undocumented
27 0 my($self, $dir) = @_;
28  
29 0 my $dest = $self->path->child($dir->basename);
30  
31 0 local $File::Copy::Recursive::RMTrgDir = 2;
32 0 ▶ File::Copy::Recursive::dircopy($dir, $dest)
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::Recursive::dircopy($dir, $dest) or die "Failed copying $dir -> $dest" 0 0 0
33 or die "Failed copying $dir -> $dest";
34  
35 0 return $self->load($dest);
36 }
37  
38 0 ▶sub load_artifacts {
Subroutine load_artifacts: not called CC=6 SCAR=37.4
Pod undocumented
39 0 my $self = shift;
40 0 ▶ return unless $self->path->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->path->exists 0 0 0
41  
42 0 for my $ent ($self->path->children) {
43 0 ▶ if ($ent->is_dir && $ent->child("blib")->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ent->is_dir and $ent->child("blib")->exists) 0 0 0
Condition0%0/3
$ent->is_dir and $ent->child("blib")->exists
!ll&&!rl&&r
000
MC/DC0%0/2
$ent->is_dir and $ent->child("blib")->exists
$ent->is_dir $ent->child("blib")->exists
Truth table0%0/3
A and B
A= $ent->is_dirB= $ent->child("blib")->exists
ABresult
0X0
100
111
44 0 ▶ warn "-> Loading artifact from $ent\n" if $Carmel::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Carmel::DEBUG 0 0 0
45 0 $self->load($ent);
46 }
47 }
48 }
49  
50 0 ▶sub load {
Subroutine load: not called CC=2 SCAR=17.9
Pod undocumented
51 0 my($self, $dir) = @_;
52  
53 0 my $artifact = Carmel::Artifact->new($dir);
54 0 ▶ while (my($package, $data) = each %{ $artifact->provides }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$artifact->provides;}) 0 0 0
55 0 $self->add($package, $artifact);
56 }
57  
58 0 return $artifact;
59 }
60  
61 0 ▶sub add {
Subroutine add: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my($self, $package, $artifact) = @_;
63 0 push @{$self->{packages}{$package}}, $artifact;
64 }
65  
66 0 ▶sub find {
Subroutine find: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my($self, $package, $want_version) = @_;
68 0 $self->_find($package, $want_version);
69 }
70  
71 0 ▶sub find_all {
Subroutine find_all: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my($self, $package, $want_version) = @_;
73 0 $self->_find($package, $want_version, 1);
74 }
75  
76 0 ▶sub find_dist {
Subroutine find_dist: not called CC=2 SCAR=17.9
Pod undocumented
77 0 my($self, $package, $distname) = @_;
78  
79 0 my $dir = $self->path->child($distname);
80 0 ▶ if ($dir->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir->exists) 0 0 0
81 0 return Carmel::Artifact->new($dir);
82 }
83  
84 0 ▶ return $self->find_match($package, sub { $_[0]->distname eq $distname });
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 }
86  
87 0 ▶sub find_match {
Subroutine find_match: not called CC=3 SCAR=24.8
Pod undocumented
88 0 my($self, $package, $cb) = @_;
89  
90 0 for my $artifact ($self->list($package)) {
91 0 ▶ return $artifact if $cb->($artifact);
Branch: 1 branch
BranchTrueFalseTotal
if &$cb($artifact) 0 0 0
92 }
93  
94 0 return;
95 }
96  
97 0 ▶sub _find {
Subroutine _find: not called CC=5 SCAR=34.0
98 0 my($self, $package, $want_version, $all) = @_;
99  
100 0 my $reqs = CPAN::Meta::Requirements->from_string_hash({ $package => $want_version });
101 0 my @artifacts;
102  
103 0 for my $artifact ($self->list($package)) {
104 0 ▶ if ($reqs->accepts_module($package, $artifact->version_for($package))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reqs->accepts_module($package, $artifact->version_for($package))) 0 0 0
105 0 ▶ if ($all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all) { } 0 0 0
106 0 push @artifacts, $artifact;
107 } else {
108 0 return $artifact;
109 }
110 }
111 }
112  
113 0 ▶ return @artifacts if $all;
Branch: 1 branch
BranchTrueFalseTotal
if $all 0 0 0
114 0 return;
115 }
116  
117 0 ▶sub list {
Subroutine list: not called CC=3 SCAR=24.8
Pod undocumented
118 0 my($self, $package) = @_;
119  
120 0 ▶ $self->load_artifacts unless $self->{_loaded}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_loaded"}++ 0 0 0
121  
122 0 map { $_->[2] }
123 0 ▶ sort { $b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] } # sort by the package version, then the main package version
Condition0%0/3
$Carmel::Repository::b->[0] <=> $Carmel::Repository::a->[0] || $Carmel::Repository::b->[1] <=> $Carmel::Repository::a->[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$Carmel::Repository::b->[0] <=> $Carmel::Repository::a->[0] || $Carmel::Repository::b->[1] <=> $Carmel::Repository::a->[1]
$Carmel::Repository::b->[0] <=> $Carmel::Repository::a->[0] $Carmel::Repository::b->[1] <=> $Carmel::Repository::a->[1]
Truth table0%0/3
A || B
A= $Carmel::Repository::b->[0] <=> $Carmel::Repository::a->[0]B= $Carmel::Repository::b->[1] <=> $Carmel::Repository::a->[1]
ABresult
1X1
011
000
124 0 map { [ $_->version_for($package), $_->version, $_ ] }
125 0 @{$self->{packages}{$package}};
126 }
127  
128 1 1;
« Carmel/ProgressBar.pm ↑ Summary Carmel/Runner.pm »