line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Carmel::Repository; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
3
|
1
|
|
|
1
|
|
4
|
use version (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
4
|
1
|
|
|
1
|
|
427
|
use DirHandle; |
|
1
|
|
|
|
|
495
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
372
|
use Carmel::Artifact; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
5
|
use CPAN::Meta::Requirements; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
7
|
1
|
|
|
1
|
|
440
|
use File::Copy::Recursive (); |
|
1
|
|
|
|
|
6102
|
|
|
1
|
|
|
|
|
26
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use Class::Tiny qw( packages ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub BUILD { |
12
|
0
|
|
|
0
|
0
|
|
my($self, $args) = @_; |
13
|
0
|
|
|
|
|
|
$self->path($args->{path}); |
14
|
0
|
|
|
|
|
|
$self->packages({}); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub path { |
18
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
19
|
0
|
0
|
|
|
|
|
if (@_ ){ |
20
|
0
|
|
|
|
|
|
$self->{path} = Path::Tiny->new($_[0]); |
21
|
|
|
|
|
|
|
} else { |
22
|
0
|
|
|
|
|
|
$self->{path}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub import_artifact { |
27
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
File::Copy::Recursive::dircopy($dir, $dest) |
33
|
|
|
|
|
|
|
or die "Failed copying $dir -> $dest"; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $self->load($dest); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub load_artifacts { |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
0
|
|
|
|
|
return unless $self->path->exists; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
for my $ent ($self->path->children) { |
43
|
0
|
0
|
0
|
|
|
|
if ($ent->is_dir && $ent->child("blib")->exists) { |
44
|
0
|
0
|
|
|
|
|
warn "-> Loading artifact from $ent\n" if $Carmel::DEBUG; |
45
|
0
|
|
|
|
|
|
$self->load($ent); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub load { |
51
|
0
|
|
|
0
|
0
|
|
my($self, $dir) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $artifact = Carmel::Artifact->new($dir); |
54
|
0
|
|
|
|
|
|
while (my($package, $data) = each %{ $artifact->provides }) { |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self->add($package, $artifact); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $artifact; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub add { |
62
|
0
|
|
|
0
|
0
|
|
my($self, $package, $artifact) = @_; |
63
|
0
|
|
|
|
|
|
push @{$self->{packages}{$package}}, $artifact; |
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub find { |
67
|
0
|
|
|
0
|
0
|
|
my($self, $package, $want_version) = @_; |
68
|
0
|
|
|
|
|
|
$self->_find($package, $want_version); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub find_all { |
72
|
0
|
|
|
0
|
0
|
|
my($self, $package, $want_version) = @_; |
73
|
0
|
|
|
|
|
|
$self->_find($package, $want_version, 1); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub find_dist { |
77
|
0
|
|
|
0
|
0
|
|
my($self, $package, $distname) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $dir = $self->path->child($distname); |
80
|
0
|
0
|
|
|
|
|
if ($dir->exists) { |
81
|
0
|
|
|
|
|
|
return Carmel::Artifact->new($dir); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
|
|
return $self->find_match($package, sub { $_[0]->distname eq $distname }); |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub find_match { |
88
|
0
|
|
|
0
|
0
|
|
my($self, $package, $cb) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
for my $artifact ($self->list($package)) { |
91
|
0
|
0
|
|
|
|
|
return $artifact if $cb->($artifact); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _find { |
98
|
0
|
|
|
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
|
0
|
|
|
|
|
if ($reqs->accepts_module($package, $artifact->version_for($package))) { |
105
|
0
|
0
|
|
|
|
|
if ($all) { |
106
|
0
|
|
|
|
|
|
push @artifacts, $artifact; |
107
|
|
|
|
|
|
|
} else { |
108
|
0
|
|
|
|
|
|
return $artifact; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
return @artifacts if $all; |
114
|
0
|
|
|
|
|
|
return; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub list { |
118
|
0
|
|
|
0
|
0
|
|
my($self, $package) = @_; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
$self->load_artifacts unless $self->{_loaded}++; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
map { $_->[2] } |
123
|
0
|
0
|
|
|
|
|
sort { $b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] } # sort by the package version, then the main package version |
124
|
0
|
|
|
|
|
|
map { [ $_->version_for($package), $_->version, $_ ] } |
125
|
0
|
|
|
|
|
|
@{$self->{packages}{$package}}; |
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |