line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Repository; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
95963
|
$CPAN::Repository::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$CPAN::Repository::VERSION = '0.008'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: API to access a directory which can be served as CPAN repository |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
2122
|
use Moo; |
|
2
|
|
|
|
|
49902
|
|
|
2
|
|
|
|
|
13
|
|
11
|
2
|
|
|
2
|
|
6312
|
use File::Path qw( make_path ); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
276
|
|
12
|
2
|
|
|
2
|
|
2183
|
use File::Spec::Functions ':ALL'; |
|
2
|
|
|
|
|
2109
|
|
|
2
|
|
|
|
|
1011
|
|
13
|
2
|
|
|
2
|
|
1489
|
use CPAN::Repository::Mailrc; |
|
2
|
|
|
|
|
19
|
|
|
2
|
|
|
|
|
70
|
|
14
|
2
|
|
|
2
|
|
1275
|
use CPAN::Repository::Packages; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
73
|
|
15
|
2
|
|
|
2
|
|
1386
|
use CPAN::Repository::Perms; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
70
|
|
16
|
2
|
|
|
2
|
|
2346
|
use File::Copy; |
|
2
|
|
|
|
|
5622
|
|
|
2
|
|
|
|
|
2648
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION ||= '0.0development'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has dir => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has real_dir => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
lazy => 1, |
28
|
|
|
|
|
|
|
builder => '_build_real_dir', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
|
389
|
sub _build_real_dir { catdir(splitdir(shift->dir)) } |
32
|
|
|
|
|
|
|
|
33
|
9
|
|
|
9
|
0
|
277
|
sub splitted_dir { splitdir(shift->real_dir) } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has url => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
lazy => 1, |
38
|
|
|
|
|
|
|
builder => '_build_url', |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
|
0
|
sub _build_url { 'http://cpan.perl.org/' } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has written_by => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
lazy => 1, |
46
|
|
|
|
|
|
|
builder => '_build_written_by', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
|
0
|
sub _build_written_by { (ref shift).' '.$VERSION } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has mailrc => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
lazy => 1, |
54
|
|
|
|
|
|
|
builder => '_build_mailrc', |
55
|
|
|
|
|
|
|
handles => [qw( |
56
|
|
|
|
|
|
|
get_alias |
57
|
|
|
|
|
|
|
)], |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _build_mailrc { |
61
|
2
|
|
|
2
|
|
367
|
my ( $self ) = @_; |
62
|
2
|
|
|
|
|
26
|
return CPAN::Repository::Mailrc->new({ |
63
|
|
|
|
|
|
|
repository_root => $self->real_dir, |
64
|
|
|
|
|
|
|
}); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has perms => ( |
68
|
|
|
|
|
|
|
is => 'ro', |
69
|
|
|
|
|
|
|
lazy => 1, |
70
|
|
|
|
|
|
|
builder => '_build_perms', |
71
|
|
|
|
|
|
|
handles => [qw( |
72
|
|
|
|
|
|
|
get_perms |
73
|
|
|
|
|
|
|
get_perms_by_userid |
74
|
|
|
|
|
|
|
)], |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _build_perms { |
78
|
1
|
|
|
1
|
|
488
|
my ( $self ) = @_; |
79
|
1
|
|
|
|
|
25
|
return CPAN::Repository::Perms->new({ |
80
|
|
|
|
|
|
|
repository_root => $self->real_dir, |
81
|
|
|
|
|
|
|
written_by => $self->written_by, |
82
|
|
|
|
|
|
|
}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has packages => ( |
87
|
|
|
|
|
|
|
is => 'ro', |
88
|
|
|
|
|
|
|
lazy => 1, |
89
|
|
|
|
|
|
|
builder => '_build_packages', |
90
|
|
|
|
|
|
|
handles => [qw( |
91
|
|
|
|
|
|
|
get_module |
92
|
|
|
|
|
|
|
get_module_version |
93
|
|
|
|
|
|
|
)], |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _build_packages { |
97
|
2
|
|
|
2
|
|
995
|
my ( $self ) = @_; |
98
|
2
|
|
|
|
|
55
|
return CPAN::Repository::Packages->new({ |
99
|
|
|
|
|
|
|
repository_root => $self->real_dir, |
100
|
|
|
|
|
|
|
url => $self->url, |
101
|
|
|
|
|
|
|
written_by => $self->written_by, |
102
|
|
|
|
|
|
|
authorbase_path_parts => [$self->authorbase_path_parts], |
103
|
|
|
|
|
|
|
}); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub is_initialized { |
107
|
4
|
|
|
4
|
0
|
6292
|
my ( $self ) = @_; |
108
|
4
|
100
|
|
|
|
86
|
$self->mailrc->exist && $self->packages->exist; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub initialize { |
112
|
1
|
|
|
1
|
0
|
2
|
my ( $self ) = @_; |
113
|
1
|
50
|
|
|
|
5
|
die "there exist already a repository at ".$self->real_dir if $self->is_initialized; |
114
|
1
|
|
|
|
|
29
|
$self->mailrc->save; |
115
|
1
|
|
|
|
|
8
|
$self->packages->save; |
116
|
1
|
|
|
|
|
95
|
$self->perms->save; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub add_author_distribution { |
120
|
3
|
|
|
3
|
0
|
34
|
my ( $self, $author, $distribution_filename, $path ) = @_; |
121
|
3
|
|
|
|
|
13
|
my @fileparts = splitdir( $distribution_filename ); |
122
|
3
|
|
|
|
|
33
|
my $filename = pop(@fileparts); |
123
|
3
|
|
|
|
|
3
|
my $author_path_filename; |
124
|
3
|
|
|
|
|
13
|
my $target_dir = $self->mkauthordir($author); |
125
|
3
|
100
|
|
|
|
10
|
if ($path) { |
126
|
1
|
|
|
|
|
9
|
my $path_dir = catfile( $self->splitted_dir, $self->authorbase_path_parts, $path ); |
127
|
1
|
50
|
|
|
|
40
|
$self->mkdir( $path_dir ) unless -d $path_dir; |
128
|
1
|
|
|
|
|
16
|
$author_path_filename = catfile( $path, $filename ); |
129
|
|
|
|
|
|
|
} else { |
130
|
2
|
|
|
|
|
6
|
$author_path_filename = catfile( $self->author_path_parts($author), $filename ); |
131
|
|
|
|
|
|
|
} |
132
|
3
|
|
|
|
|
18
|
copy($distribution_filename,catfile( $self->splitted_dir, $self->authorbase_path_parts, $author_path_filename )); |
133
|
3
|
|
|
|
|
1586
|
$self->packages->add_distribution($author_path_filename)->save; |
134
|
3
|
100
|
|
|
|
444
|
$self->mailrc->set_alias($author)->save unless defined $self->mailrc->aliases->{$author}; |
135
|
3
|
|
|
|
|
37
|
return catfile( $self->authorbase_path_parts, $self->author_path_parts($author), $filename ); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub set_perms { |
139
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
140
|
0
|
|
|
|
|
0
|
$self->perms->set_perms(@_)->save; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub set_alias { |
144
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $author, $alias ) = @_; |
145
|
0
|
|
|
|
|
0
|
$self->mailrc->set_alias($author,$alias)->save; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub mkauthordir { |
149
|
3
|
|
|
3
|
0
|
7
|
my ( $self, $author ) = @_; |
150
|
3
|
|
|
|
|
12
|
my $authordir = $self->authordir($author); |
151
|
3
|
100
|
|
|
|
119
|
$self->mkdir( $authordir ) unless -d $authordir; |
152
|
3
|
|
|
|
|
9
|
return $authordir; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub author_path_parts { |
156
|
8
|
|
|
8
|
0
|
21
|
my ( $self, $author ) = @_; |
157
|
8
|
|
|
|
|
94
|
return substr( $author, 0, 1 ), substr( $author, 0, 2 ), $author; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
14
|
|
|
14
|
0
|
1696
|
sub authorbase_path_parts { 'authors', 'id' } |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub authordir { |
163
|
3
|
|
|
3
|
0
|
6
|
my ( $self, $author ) = @_; |
164
|
3
|
|
|
|
|
22
|
return catdir( $self->splitted_dir, $self->authorbase_path_parts, $self->author_path_parts($author) ); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub modules { |
168
|
1
|
|
|
1
|
0
|
1578
|
my ( $self ) = @_; |
169
|
1
|
|
|
|
|
3
|
my %modules; |
170
|
1
|
|
|
|
|
3
|
for (keys %{$self->packages->modules}) { |
|
1
|
|
|
|
|
30
|
|
171
|
2
|
|
|
|
|
88
|
$modules{$_} = catfile( $self->splitted_dir, $self->authorbase_path_parts, splitdir( $self->packages->modules->{$_}->[1] ) ); |
172
|
|
|
|
|
|
|
} |
173
|
1
|
|
|
|
|
54
|
return \%modules; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
1
|
|
|
1
|
0
|
1316
|
sub timestamp { shift->packages->timestamp } |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# |
179
|
|
|
|
|
|
|
# Utilities |
180
|
|
|
|
|
|
|
# |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub mkdir { |
183
|
3
|
|
|
3
|
0
|
9
|
my ( $self, @path ) = @_; |
184
|
3
|
|
|
|
|
7790
|
make_path(catdir(@path),{ error => \my $err }); |
185
|
3
|
50
|
|
|
|
24
|
if (@$err) { |
186
|
0
|
|
|
|
|
|
for my $diag (@$err) { |
187
|
0
|
|
|
|
|
|
my ($file, $message) = %$diag; |
188
|
0
|
0
|
|
|
|
|
if ($file eq '') { |
189
|
0
|
|
|
|
|
|
die "general error: $message\n"; |
190
|
|
|
|
|
|
|
} else { |
191
|
0
|
|
|
|
|
|
die "problem making path $file: $message\n"; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
__END__ |