line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Repository::Perms; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GETTY'; |
3
|
|
|
|
|
|
|
# ABSTRACT: 06perms |
4
|
|
|
|
|
|
|
$CPAN::Repository::Perms::VERSION = '0.009'; |
5
|
2
|
|
|
2
|
|
2543
|
use Moo; |
|
2
|
|
|
|
|
9998
|
|
|
2
|
|
|
|
|
9
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with qw( |
8
|
|
|
|
|
|
|
CPAN::Repository::Role::File |
9
|
|
|
|
|
|
|
); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
2264
|
use Dist::Data; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use File::Spec::Functions ':ALL'; |
13
|
|
|
|
|
|
|
use IO::File; |
14
|
|
|
|
|
|
|
use DateTime::Format::RFC3339; |
15
|
|
|
|
|
|
|
use DateTime::Format::Epoch::Unix; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub file_parts { 'modules', '06perms.txt' } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @perm_perms = qw( m f c ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has perms => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
lazy => 1, |
24
|
|
|
|
|
|
|
builder => '_build_perms', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _build_perms { |
28
|
|
|
|
|
|
|
my ( $self ) = @_; |
29
|
|
|
|
|
|
|
return {} unless $self->exist; |
30
|
|
|
|
|
|
|
my @lines = $self->get_file_lines; |
31
|
|
|
|
|
|
|
my %perms; |
32
|
|
|
|
|
|
|
for (@lines) { |
33
|
|
|
|
|
|
|
chomp($_); |
34
|
|
|
|
|
|
|
next if ($_ =~ /[^:]:[ \t]/); |
35
|
|
|
|
|
|
|
next if ($_ =~ /^ +/); |
36
|
|
|
|
|
|
|
next unless $_; |
37
|
|
|
|
|
|
|
my @perm_parts = split(',',$_); |
38
|
|
|
|
|
|
|
if (@perm_parts == 3) { |
39
|
|
|
|
|
|
|
my $module = shift @perm_parts; |
40
|
|
|
|
|
|
|
my $userid = shift @perm_parts; |
41
|
|
|
|
|
|
|
my $perm = shift @perm_parts; |
42
|
|
|
|
|
|
|
$perms{$module} = {} unless defined $perms{$module}; |
43
|
|
|
|
|
|
|
warn "already found entry for ".$userid." on ".$module if defined $perms{$module}->{$userid}; |
44
|
|
|
|
|
|
|
$perms{$module}->{$userid} = $perm; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
return \%perms; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has written_by => ( |
51
|
|
|
|
|
|
|
is => 'ro', |
52
|
|
|
|
|
|
|
required => 1, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub perms_linecount { |
56
|
|
|
|
|
|
|
my ( $self ) = @_; |
57
|
|
|
|
|
|
|
my $i = 0; |
58
|
|
|
|
|
|
|
for (keys %{$self->perms}) { |
59
|
|
|
|
|
|
|
for my $u (keys %{$self->perms->{$_}}) { |
60
|
|
|
|
|
|
|
$i++; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
return $i; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub set_perms { |
67
|
|
|
|
|
|
|
my ( $self, $module, $userid, $perm ) = @_; |
68
|
|
|
|
|
|
|
die "unknown perm ".$perm unless grep { $_ eq $perm } @perm_perms; |
69
|
|
|
|
|
|
|
$self->perms->{$module} = {} unless defined $self->perms->{$module}; |
70
|
|
|
|
|
|
|
$self->perms->{$module}->{$userid} = $perm; |
71
|
|
|
|
|
|
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_perms { |
75
|
|
|
|
|
|
|
my ( $self, $module ) = @_; |
76
|
|
|
|
|
|
|
return defined $self->perms->{$module} |
77
|
|
|
|
|
|
|
? $self->perms->{$module} |
78
|
|
|
|
|
|
|
: {} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub get_perms_by_userid { |
82
|
|
|
|
|
|
|
my ( $self, $userid ) = @_; |
83
|
|
|
|
|
|
|
my %perms_by_userid; |
84
|
|
|
|
|
|
|
for (keys %{$self->perms}) { |
85
|
|
|
|
|
|
|
if (defined $self->perms->{$_}->{$userid}) { |
86
|
|
|
|
|
|
|
$perms_by_userid{$_} = $self->perms->{$_}->{$userid}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
return \%perms_by_userid; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# File: 06perms.txt |
93
|
|
|
|
|
|
|
# Description: CSV file of upload permission to the CPAN per namespace |
94
|
|
|
|
|
|
|
# best-permission is one of "m" for "modulelist", "f" for |
95
|
|
|
|
|
|
|
# "first-come", "c" for "co-maint" |
96
|
|
|
|
|
|
|
# Columns: package,userid,best-permission |
97
|
|
|
|
|
|
|
# Line-Count: 215301 |
98
|
|
|
|
|
|
|
# Written-By: PAUSE version 1.14 |
99
|
|
|
|
|
|
|
# Date: Fri, 06 Jul 2012 20:23:21 GMT |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub generate_content { |
102
|
|
|
|
|
|
|
my ( $self ) = @_; |
103
|
|
|
|
|
|
|
my @file_parts = $self->file_parts; |
104
|
|
|
|
|
|
|
my $content = ""; |
105
|
|
|
|
|
|
|
$content .= $self->generate_header_line('File:',(pop @file_parts)); |
106
|
|
|
|
|
|
|
$content .= $self->generate_header_line('Description:','Description: CSV file of upload permission to the CPAN per namespace'); |
107
|
|
|
|
|
|
|
$content .= ' best-permission is one of "m" for "modulelist", "f" for'."\n"; |
108
|
|
|
|
|
|
|
$content .= ' "first-come", "c" for "co-maint"'."\n"; |
109
|
|
|
|
|
|
|
$content .= $self->generate_header_line('Columns:','package, userid, best-permission'); |
110
|
|
|
|
|
|
|
$content .= $self->generate_header_line('Intended-For:','Automated fetch routines, namespace documentation.'); |
111
|
|
|
|
|
|
|
$content .= $self->generate_header_line('Written-By:',$self->written_by); |
112
|
|
|
|
|
|
|
$content .= $self->generate_header_line('Line-Count:',$self->perms_linecount); |
113
|
|
|
|
|
|
|
$content .= $self->generate_header_line('Date:',DateTime->now->strftime('%a, %e %b %y %T %Z')); |
114
|
|
|
|
|
|
|
$content .= "\n"; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my @perms; |
117
|
|
|
|
|
|
|
for (sort { $a cmp $b } keys %{$self->perms}) { |
118
|
|
|
|
|
|
|
for my $u (sort { $a cmp $b } keys %{$self->perms->{$_}}) { |
119
|
|
|
|
|
|
|
push @perms, join(",",$_,$u,$self->perms->{$_}->{$u}); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
$content .= join "\n", @perms; |
123
|
|
|
|
|
|
|
return $content; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub generate_header_line { |
127
|
|
|
|
|
|
|
my ( $self, $key, $value ) = @_; |
128
|
|
|
|
|
|
|
return sprintf("%-13s %s\n",$key,$value); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |