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