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