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