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   12 use strict;
  2         3  
  2         49  
3 2     2   28 use warnings;
  2         4  
  2         56  
4              
5 2     2   9 use parent qw/CPAN::MirrorMerger::Index/;
  2         4  
  2         16  
6              
7             use Class::Accessor::Lite
8 2     2   119 ro => [qw/multiplex_index mirrors mirror_cache logger/];
  2         11  
  2         13  
9              
10             sub save_with_included_packages {
11 1     1 0 31 my ($self, $storage) = @_;
12              
13 1         2 for my $mirror (@{ $self->mirrors }) {
  1         5  
14 3         749 my $index = $self->mirror_cache->get_or_fetch_index($mirror);
15              
16 3         16 my $previous_package_path = '';
17 3         4 for my $package_info (@{ $index->packages }) {
  3         7  
18             # skip contiguous packages for performance
19 3 50       17 next if $previous_package_path eq $package_info->canonicalized_path();
20 3         8 $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       9 next if $storage->exists($save_key);
25              
26 3         70 my $package_path = eval {
27 3         10 $self->mirror_cache->get_or_fetch_package($mirror, $package_info);
28             };
29 3 50       19 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         12 $storage->copy($package_path, $save_key);
39             }
40             }
41 1         382 $self->save($storage);
42             }
43              
44             1;
45             __END__