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.12';
3 2     2   3561 use Moo;
  2         40299  
  2         62  
4 2     2   5720 use CPAN::DistnameInfo;
  2         2342  
  2         650  
5              
6             has filehandle => (is => 'ro');
7             has entries => (is => 'ro', default => sub { return {} });
8              
9             sub add_file
10             {
11 8     8 0 12 my $self = shift;
12 8         23 my ($path, $time, $size) = @_;
13 8         33 my $distinfo = CPAN::DistnameInfo->new($path);
14 8         458 my $entries = $self->entries;
15 8         10 my $distname;
16              
17 8 100 33     51 if (!defined($distinfo) || !defined($distname = $distinfo->dist)) {
18 4         31 $distname = '';
19             }
20 8         38 push(@{ $entries->{$distname} }, [$path,$time,$size] );
  8         90  
21             }
22              
23             sub finish
24             {
25 2     2 0 5 my $self = shift;
26 2         7 my $entries = $self->entries;
27 2         8 my $fh = $self->filehandle;
28              
29 2         12 foreach my $distname (sort { lc($a) cmp lc($b) } keys %$entries) {
  3         10  
30 5         8 foreach my $entry (sort { $a->[1] <=> $b->[1] }
  4         7  
  5         11  
31             @{ $entries->{$distname} }) {
32 8         55 printf $fh "%s %d %d\n", @$entry;
33             }
34             }
35             }
36              
37             1;