File Coverage

blib/lib/CPAN/MirrorMerger/Index/Merged.pm
Criterion Covered Total %
statement 28 37 75.6
branch 3 8 37.5
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 36 51 70.5


line stmt bran cond sub pod time code
1             package CPAN::MirrorMerger::Index::Merged;
2 2     2   13 use strict;
  2         4  
  2         81  
3 2     2   10 use warnings;
  2         3  
  2         49  
4              
5 2     2   27 use parent qw/CPAN::MirrorMerger::Index/;
  2         3  
  2         30  
6              
7             use Class::Accessor::Lite
8 2     2   129 ro => [qw/multiplex_index mirrors mirror_cache logger/];
  2         3  
  2         11  
9              
10             sub save_with_included_packages {
11 1     1 0 33 my ($self, $storage) = @_;
12              
13 1         2 for my $mirror (@{ $self->mirrors }) {
  1         3  
14 3         767 my $index = $self->mirror_cache->get_or_fetch_index($mirror);
15              
16 3         19 my $previous_package_path = '';
17 3         5 for my $package_info (@{ $index->packages }) {
  3         7  
18             # skip contiguous packages for performance
19 3 50       19 next if $previous_package_path eq $package_info->canonicalized_path();
20 3         7 $previous_package_path = $package_info->canonicalized_path();
21              
22             # skip exists packages for performance
23 3         5 my $save_key = $mirror->package_path($package_info->canonicalized_path);
24 3 50       8 next if $storage->exists($save_key);
25              
26 3         75 my $package_path = eval {
27 3         10 $self->mirror_cache->get_or_fetch_package($mirror, $package_info);
28             };
29 3 50       11 if (my $e = $@) {
30 0 0       0 if (CPAN::MirrorMerger::Agent::Exception::NotFound->caught($e)) {
31 0         0 $self->logger->warn("skip package @{[ $package_info->path ]} on @{[ $mirror->name ]}");
  0         0  
  0         0  
32 0         0 next; # skip it
33             }
34 0         0 $self->logger->error("failed to fetch package @{[ $package_info->path ]} on @{[ $mirror->name ]}");
  0         0  
  0         0  
35 0         0 die $e;
36             }
37              
38 3         11 $storage->copy($package_path, $save_key);
39             }
40             }
41 1         373 $self->save($storage);
42             }
43              
44             1;
45             __END__