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