File Coverage

blib/lib/BackPAN/Index/Create/OrderBy/Author.pm
Criterion Covered Total %
statement 22 24 91.6
branch 1 2 50.0
condition 1 3 33.3
subroutine 4 4 100.0
pod 0 2 0.0
total 28 35 80.0


line stmt bran cond sub pod time code
1             package BackPAN::Index::Create::OrderBy::Author;
2             $BackPAN::Index::Create::OrderBy::Author::VERSION = '0.12';
3 2     2   3464 use Moo;
  2         30950  
  2         68  
4 2     2   5709 use CPAN::DistnameInfo;
  2         2102  
  2         661  
5              
6             has filehandle => (is => 'ro');
7             has entries => (is => 'ro', default => sub { return {} });
8              
9             sub add_file
10             {
11 4     4 0 9 my $self = shift;
12 4         9 my ($path, $time, $size) = @_;
13 4         26 my $distinfo = CPAN::DistnameInfo->new($path);
14 4         341 my $entries = $self->entries;
15 4         7 my $author;
16              
17 4 50 33     59 if (!defined($distinfo) || !defined($author = $distinfo->cpanid)) {
18 0         0 $author = '';
19             }
20 4         33 push(@{ $entries->{$author} }, [$path,$time,$size] );
  4         56  
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         13 foreach my $author (sort { lc($a) cmp lc($b) } keys %$entries) {
  2         9  
30 4         8 foreach my $entry (sort { $a->[1] <=> $b->[1] }
  0         0  
  4         9  
31             @{ $entries->{$author} }) {
32 4         38 printf $fh "%s %d %d\n", @$entry;
33             }
34             }
35             }
36              
37             1;