| 1 | package CPAN::Repository::Perms; | ||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||
| 3 | # ABSTRACT: 06perms | ||||||||||
| 4 | 3 | $CPAN::Repository::Perms::VERSION = '0.009'; | |||||||||
| 5 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | with qw( | |||||||||
| 8 | CPAN::Repository::Role::File | ||||||||||
| 9 | ); | ||||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | use Dist::Data; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | ▶ | use File::Spec::Functions ':ALL'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use IO::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | ▶ | use DateTime::Format::RFC3339; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 3 | ▶ | use DateTime::Format::Epoch::Unix; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 7 | ▶ | sub file_parts { 'modules', '06perms.txt' } | ||||||||
|
Subroutine
file_parts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | 3 | our @perm_perms = qw( m f c ); | |||||||||
| 20 | |||||||||||
| 21 | 3 | has perms => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | lazy => 1, | ||||||||||
| 24 | builder => '_build_perms', | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | sub _build_perms { | ||||||||||
| 28 | 2 | ▶ | my ( $self ) = @_; | ||||||||
|
Subroutine
_build_perms: called CC=9 SCAR=42.4
| |||||||||||
| 29 | 2 | ▶ | return {} unless $self->exist; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | my @lines = $self->get_file_lines; | |||||||||
| 31 | 0 | my %perms; | |||||||||
| 32 | 0 | for (@lines) { | |||||||||
| 33 | 0 | chomp($_); | |||||||||
| 34 | 0 | ▶ | next if ($_ =~ /[^:]:[ \t]/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | ▶ | next if ($_ =~ /^ +/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | ▶ | next unless $_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | my @perm_parts = split(',',$_); | |||||||||
| 38 | 0 | ▶ | if (@perm_parts == 3) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | my $module = shift @perm_parts; | |||||||||
| 40 | 0 | my $userid = shift @perm_parts; | |||||||||
| 41 | 0 | my $perm = shift @perm_parts; | |||||||||
| 42 | 0 | ▶ | $perms{$module} = {} unless defined $perms{$module}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | ▶ | warn "already found entry for ".$userid." on ".$module if defined $perms{$module}->{$userid}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | $perms{$module}->{$userid} = $perm; | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | 0 | return \%perms; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 3 | has written_by => ( | |||||||||
| 51 | is => 'ro', | ||||||||||
| 52 | required => 1, | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | sub perms_linecount { | ||||||||||
| 56 | 2 | ▶ | my ( $self ) = @_; | ||||||||
|
Subroutine
perms_linecount: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 57 | 2 | my $i = 0; | |||||||||
| 58 | 2 | for (keys %{$self->perms}) { | |||||||||
| 59 | 3 | for my $u (keys %{$self->perms->{$_}}) { | |||||||||
| 60 | 3 | $i++; | |||||||||
| 61 | } | ||||||||||
| 62 | } | ||||||||||
| 63 | 2 | return $i; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub set_perms { | ||||||||||
| 67 | 3 | ▶ | my ( $self, $module, $userid, $perm ) = @_; | ||||||||
|
Subroutine
set_perms: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||
| 68 | 3 | ▶ | die "unknown perm ".$perm unless grep { $_ eq $perm } @perm_perms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 3 | ▶ | $self->perms->{$module} = {} unless defined $self->perms->{$module}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 3 | $self->perms->{$module}->{$userid} = $perm; | |||||||||
| 71 | 3 | return $self; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | sub get_perms { | ||||||||||
| 75 | 0 | ▶ | my ( $self, $module ) = @_; | ||||||||
|
Subroutine
get_perms: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 76 | return defined $self->perms->{$module} | ||||||||||
| 77 | 0 | ▶ | ? $self->perms->{$module} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | : {} | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | sub get_perms_by_userid { | ||||||||||
| 82 | 0 | ▶ | my ( $self, $userid ) = @_; | ||||||||
|
Subroutine
get_perms_by_userid: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 83 | 0 | my %perms_by_userid; | |||||||||
| 84 | 0 | for (keys %{$self->perms}) { | |||||||||
| 85 | 0 | ▶ | if (defined $self->perms->{$_}->{$userid}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $perms_by_userid{$_} = $self->perms->{$_}->{$userid}; | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | 0 | 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 | 2 | ▶ | my ( $self ) = @_; | ||||||||
|
Subroutine
generate_content: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 103 | 2 | my @file_parts = $self->file_parts; | |||||||||
| 104 | 2 | my $content = ""; | |||||||||
| 105 | 2 | $content .= $self->generate_header_line('File:',(pop @file_parts)); | |||||||||
| 106 | 2 | $content .= $self->generate_header_line('Description:','Description: CSV file of upload permission to the CPAN per namespace'); | |||||||||
| 107 | 2 | $content .= ' best-permission is one of "m" for "modulelist", "f" for'."\n"; | |||||||||
| 108 | 2 | $content .= ' "first-come", "c" for "co-maint"'."\n"; | |||||||||
| 109 | 2 | $content .= $self->generate_header_line('Columns:','package, userid, best-permission'); | |||||||||
| 110 | 2 | $content .= $self->generate_header_line('Intended-For:','Automated fetch routines, namespace documentation.'); | |||||||||
| 111 | 2 | $content .= $self->generate_header_line('Written-By:',$self->written_by); | |||||||||
| 112 | 2 | $content .= $self->generate_header_line('Line-Count:',$self->perms_linecount); | |||||||||
| 113 | 2 | $content .= $self->generate_header_line('Date:',DateTime->now->strftime('%a, %e %b %y %T %Z')); | |||||||||
| 114 | 2 | $content .= "\n"; | |||||||||
| 115 | |||||||||||
| 116 | 2 | my @perms; | |||||||||
| 117 | 2 | for (sort { $a cmp $b } keys %{$self->perms}) { | |||||||||
| 118 | 3 | for my $u (sort { $a cmp $b } keys %{$self->perms->{$_}}) { | |||||||||
| 119 | 3 | push @perms, join(",",$_,$u,$self->perms->{$_}->{$u}); | |||||||||
| 120 | } | ||||||||||
| 121 | } | ||||||||||
| 122 | 2 | $content .= join "\n", @perms; | |||||||||
| 123 | 2 | return $content; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | sub generate_header_line { | ||||||||||
| 127 | 14 | ▶ | my ( $self, $key, $value ) = @_; | ||||||||
|
Subroutine
generate_header_line: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 128 | 14 | return sprintf("%-13s %s\n",$key,$value); | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 3 | 1; | |||||||||
| 132 | |||||||||||
| 133 | __END__ | ||||||||||
| 134 | |||||||||||
| 135 | =pod | ||||||||||
| 136 | |||||||||||
| 137 | =head1 NAME | ||||||||||
| 138 | |||||||||||
| 139 | CPAN::Repository::Perms - 06perms | ||||||||||
| 140 | |||||||||||
| 141 | =head1 VERSION | ||||||||||
| 142 | |||||||||||
| 143 | version 0.009 | ||||||||||
| 144 | |||||||||||
| 145 | =head1 SYNOPSIS | ||||||||||
| 146 | |||||||||||
| 147 | use CPAN::Repository::Perms; | ||||||||||
| 148 | |||||||||||
| 149 | my $packages = CPAN::Repository::Perms->new({ | ||||||||||
| 150 | repository_root => $fullpath_to_root, | ||||||||||
| 151 | written_by => $written_by, | ||||||||||
| 152 | }); | ||||||||||
| 153 | |||||||||||
| 154 | =encoding utf8 | ||||||||||
| 155 | |||||||||||
| 156 | =head1 SEE ALSO | ||||||||||
| 157 | |||||||||||
| 158 | L<CPAN::Repository> | ||||||||||
| 159 | |||||||||||
| 160 | =head1 SUPPORT | ||||||||||
| 161 | |||||||||||
| 162 | IRC | ||||||||||
| 163 | |||||||||||
| 164 | Join #duckduckgo on irc.freenode.net. Highlight Getty for fast reaction :). | ||||||||||
| 165 | |||||||||||
| 166 | Repository | ||||||||||
| 167 | |||||||||||
| 168 | http://github.com/Getty/p5-cpan-repository | ||||||||||
| 169 | Pull request and additional contributors are welcome | ||||||||||
| 170 | |||||||||||
| 171 | Issue Tracker | ||||||||||
| 172 | |||||||||||
| 173 | http://github.com/Getty/p5-cpan-repository/issues | ||||||||||
| 174 | |||||||||||
| 175 | =head1 AUTHOR | ||||||||||
| 176 | |||||||||||
| 177 | Torsten Raudssus <torsten@raudss.us> L<http://raudss.us/> | ||||||||||
| 178 | |||||||||||
| 179 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 180 | |||||||||||
| 181 | This software is copyright (c) 2012 by DuckDuckGo, Inc. L<http://duckduckgo.com/>. | ||||||||||
| 182 | |||||||||||
| 183 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 184 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 185 | |||||||||||
| 186 | =cut | ||||||||||