File Coverage

lib/Acme/CPANAuthors/Utils/CPANIndex.pm
Criterion Covered Total %
statement 56 57 98.2
branch 7 8 87.5
condition n/a
subroutine 13 14 92.8
pod 1 1 100.0
total 77 80 96.2


line stmt bran cond sub pod time code
1             package Acme::CPANAuthors::Utils::CPANIndex;
2              
3 3     3   15 use strict;
  3         4  
  3         87  
4 3     3   11 use warnings;
  3         4  
  3         59  
5 3     3   9 use Carp;
  3         4  
  3         658  
6              
7             sub new {
8 6     6 1 2371 my $class = shift;
9 6         24 my $self = bless { preambles => {} }, $class;
10              
11 6         22 $self->_install_methods;
12 6         12 $self->{$_} = {} for keys %{ $self->_mappings };
  6         16  
13              
14 6 50       33 $self->_parse(@_) if @_;
15              
16 4         290 $self;
17             }
18              
19 0     0   0 sub _mappings {+{}}
20 4     4   12 sub _preambles {}
21              
22             sub _install_methods {
23 6     6   439 my $self = shift;
24 6         12 my $class = ref $self;
25              
26 3     3   14 no strict 'refs';
  3         3  
  3         73  
27 3     3   9 no warnings 'redefine';
  3         4  
  3         1474  
28 6         23 for my $method ($self->_preambles) {
29 16         76 *{"$class\::$method"} = sub {
30 8     8   622 my $self = shift;
31 8         48 $self->{preambles}{$method};
32             }
33 16         44 }
34              
35 6         10 for my $method (keys %{ $self->_mappings }) {
  6         19  
36 10         24 my $key = $self->_mappings->{$method};
37 10         51 *{"$class\::$method"} = sub {
38 12     12   8403 my ($self, $name) = @_;
39 12         51 $self->{$key}{$name};
40 10         55 };
41 10         41 *{"$class\::${method}s"} = sub {
42 5     5   3726 my $self = shift;
43 5         11 values %{ $self->{$key} };
  5         33  
44 10         25 };
45 10         54 *{"$class\::${method}_count"} = sub {
46 3     3   536 my $self = shift;
47 3         9 scalar values %{ $self->{$key} };
  3         17  
48 10         28 };
49             }
50             }
51              
52             sub _handle {
53 6     6   19 my ($self, $file) = @_;
54              
55 6         6 my $handle;
56 6 100       28 if ($file =~ /\.gz$/) {
57 3         1259 require IO::Uncompress::Gunzip;
58 3 100       58452 $handle = IO::Uncompress::Gunzip->new($file) or croak "Failed to read $file";
59             }
60             else {
61 3         942 require IO::File;
62 3 100       14454 $handle = IO::File->new($file, 'r') or croak "Failed to read $file";
63 2         178 binmode $handle;
64             }
65 4         3403 $handle;
66             }
67              
68             1;
69              
70             __END__