File Coverage

blib/lib/CPAN/Mini/LatestDistVersion.pm
Criterion Covered Total %
statement 15 45 33.3
branch 0 14 0.0
condition 0 6 0.0
subroutine 5 10 50.0
pod 2 2 100.0
total 22 77 28.5


line stmt bran cond sub pod time code
1             package CPAN::Mini::LatestDistVersion;
2              
3 1     1   25185 use base 'CPAN::Mini';
  1         2  
  1         1015  
4              
5 1     1   1632948 use strict;
  1         3  
  1         41  
6 1     1   6 use warnings;
  1         11  
  1         35  
7              
8 1     1   1244 use Parse::CPAN::Packages::Fast;
  1         8539  
  1         35  
9 1     1   11 use CPAN::DistnameInfo;
  1         2  
  1         498  
10              
11             our $VERSION = '0.01';
12              
13             sub new {
14 0     0 1   my $class = shift;
15 0           my $self = $class->SUPER::new( @_ );
16              
17 0 0 0       if( !$self->{ path_filters } ) {
    0          
18 0           $self->{ path_filters } = [];
19             }
20             elsif( $self->{ path_filters } && ref( $self->{ path_filters } ) ne 'ARRAY') {
21 0           $self->{ path_filters } = [ $self->{ path_filters } ];
22             }
23              
24 0     0     push @{ $self->{ path_filters } }, sub { _filter_latest( $self, @_ ) };
  0            
  0            
25              
26 0           return $self;
27             }
28              
29             sub mirror_indices {
30 0     0 1   my $self = shift;
31 0           $self->SUPER::mirror_indices( @_ );
32              
33 0           my $packages = Parse::CPAN::Packages::Fast->new( $self->_scratch_dir . '/modules/02packages.details.txt.gz' );
34 0           $self->{ _latest_dists } = _get_latest_dists( $packages );
35             }
36              
37             sub _filter_latest {
38 0     0     my ( $self, $file ) = @_;
39 0           my $dist = CPAN::DistnameInfo->new( $file );
40              
41 0 0 0       return 1 if !$dist || !$dist->distvname; # Skip problem dists, if any
42 0 0         return 0 if $dist->distvname eq $self->{ _latest_dists }->{ $dist->dist }->distvname;
43 0           return 1;
44             }
45              
46             # Slightly modified from Parse::CPAN::Packages::Fast
47             sub _get_latest_dists {
48 0     0     my $self = shift;
49              
50 0           my %latest_dist;
51              
52 0           for my $pathname ( keys %{ $self->{ dist_to_pkgs } } ) {
  0            
53 0           my $d = Parse::CPAN::Packages::Fast::Distribution->new( $pathname, $self );
54 0           my $dist = $d->dist;
55 0 0         next if !defined $dist;
56 0 0         if ( !exists $latest_dist{ $dist } ) {
57 0           $latest_dist{ $dist } = $d;
58             }
59             else {
60 0 0         if ( CPAN::Version->vlt( $latest_dist{ $dist }->version, $d->version ) ) {
61 0           $latest_dist{ $dist } = $d;
62             }
63             }
64             }
65              
66 0           return \%latest_dist;
67             }
68              
69             1;
70              
71             __END__