line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MyCPAN::Indexer::CPANMiniInject; |
2
|
1
|
|
|
1
|
|
1814
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use parent qw(MyCPAN::Indexer::Component); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
51
|
use vars qw($VERSION $logger); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
72
|
|
7
|
|
|
|
|
|
|
$VERSION = '1.28_12'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
10
|
1
|
|
|
1
|
|
5
|
use File::Spec::Functions qw(catfile); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
11
|
1
|
|
|
1
|
|
5
|
use Log::Log4perl; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
77
|
use MyCPAN::Indexer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use YAML; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
MyCPAN::Indexer::CPANMiniInject - Do the indexing, and put the dists in a MiniCPAN |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Use this in backpan_indexer.pl by specifying it as the queue class: |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# in backpan_indexer.config |
24
|
|
|
|
|
|
|
worker_class MyCPAN::Indexer::CPANMiniInject |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This class takes a distribution and analyses it. Once it knows the modules |
29
|
|
|
|
|
|
|
inside the distribution, it adds the distribution to a CPAN::Mini::Inject |
30
|
|
|
|
|
|
|
staging repository. This portion specifically does not inject the modules |
31
|
|
|
|
|
|
|
into the MiniCPAN. The injection has to happen after all of the workers |
32
|
|
|
|
|
|
|
have finished. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 Configuration |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over 4 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item minicpan_inject_config |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
The location of the configuration file for CPAN::Mini::Config |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=back |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 Methods |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over 4 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item get_task( $Notes ) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
C sets the C key in the C<$Notes> hash reference. The |
53
|
|
|
|
|
|
|
value is a code reference that takes a distribution path as its only |
54
|
|
|
|
|
|
|
argument and indexes that distribution. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
See L for details about what C expects |
57
|
|
|
|
|
|
|
and should do. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
BEGIN { |
62
|
|
|
|
|
|
|
$logger = Log::Log4perl->get_logger( 'Worker' ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub component_type { $_[0]->worker_type } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_task |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
my( $self ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $child_task = sub { |
72
|
|
|
|
|
|
|
my $dist = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $basename = $self->_check_for_previous_result( $dist ); |
75
|
|
|
|
|
|
|
return unless $basename; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $Config = $self->get_config; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$logger->info( "Child [$$] processing $dist\n" ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $indexer = $self->get_coordinator->get_component( 'indexer' ); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
unless( chdir $Config->temp_dir ) |
84
|
|
|
|
|
|
|
{ |
85
|
|
|
|
|
|
|
$logger->error( "Could not change to " . $Config->temp_dir . " : $!\n" ); |
86
|
|
|
|
|
|
|
exit 255; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
local $SIG{ALRM} = sub { die "alarm\n" }; |
90
|
|
|
|
|
|
|
alarm( $Config->alarm || 15 ); |
91
|
|
|
|
|
|
|
my $info = eval { $indexer->run( $dist ) }; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
unless( defined $info ) |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
$logger->error( "run failed: $@" ); |
96
|
|
|
|
|
|
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
elsif( ! eval { $info->run_info( 'completed' ) } ) |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
$logger->error( "$basename did not complete\n" ); |
101
|
|
|
|
|
|
|
$self->_copy_bad_dist( $info ) if $Config->copy_bad_dists; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
alarm 0; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$self->_add_run_info( $info ); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$self->get_note( 'reporter' )->( $info ); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$logger->debug( "Child [$$] process done" ); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$self->set_note( 'child_task', $child_task ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _copy_bad_dist |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
my( $self, $info ) = @_; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $config = $self->get_config; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
if( my $bad_dist_dir = $config->copy_bad_dists ) |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
my $dist_file = $info->dist_info( 'dist_file' ); |
127
|
|
|
|
|
|
|
my $basename = $info->dist_info( 'dist_basename' ); |
128
|
|
|
|
|
|
|
my $new_name = catfile( $bad_dist_dir, $basename ); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
unless( -e $new_name ) |
131
|
|
|
|
|
|
|
{ |
132
|
|
|
|
|
|
|
$logger->debug( "Copying bad dist" ); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my( $in, $out ); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
unless( open $in, "<", $dist_file ) |
137
|
|
|
|
|
|
|
{ |
138
|
|
|
|
|
|
|
$logger->fatal( "Could not open bad dist to $dist_file: $!" ); |
139
|
|
|
|
|
|
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
unless( open $out, ">", $new_name ) |
143
|
|
|
|
|
|
|
{ |
144
|
|
|
|
|
|
|
$logger->fatal( "Could not copy bad dist to $new_name: $!" ); |
145
|
|
|
|
|
|
|
return; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
while( <$in> ) { print { $out } $_ } |
149
|
|
|
|
|
|
|
close $in; |
150
|
|
|
|
|
|
|
close $out; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub _check_for_previous_result |
156
|
|
|
|
|
|
|
{ |
157
|
|
|
|
|
|
|
my( $self ) = @_; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $Config = $self->get_config; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $dist = $self->get_dist_info( 'filename' ); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
( my $basename = basename( $dist ) ) =~ s/\.(tgz|tar\.gz|zip)$//; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my $yml_dir = catfile( $Config->report_dir, "meta" ); |
166
|
|
|
|
|
|
|
my $yml_error_dir = catfile( $Config->report_dir, "meta-errors" ); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $yml_path = catfile( $yml_dir, "$basename.yml" ); |
169
|
|
|
|
|
|
|
my $yml_error_path = catfile( $yml_error_dir, "$basename.yml" ); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
if( my @path = grep { -e } ( $yml_path, $yml_error_path ) ) |
172
|
|
|
|
|
|
|
{ |
173
|
|
|
|
|
|
|
$logger->debug( "Found run output for $basename in $path[0]. Skipping...\n" ); |
174
|
|
|
|
|
|
|
return; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
return $basename; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub _add_run_info |
181
|
|
|
|
|
|
|
{ |
182
|
|
|
|
|
|
|
my( $self, $info ) = @_; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
my $Config = $self->get_config; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
return unless eval { $info->can( 'set_run_info' ) }; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$info->set_run_info( $_, $Config->get( $_ ) ) |
189
|
|
|
|
|
|
|
foreach ( $Config->directives ); |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
$info->set_run_info( 'uuid', $Config->UUID ); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
$info->set_run_info( 'child_pid', $$ ); |
194
|
|
|
|
|
|
|
$info->set_run_info( 'parent_pid', getppid ); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$info->set_run_info( 'ENV', \%ENV ); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
return 1; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 SEE ALSO |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
MyCPAN::Indexer, MyCPAN::Indexer::Tutorial |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
This code is in Github: |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
git://github.com/briandfoy/mycpan-indexer.git |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHOR |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
brian d foy, C<< >> |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Copyright (c) 2008-2013, brian d foy, All Rights Reserved. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
You may redistribute this under the same terms as Perl itself. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
1; |