File Coverage

blib/lib/BackPAN/Index/Create/OrderBy/Dist.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 4 4 100.0
pod 0 2 0.0
total 31 35 88.5


line stmt bran cond sub pod time code
1             package BackPAN::Index::Create::OrderBy::Dist;
2             $BackPAN::Index::Create::OrderBy::Dist::VERSION = '0.13';
3 2     2   5172 use Moo;
  2         17377  
  2         13  
4 2     2   2985 use CPAN::DistnameInfo;
  2         1480  
  2         413  
5              
6             has filehandle => (is => 'ro');
7             has entries => (is => 'ro', default => sub { return {} });
8              
9             sub add_file
10             {
11 8     8 0 10 my $self = shift;
12 8         8 my ($path, $time, $size) = @_;
13 8         23 my $distinfo = CPAN::DistnameInfo->new($path);
14 8         318 my $entries = $self->entries;
15 8         8 my $distname;
16              
17 8 100 33     27 if (!defined($distinfo) || !defined($distname = $distinfo->dist)) {
18 4         15 $distname = '';
19             }
20 8         23 push(@{ $entries->{$distname} }, [$path,$time,$size] );
  8         56  
21             }
22              
23             sub finish
24             {
25 2     2 0 24 my $self = shift;
26 2         7 my $entries = $self->entries;
27 2         6 my $fh = $self->filehandle;
28              
29 2         9 foreach my $distname (sort { lc($a) cmp lc($b) } keys %$entries) {
  3         10  
30 5         5 foreach my $entry (sort { $a->[1] <=> $b->[1] }
  4         6  
  5         9  
31             @{ $entries->{$distname} }) {
32 8         35 printf $fh "%s %d %d\n", @$entry;
33             }
34             }
35             }
36              
37             1;