line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Local::Plugin::MailRc; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$CPAN::Local::Plugin::MailRc::VERSION = '0.010'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Update 01mailrc.txt |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
81475
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1483
|
use CPAN::Index::API::File::MailRc; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use CPAN::DistnameInfo; |
13
|
|
|
|
|
|
|
use IO::String; |
14
|
|
|
|
|
|
|
use URI; |
15
|
|
|
|
|
|
|
use Path::Class qw(file dir); |
16
|
|
|
|
|
|
|
use Carp qw(croak); |
17
|
|
|
|
|
|
|
use Path::Class::URI; |
18
|
|
|
|
|
|
|
use List::Util qw(first); |
19
|
|
|
|
|
|
|
use Regexp::Common qw(URI); |
20
|
|
|
|
|
|
|
use Compress::Zlib qw(gzopen Z_STREAM_END), '$gzerrno'; |
21
|
|
|
|
|
|
|
use namespace::autoclean; |
22
|
|
|
|
|
|
|
use Moose; |
23
|
|
|
|
|
|
|
use MooseX::CoercePerAttribute; |
24
|
|
|
|
|
|
|
extends 'CPAN::Local::Plugin'; |
25
|
|
|
|
|
|
|
with qw(CPAN::Local::Role::Initialise CPAN::Local::Role::Index); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'root' => |
28
|
|
|
|
|
|
|
( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
required => 1, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'source' => |
35
|
|
|
|
|
|
|
( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
38
|
|
|
|
|
|
|
traits => [qw(Array CoercePerAttribute)], |
39
|
|
|
|
|
|
|
handles => { sources => 'elements' }, |
40
|
|
|
|
|
|
|
coerce => { Str => sub { [$_] } } |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'no_update' => |
44
|
|
|
|
|
|
|
( |
45
|
|
|
|
|
|
|
is => 'ro', |
46
|
|
|
|
|
|
|
isa => 'Bool', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub initialise |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
dir($self->root)->mkpath; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $mailrc = CPAN::Index::API::File::MailRc->new( |
56
|
|
|
|
|
|
|
repo_path => $self->root, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$mailrc->write_to_tarball; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub index |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
my ($self, @distros) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return if $self->no_update; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my ( @authors, %seen_authors, %authors_in_repo ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# extract all author ids form the local 02packages.details file |
71
|
|
|
|
|
|
|
$authors_in_repo{$_}++ for map { |
72
|
|
|
|
|
|
|
CPAN::DistnameInfo->new($_->{distribution})->cpanid |
73
|
|
|
|
|
|
|
} CPAN::Index::API::File::PackagesDetails->read_from_repo_path($self->root)->packages; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# also check the newly injected distros |
76
|
|
|
|
|
|
|
$authors_in_repo{$_->{authorid}}++ for @distros; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
foreach my $source ( $self->sources ) |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
# convert a local path to a 'file://' uri for LWP::Simple::get() |
81
|
|
|
|
|
|
|
# (this whole business can be handled better by IO::All) |
82
|
|
|
|
|
|
|
my $source_uri = $source =~ /$RE{URI}/ ? URI->new($source) : file($source)->uri; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $content = LWP::Simple::get($source_uri->as_string); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# handle tarballs |
87
|
|
|
|
|
|
|
if ($source_uri->path =~ /\.tar\.gz$/) { |
88
|
|
|
|
|
|
|
my $io = IO::String->new($content); |
89
|
|
|
|
|
|
|
my $gz = gzopen($io, 'rb') or croak "Cannot read gzipped mailrc: $gzerrno"; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my ($buffer, $unzipped_content); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$unzipped_content .= $buffer while $gz->gzread($buffer) > 0 ; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
croak "Error reading from mailrc: $gzerrno" . ($gzerrno+0) . "\n" |
96
|
|
|
|
|
|
|
if $gzerrno != Z_STREAM_END; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$gz->gzclose and croak "Error closing mailrc"; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$content = $unzipped_content; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $mailrc = CPAN::Index::API::File::MailRc->read_from_string($content); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
foreach my $author ( $mailrc->authors ) |
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
next if $seen_authors{$author->{authorid}}++; |
108
|
|
|
|
|
|
|
next unless $authors_in_repo{$author->{authorid}}; |
109
|
|
|
|
|
|
|
push @authors, $author; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $combined_mailrc = CPAN::Index::API::File::MailRc->new( |
114
|
|
|
|
|
|
|
authors => \@authors, |
115
|
|
|
|
|
|
|
repo_path => $self->root, |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
$combined_mailrc->write_to_tarball; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub requires_distribution_roles { qw(Metadata) } |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |
127
|
|
|
|
|
|
|
=pod |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NAME |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
CPAN::Local::Plugin::MailRc - Update 01mailrc.txt |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 VERSION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
version 0.010 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 IMPLEMENTS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item L<CPAN::Local::Role::Initialise> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item L<CPAN::Local::Role::Index> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 METHODS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 initialise |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Initializes the following index files: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item C<authors/01mailrc.txt.> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item C<modules/02packages.details.txt.gz> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item C<modules/03modlist.data.gz> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 index |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Updates C<02packages.details.txt.gz> with information for the |
166
|
|
|
|
|
|
|
newly added distributions. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Peter Shangov <pshangov@yahoo.com> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Venda, Inc.. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
177
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|