| 1 | package CPAN::Index::API::File::MailRc; | ||||||||||
| 2 | { | ||||||||||
| 3 | 2 | $CPAN::Index::API::File::MailRc::VERSION = '0.007'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Interface to 01mailrc.txt | ||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | with qw( | |||||||||
| 15 | CPAN::Index::API::Role::Writable | ||||||||||
| 16 | CPAN::Index::API::Role::Readable | ||||||||||
| 17 | CPAN::Index::API::Role::Clonable | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | has authors => ( | ||||||||||
| 21 | is => 'bare', | ||||||||||
| 22 | isa => 'ArrayRef', | ||||||||||
| 23 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 24 | 2 | traits => ['Array'], | |||||||||
| 25 | handles => { | ||||||||||
| 26 | author_count => 'count', | ||||||||||
| 27 | authors => 'elements', | ||||||||||
| 28 | }, | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | sub sorted_authors { | ||||||||||
| 32 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
sorted_authors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | 1 | return sort { $a->{authorid} cmp $b->{authorid} } $self->authors; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | sub parse { | ||||||||||
| 37 | 1 | ▶ | my ( $self, $content ) = @_; | ||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 38 | |||||||||||
| 39 | 1 | my @authors; | |||||||||
| 40 | |||||||||||
| 41 | 1 | ▶ | if ($content) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | { | ||||||||||
| 43 | |||||||||||
| 44 | 1 | foreach my $line ( split "\n", $content ) { | |||||||||
| 45 | 3 | my ( $alias, $authorid, $long ) = split ' ', $line, 3; | |||||||||
| 46 | 3 | $long =~ s/^"//; | |||||||||
| 47 | 3 | $long =~ s/"$//; | |||||||||
| 48 | 3 | my ($name, $email) = $long =~ /(.*) <(.+)>$/; | |||||||||
| 49 | |||||||||||
| 50 | 3 | ▶ | undef $email if $email eq 'CENSORED'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 3 | my $author = { | |||||||||
| 53 | authorid => $authorid, | ||||||||||
| 54 | name => $name, | ||||||||||
| 55 | email => $email, | ||||||||||
| 56 | }; | ||||||||||
| 57 | |||||||||||
| 58 | 3 | push @authors, $author; | |||||||||
| 59 | } | ||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | return ( authors => \@authors ); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub default_location { 'authors/01mailrc.txt.gz' } | ||||||||
|
Subroutine
default_location: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | |||||||||||
| 67 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | =pod | ||||||||||
| 73 | |||||||||||
| 74 | =head1 NAME | ||||||||||
| 75 | |||||||||||
| 76 | CPAN::Index::API::File::MailRc - Interface to 01mailrc.txt | ||||||||||
| 77 | |||||||||||
| 78 | =head1 VERSION | ||||||||||
| 79 | |||||||||||
| 80 | version 0.007 | ||||||||||
| 81 | |||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||
| 83 | |||||||||||
| 84 | my $mailrc = CPAN::Index::File::MailRc->parse_from_repo_uri( | ||||||||||
| 85 | 'http://cpan.perl.org' | ||||||||||
| 86 | ); | ||||||||||
| 87 | |||||||||||
| 88 | foreach my $author ($mailrc->sorted_authors) { | ||||||||||
| 89 | ... # do something | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | =head1 DESCRIPTION | ||||||||||
| 93 | |||||||||||
| 94 | This is a class to read and write 01mailrc.txt | ||||||||||
| 95 | |||||||||||
| 96 | =head1 METHODS | ||||||||||
| 97 | |||||||||||
| 98 | =head2 authors | ||||||||||
| 99 | |||||||||||
| 100 | List of hashres containing author data. The structure of the hashrefs is | ||||||||||
| 101 | as follows: | ||||||||||
| 102 | |||||||||||
| 103 | =over | ||||||||||
| 104 | |||||||||||
| 105 | =item authorid | ||||||||||
| 106 | |||||||||||
| 107 | CPAN id of the author. This should be a string containing only capital latin | ||||||||||
| 108 | letters and is at least 2 characters long. | ||||||||||
| 109 | |||||||||||
| 110 | =item name | ||||||||||
| 111 | |||||||||||
| 112 | Author's full name. | ||||||||||
| 113 | |||||||||||
| 114 | =item email | ||||||||||
| 115 | |||||||||||
| 116 | Author's email. | ||||||||||
| 117 | |||||||||||
| 118 | =back | ||||||||||
| 119 | |||||||||||
| 120 | =head2 sorted_authors | ||||||||||
| 121 | |||||||||||
| 122 | List of authors sorted by pause id. | ||||||||||
| 123 | |||||||||||
| 124 | =head2 parse | ||||||||||
| 125 | |||||||||||
| 126 | Parses the file and reurns its representation as a data structure. | ||||||||||
| 127 | |||||||||||
| 128 | =head2 default_location | ||||||||||
| 129 | |||||||||||
| 130 | Default file location - C<authors/01mailrc.txt.gz>. | ||||||||||
| 131 | |||||||||||
| 132 | =head1 METHODS FROM ROLES | ||||||||||
| 133 | |||||||||||
| 134 | =over | ||||||||||
| 135 | |||||||||||
| 136 | =item <CPAN::Index::API::Role::Readable/read_from_string> | ||||||||||
| 137 | |||||||||||
| 138 | =item <CPAN::Index::API::Role::Readable/read_from_file> | ||||||||||
| 139 | |||||||||||
| 140 | =item <CPAN::Index::API::Role::Readable/read_from_tarball> | ||||||||||
| 141 | |||||||||||
| 142 | =item <CPAN::Index::API::Role::Readable/read_from_repo_path> | ||||||||||
| 143 | |||||||||||
| 144 | =item <CPAN::Index::API::Role::Readable/read_from_repo_uri> | ||||||||||
| 145 | |||||||||||
| 146 | =item L<CPAN::Index::API::Role::Writable/tarball_is_default> | ||||||||||
| 147 | |||||||||||
| 148 | =item L<CPAN::Index::API::Role::Writable/repo_path> | ||||||||||
| 149 | |||||||||||
| 150 | =item L<CPAN::Index::API::Role::Writable/template> | ||||||||||
| 151 | |||||||||||
| 152 | =item L<CPAN::Index::API::Role::Writable/content> | ||||||||||
| 153 | |||||||||||
| 154 | =item L<CPAN::Index::API::Role::Writable/write_to_file> | ||||||||||
| 155 | |||||||||||
| 156 | =item L<CPAN::Index::API::Role::Writable/write_to_tarball> | ||||||||||
| 157 | |||||||||||
| 158 | =item L<CPAN::Index::API::Role::Clonable/clone> | ||||||||||
| 159 | |||||||||||
| 160 | =back | ||||||||||
| 161 | |||||||||||
| 162 | =head1 AUTHOR | ||||||||||
| 163 | |||||||||||
| 164 | Peter Shangov <pshangov@yahoo.com> | ||||||||||
| 165 | |||||||||||
| 166 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 167 | |||||||||||
| 168 | This software is copyright (c) 2012 by Venda, Inc.. | ||||||||||
| 169 | |||||||||||
| 170 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 171 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | |||||||||||
| 176 | __DATA__ | ||||||||||
| 177 | [% | ||||||||||
| 178 | foreach my $author ($self->sorted_authors) { | ||||||||||
| 179 | $OUT .= sprintf qq[alias %s "%s <%s>"\n], | ||||||||||
| 180 | $author->{authorid}, | ||||||||||
| 181 | $author->{name}, | ||||||||||
| 182 | $author->{email} ? $author->{email} : 'CENSORED'; | ||||||||||
| 183 | } | ||||||||||
| 184 | %] | ||||||||||