line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Parse 06perms.txt.gz |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Parse::CPAN::Perms; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
25156
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use IO::Zlib; |
13
|
|
|
|
|
|
|
use File::stat; |
14
|
|
|
|
|
|
|
use Carp qw(croak); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has permsfile => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => 'Str', |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has perms => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => 'HashRef', |
28
|
|
|
|
|
|
|
builder => 'build_perms', |
29
|
|
|
|
|
|
|
clearer => 'clear_perms', |
30
|
|
|
|
|
|
|
lazy => 1, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has mtime => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => 'Int', |
37
|
|
|
|
|
|
|
default => 0, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
around BUILDARGS => sub { |
43
|
|
|
|
|
|
|
my ($orig, $class) = (shift, shift); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return $class->$orig(@_) unless @_ %2 or ref $_[0] eq 'HASH'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $path = shift; |
48
|
|
|
|
|
|
|
my $arg = -f $path ? $path : "$path/modules/06perms.txt.gz"; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return {permsfile => $arg, @_}; |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub build_perms { |
56
|
|
|
|
|
|
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $permsfile = $self->permsfile; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $fh = IO::Zlib->new( $permsfile, "rb" ); |
61
|
|
|
|
|
|
|
croak "Failed to read $permsfile: $!" unless $fh; |
62
|
|
|
|
|
|
|
my $perms_data = $self->__read_perms($fh); |
63
|
|
|
|
|
|
|
$fh->close; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $mtime = (stat $permsfile)->mtime; |
66
|
|
|
|
|
|
|
$self->mtime($mtime); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $perms_data; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub __read_perms { |
74
|
|
|
|
|
|
|
my ($self, $fh) = @_; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $inheader = 1; |
77
|
|
|
|
|
|
|
my $perms = {}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
while (<$fh>) { |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if ($inheader) { |
82
|
|
|
|
|
|
|
$inheader = 0 if not m/ \S /x; |
83
|
|
|
|
|
|
|
next; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
chomp; |
87
|
|
|
|
|
|
|
my ($module, $author, $perm) = split m/\s* , \s*/x; |
88
|
|
|
|
|
|
|
$perms->{$module}->{$author} = $perm; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
return $perms; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub is_authorized { |
97
|
|
|
|
|
|
|
my ( $self, $author, $module ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return 0 unless $author && $module; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $perms = $self->perms; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return 1 if not exists $perms->{$module}; # Old mods may not have perms |
104
|
|
|
|
|
|
|
return 1 if exists $perms->{$module}->{$author}; |
105
|
|
|
|
|
|
|
return 0; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub refresh { |
111
|
|
|
|
|
|
|
my ($self, $force) = @_; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $mtime = (stat $self->permsfile)->mtime; |
114
|
|
|
|
|
|
|
return $self unless $mtime > $self->mtime or $force; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$self->clear_perms; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return $self; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=pod |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=for :stopwords Jeffrey Ryan Thalhammer cpan testmatrix url annocpan anno bugtracker rt |
129
|
|
|
|
|
|
|
cpants kwalitee diff irc mailto metadata placeholders metacpan |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 NAME |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Parse::CPAN::Perms - Parse 06perms.txt.gz |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 VERSION |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
version 0.004 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SYNOPSIS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Construction |
142
|
|
|
|
|
|
|
my $perms = Parse::CPAN::Perms->new('path/to/06perms.txt.gz'); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# Get all perms data as hash ref |
145
|
|
|
|
|
|
|
my $perms_data = $perms->perms; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Boolean convenience method |
148
|
|
|
|
|
|
|
$perms->is_authorized(AUTHOR => 'Package::Name'); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DESCRIPTION |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
!! THIS MODULE IS EXPERIMENTAL. INTERFACE IS SUBJECT TO CHANGE !! |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This module parses the F<06perms.txt.gz> file from a CPAN-like repository. |
155
|
|
|
|
|
|
|
At this time, it only parses the compressed form and it provides no mechanism |
156
|
|
|
|
|
|
|
for adding new permissions or writing the data back out to a file. If you |
157
|
|
|
|
|
|
|
desire those features, please contact the author. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=over 4 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item new('path/to/06perms.txt.gz') |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item new(parmsfile => 'path/to/06perms.txt.gz') |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Constructs a new instance of Parse::CPAN::Perms from the specified perms file. |
168
|
|
|
|
|
|
|
The file must exist and must be readable. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=back |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 METHODS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item perms() |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Returns all the permission data as a hash reference |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item is_authorized(AUTHOR => 'Package::Name') |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns true if the author has permission for the package |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item refresh( $force ) |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Causes the permisions hash to be cleared if the C<permsfile> has |
187
|
|
|
|
|
|
|
changed since the last time it was read. The permissions hash will be |
188
|
|
|
|
|
|
|
lazily re-read from disk the next time it is needed. If C<$force> is |
189
|
|
|
|
|
|
|
true, then the permissions hash is cleared unconditionally. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 SEE ALSO |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L<CPAN::Repository::Perms> serves a similar purpose, but is a much more robust |
196
|
|
|
|
|
|
|
module. However, it is bundled with several other CPAN-related modules which |
197
|
|
|
|
|
|
|
may or may not fit your needs and desires. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 SUPPORT |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 Perldoc |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
perldoc Parse::CPAN::Perms |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 Websites |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
The following websites have more information about this module, and may be of help to you. As always, |
210
|
|
|
|
|
|
|
in addition to those websites please use your favorite search engine to discover more resources. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over 4 |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
MetaCPAN |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
A modern, open-source CPAN search engine, useful to view POD in HTML format. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
L<http://metacpan.org/release/Parse-CPAN-Perms> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
CPAN Ratings |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
The CPAN Ratings is a website that allows community ratings and reviews of Perl modules. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Parse-CPAN-Perms> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
CPANTS |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L<http://cpants.perl.org/dist/overview/Parse-CPAN-Perms> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item * |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
CPAN Testers |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
L<http://www.cpantesters.org/distro/P/Parse-CPAN-Perms> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item * |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
CPAN Testers Matrix |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
L<http://matrix.cpantesters.org/?dist=Parse-CPAN-Perms> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
CPAN Testers Dependencies |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
L<http://deps.cpantesters.org/?module=Parse::CPAN::Perms> |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=back |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 Internet Relay Chat |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
You can get live help by using IRC ( Internet Relay Chat ). If you don't know what IRC is, |
267
|
|
|
|
|
|
|
please read this excellent guide: L<http://en.wikipedia.org/wiki/Internet_Relay_Chat>. Please |
268
|
|
|
|
|
|
|
be courteous and patient when talking to us, as we might be busy or sleeping! You can join |
269
|
|
|
|
|
|
|
those networks/channels and get help: |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=over 4 |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=item * |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
irc.perl.org |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
You can connect to the server at 'irc.perl.org' and join this channel: #pinto then talk to this person for help: thaljef. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=back |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head2 Bugs / Feature Requests |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
L<https://github.com/thaljef/Parse-CPAN-Perms/issues> |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=head2 Source Code |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
The code is open to the world, and available for you to hack on. Please feel free to browse it and play |
288
|
|
|
|
|
|
|
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull |
289
|
|
|
|
|
|
|
from your repository :) |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
L<https://github.com/thaljef/Parse-CPAN-Perms> |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
git clone git://github.com/thaljef/Parse-CPAN-Perms.git |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 AUTHOR |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@stratopan.com> |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Jeffrey Ryan Thalhammer. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
304
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=cut |