blib/lib/CPAN/Mini/Devel/Recent.pm

filter: Statementstmt 35.7% 49 / 137 Branchbran 1.9% 1 / 52 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 71.4% 15 / 21 Podpod n/a totaltotal 30.5% 65 / 213 SCAR 61.6
CC
33
Cov
26%
_parse_module_index
1056.0
BEGIN
2.9
_fixed_mirrors
2.0
CRAP 471.1
↑ Summary
1 #
2 # This file is part of CPAN-Mini-Devel-Recent
3 #
4 # This software is Copyright (c) 2011 by David Golden.
5 #
6 # This is free software, licensed under:
7 #
8 # The Apache License, Version 2.0, January 2004
9 #
10 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 package CPAN::Mini::Devel::Recent;
14 BEGIN {
15 1 ▶ $CPAN::Mini::Devel::Recent::VERSION = '0.06';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 }
17 # ABSTRACT: Create CPAN::Mini mirror with recent developer releases
18  
19 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use CPAN::Mini 0.567;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use CPAN 1.92 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use CPAN::Tarzip;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use CPAN::HandleConfig;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use File::Temp 0.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use File::Spec 3.27;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use File::Basename qw/basename/;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use YAML::Syck 1.07 qw/LoadFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 our @ISA = qw/CPAN::Mini/;
31  
32 #--------------------------------------------------------------------------#
33 # globals
34 #--------------------------------------------------------------------------#
35  
36 BEGIN {
37 1 ▶ *DEBUG = $ENV{CPAN_MINI_DEBUG} ? sub {1} : sub {0};
Subroutine BEGIN: called CC=2 SCAR=10.5
Subroutine __ANON__: not called CC=1 SCAR=2.0
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'CPAN_MINI_DEBUG'} ? : 0 1 1
38 }
39  
40 1 my $tmp_dir = File::Temp->newdir( 'CPAN-Mini-Devel-Recent-XXXXXXX',
41 DIR => File::Spec->tmpdir,
42 );
43  
44 #--------------------------------------------------------------------------#
45 # Extend index methods to mirror RECENT* files
46 #--------------------------------------------------------------------------#
47  
48 1 my @recent_files = qw(
49 authors/RECENT-1h.yaml
50 authors/RECENT-6h.yaml
51 authors/RECENT-1d.yaml
52 authors/RECENT-1W.yaml
53 authors/RECENT-1M.yaml
54 authors/RECENT-1Q.yaml
55 authors/RECENT-1Y.yaml
56 authors/RECENT-Z.yaml
57 );
58  
59 sub _fixed_mirrors {
60 0 ▶ my $self = shift;
Subroutine _fixed_mirrors: not called CC=1 SCAR=6.9
61 0 return (@recent_files, $self->SUPER::_fixed_mirrors);
62 }
63  
64 #--------------------------------------------------------------------------#
65 # Replace _get_mirror_list to add developer versions
66 #--------------------------------------------------------------------------#
67  
68 sub _get_mirror_list {
69 0 ▶ my $self = shift;
Subroutine _get_mirror_list: not called CC=1 SCAR=6.9
70  
71 ## CPAN::Mini::Devel::Recent addition using find-ls.gz
72 0 my @recent = map {File::Spec->catfile($self->{scratch}, $_)} @recent_files;
73  
74 my $packages = File::Spec->catfile(
75 $self->{scratch},
76 0 qw(modules 02packages.details.txt.gz)
77 );
78  
79 0 return $self->_parse_module_index( $packages, @recent );
80 }
81  
82 #--------------------------------------------------------------------------#
83 # private variables and functions
84 #--------------------------------------------------------------------------#
85  
86 1 my $module_index_re = qr{
87 ^\s href="\.\./authors/id/./../ # skip prelude
88 ([^"]+) # capture to next dquote mark
89 .+? </a> # skip to end of hyperlink
90 \s+ # skip spaces
91 \S+ # skip size
92 \s+ # skip spaces
93 (\S+) # capture day
94 \s+ # skip spaces
95 (\S+) # capture month
96 \s+ # skip spaces
97 (\S+) # capture year
98 }xms;
99  
100 1 my %months = (
101 Jan => '01', Feb => '02', Mar => '03', Apr => '04', May => '05',
102 Jun => '06', Jul => '07', Aug => '08', Sep => '09', Oct => '10',
103 Nov => '11', Dec => '12'
104 );
105  
106 # standard regexes
107 # note on archive suffixes -- .pm.gz shows up in 02packagesf
108 1 my %re = (
109 perls => qr{(?:
110 /(?:emb|syb|bio)?perl-\d
111 | /(?:parrot|ponie|kurila|Perl6-Pugs)-\d
112 | /perl-?5\.004
113 | /perl_mlb\.zip
114 | /Per6-Pugs
115 )}xi,
116 archive => qr{\.(?:tar\.(?:bz2|gz|Z)|t(?:gz|bz)|(?<!ppm\.)zip|pm.gz)$}i,
117 target_dir => qr{^id/\w/\w\w/},
118 leading_initials => qr{(.)/\1./},
119 );
120  
121 # match version and suffix
122 1 $re{version_suffix} = qr{([-._]v?[0-9].*)?($re{archive})};
123  
124 # split into "AUTHOR/Name" and "Version"
125 1 $re{split_them} = qr{^(.+?)$re{version_suffix}$};
126  
127 # matches "AUTHOR/tarball.suffix" or AUTHOR/modules/tarball.suffix
128 # and not other "AUTHOR/subdir/whatever"
129  
130 # Just get AUTHOR/tarball.suffix from whatever file name is passed in
131 sub _get_base_id {
132 0 ▶ my $file = shift;
Subroutine _get_base_id: not called CC=1 SCAR=6.9
133 0 my $base_id = $file;
134 0 $base_id =~ s{$re{target_dir}}{};
135 0 return $base_id;
136 }
137  
138 sub _base_name {
139 0 ▶ my ($base_id) = @_;
Subroutine _base_name: not called CC=1 SCAR=6.9
140 0 my $base_file = basename $base_id;
141 0 my ($base_name, $base_version) = $base_file =~ $re{split_them};
142 0 return $base_name;
143 }
144  
145  
146 #--------------------------------------------------------------------------#
147 # _parse_module_index
148 #
149 # parse index and return array_ref of distributions in reverse date order
150 #--------------------------------------------------------------------------#-
151  
152 sub _parse_module_index {
153 0 ▶ my ($self, $packages, @recent ) = @_;
Subroutine _parse_module_index: not called CC=32 SCAR=69.6
154  
155 # first walk the packages list
156 # and build an index
157  
158 0 my (%valid_distros, %mirror);
159 0 my (%latest, %latest_dev);
160  
161 0 ▶ my $gz = Compress::Zlib::gzopen($packages, "rb")
Branch: 1 branch
BranchTrueFalseTotal
my $gz = &Compress::Zlib::gzopen($packages, "rb") or die "Cannot open package list: $Compress::Zlib::gzerrno" 0 0 0
162 or die "Cannot open package list: $Compress::Zlib::gzerrno";
163  
164 0 $self->trace( "Scanning 02packages.details ...\n" );
165 0 my $inheader = 1;
166 0 ▶ while ($gz->gzreadline($_) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gz->gzreadline($_) > 0) 0 0 0
167 0 ▶ if ($inheader) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inheader) 0 0 0
168 0 ▶ $inheader = 0 unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
169 0 next;
170 }
171  
172 0 my ($module, $version, $path) = split;
173  
174 # shouldn't happen, but 02packages has in the past indexed a PPM file
175 0 ▶ next unless $path =~ $re{archive};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /$re{"archive"}/ 0 0 0
176  
177 0 ▶ next if $self->_filter_module({
Branch: 1 branch
BranchTrueFalseTotal
if $self->_filter_module({"module", $module, "version", $version, "path", $path}) 0 0 0
178 module => $module,
179 version => $version,
180 path => $path,
181 });
182  
183  
184 0 ▶ my $base_id = _get_base_id("id/$path")
Branch: 1 branch
BranchTrueFalseTotal
my $base_id = _get_base_id("id/$path") or $self->trace("Error getting base_id of '${path}'\n") 0 0 0
185 or $self->trace("Error getting base_id of '$path'\n");
186 0 $valid_distros{$base_id}++;
187 0 ▶ my $base_name = _base_name( $base_id )
Branch: 1 branch
BranchTrueFalseTotal
my $base_name = _base_name($base_id) or $self->trace("Error getting base_name of '${base_id}'\n") 0 0 0
188 or $self->trace("Error getting base_name of '$base_id'\n");
189 0 ▶ if ($base_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base_name) 0 0 0
190 0 $latest{$base_name} = {
191 datetime => 0,
192 base_id => $base_id
193 };
194 }
195 }
196  
197 # next walk the recent list
198 0 $self->trace( "Scanning RECENT files for dev releases ...\n" );
199  
200 0 my %living;
201  
202 0 for my $rr ( reverse @recent ) {
203 0 my $yaml = LoadFile( $rr );
204 0 my ($add, $del) = (0,0);
205 0 for my $rec ( sort {$a->{epoch} <=> $b->{epoch}} @{$yaml->{recent}} ) {
206 0 ▶ if ( $rec->{type} eq 'new' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rec->{'type'} eq 'new') { } 0 0 0
elsif ($rec->{'type'} eq 'delete') { } 0 0 0
207 0 $living{$rec->{path}} = $rec;
208 0 $add++;
209 }
210 elsif ( $rec->{type} eq 'delete' ) {
211 0 delete $living{$rec->{path}};
212 0 $del++;
213 }
214 }
215 }
216  
217 0 my $match = 0;
218 0 for my $rec ( sort {$a->{epoch} <=> $b->{epoch}} values %living ) {
219 0 my %stat;
220 0 @stat{qw/name datetime type/}=@{$rec}{qw/path epoch type/};
221  
222 # skip things that aren't a tarball
223 0 ▶ next unless $stat{name} =~ $re{archive};
Branch: 1 branch
BranchTrueFalseTotal
unless $stat{"name"} =~ /$re{"archive"}/ 0 0 0
224  
225 # skip if not AUTHOR/tarball
226 # skip perls
227 my $base_id = _get_base_id($stat{name})
228 0 ▶ or $self->trace("Error getting base_id of '$stat{name}'\n");
Branch: 1 branch
BranchTrueFalseTotal
my $base_id = _get_base_id($stat{"name"}) or $self->trace(qq[Error getting base_id of '$stat{"name"}'\n]) 0 0 0
229 0 ▶ next unless $base_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $base_id 0 0 0
230  
231 0 ▶ next if $base_id =~ $re{perls};
Branch: 1 branch
BranchTrueFalseTotal
if $base_id =~ /$re{"perls"}/ 0 0 0
232  
233 0 ▶ my $base_name = _base_name( $base_id )
Branch: 1 branch
BranchTrueFalseTotal
my $base_name = _base_name($base_id) or $self->trace("# Error getting base_name from '${base_id}'") 0 0 0
234 or $self->trace("# Error getting base_name from '$base_id'");
235  
236 # if $base_id matches 02packages, then it is the latest version
237 # and we definitely want it; also update datetime from the initial
238 # assumption of 0
239 0 ▶ if ( $valid_distros{$base_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valid_distros{$base_id}) { } 0 0 0
240 0 $mirror{$base_id} = $stat{datetime};
241 0 ▶ next unless $base_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $base_name 0 0 0
242 0 $latest{$base_name}{base_id} = $base_id;
243 0 ▶ if ( $stat{datetime} > $latest{$base_name}{datetime} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stat{"datetime"} > $latest{$base_name}{"datetime"}) 0 0 0
244 0 $latest{$base_name}{datetime} = $stat{datetime};
245 }
246 0 $match++;
247 }
248 # if not in the packages file, we only want it if it resembles
249 # something in the package file and we only the most recent one
250 else {
251 # skip if couldn't parse out the name without version number
252 0 ▶ next unless defined $base_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base_name 0 0 0
253  
254 # skip unless there's a matching base from the packages file
255 0 ▶ next unless exists $latest{$base_name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $latest{$base_name} 0 0 0
256  
257 # keep only the latest
258 0 ▶ $latest_dev{$base_name} ||= { datetime => 0 };
Condition0%0/2
$latest_dev{$base_name} ||= {"datetime", 0}
l!l
00
MC/DC0%0/1
$latest_dev{$base_name} ||= {"datetime", 0}
$latest_dev{$base_name}
Truth table0%0/2
A
A= $latest_dev{$base_name}
Aresult
11
00
259 0 ▶ if ( $stat{datetime} > $latest_dev{$base_name}{datetime} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stat{"datetime"} > $latest_dev{$base_name}{"datetime"}) 0 0 0
260 $latest_dev{$base_name} = {
261 datetime => $stat{datetime},
262 0 base_id => $base_id
263 };
264 }
265 }
266 }
267  
268 # pick up anything from packages we didn't already get (shouldn't happen)
269 0 my $missing = 0;
270 0 for my $base_name ( keys %latest ) {
271 0 my $base_id = $latest{$base_name}{base_id};
272 0 ▶ next if exists $mirror{$base_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mirror{$base_id} 0 0 0
273 0 $mirror{$base_id} = $latest{$base_name}{datetime};
274 0 $missing++;
275 }
276  
277 # for dev versions, it must be newer than the latest version of
278 # the same base name from the packages file
279  
280 0 for my $base_name ( keys %latest_dev ) {
281 0 ▶ if ( ! $latest{$base_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($latest{$base_name}) 0 0 0
282 0 $self->trace( "Shouldn't be missing '$base_name' matching '$latest_dev{$base_name}{base_id}'\n" );
283 0 next;
284 }
285 0 ▶ next if $latest{$base_name}{datetime} > $latest_dev{$base_name}{datetime};
Branch: 1 branch
BranchTrueFalseTotal
if $latest{$base_name}{"datetime"} > $latest_dev{$base_name}{"datetime"} 0 0 0
286 0 my $base_id = $latest_dev{$base_name}{base_id};
287 0 $mirror{ $base_id } = $latest_dev{$base_name}{datetime};
288 }
289  
290 my $mirror_list =
291 0 [ sort map { s{^(((.).).+)$}{authors/id/$3/$2/$1}; $_ } keys %mirror ];
292  
293 0 return $mirror_list;
294 }
295  
296 1 1; #modules must return true
297  
298  
299  
300 =pod
301  
302 =head1 NAME
303  
304 CPAN::Mini::Devel::Recent - Create CPAN::Mini mirror with recent developer releases
305  
306 =head1 VERSION
307  
308 version 0.06
309  
310 =head1 SYNOPSIS
311  
312 $ minicpan -c CPAN::Mini::Devel::Recent
313  
314 =head1 DESCRIPTION
315  
316 CPAN::Mini::Devel::Recent is similar to L<CPAN::Mini::Devel>, except it
317 uses the new, experimental C<<< RECENT-* >>> index files on CPAN, which are updated
318 more frequently than the C<<< indices/find-ls.gz >>> file that CPAN::Mini::Devel uses.
319  
320 Normally, L<CPAN::Mini> creates a minimal CPAN mirror with the latest version of
321 each distribution, but excluding developer releases (those with an underscore
322 in the version number, like 0.10_01).
323  
324 CPAN::Mini::Devel::Recent enhances CPAN::Mini to include the latest developer and
325 non-developer release in the mirror. For example, if Foo-Bar-0.01,
326 Foo-Bar-0.02, Foo-Bar-0.03_01 and Foo-Bar-0.03_02 are on CPAN, only
327 Foo-Bar-0.02 and Foo-Bar 0.03_02 will be mirrored. This is particularly useful
328 for creating a local mirror for smoke testing.
329  
330 Unauthorized releases will also be included if they resemble a distribution
331 name already in the normal CPAN packages list.
332  
333 There may be errors retrieving very new modules if they are indexed but not
334 yet synchronized on the mirror.
335  
336 =for Pod::Coverage DEBUG
337  
338 =head1 USAGE
339  
340 See L<CPAN::Mini>.
341  
342 =head1 BUGS
343  
344 Please report any bugs or feature using the CPAN Request Tracker.
345 Bugs can be submitted through the web interface at
346 L<http://rt.cpan.org/Dist/Display.html?Queue=CPAN-Mini-Devel-Recent>
347  
348 When submitting a bug or request, please include a test-file or a patch to an
349 existing test-file that illustrates the bug or desired feature.
350  
351 =head1 SEE ALSO
352  
353 =over
354  
355 =item *
356  
357 L<CPAN::Mini>
358  
359 =item *
360  
361 L<CPAN::Mini::Devel>
362  
363 =back
364  
365 =head1 AUTHOR
366  
367 David Golden <dagolden@cpan.org>
368  
369 =head1 COPYRIGHT AND LICENSE
370  
371 This software is Copyright (c) 2011 by David Golden.
372  
373 This is free software, licensed under:
374  
375 The Apache License, Version 2.0, January 2004
376  
377 =cut
378  
379  
380 __END__
↑ Summary