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