File Coverage

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


line stmt bran cond sub pod time code
1             package Acme::CPANAuthors::Utils::CPANIndex;
2              
3 4     4   140571 use strict;
  4         9  
  4         182  
4 4     4   23 use warnings;
  4         11  
  4         202  
5 4     4   57 use Carp;
  4         22  
  4         1222  
6              
7             sub new {
8 7     7 1 7016 my $class = shift;
9 7         33 my $self = bless { preambles => {} }, $class;
10              
11 7         40 $self->_install_methods;
12 7         21 $self->{$_} = {} for keys %{ $self->_mappings };
  7         23  
13              
14 7 50       52 $self->_parse(@_) if @_;
15              
16 5         615 $self;
17             }
18              
19 0     0   0 sub _mappings {+{}}
20       5     sub _preambles {}
21              
22             sub _install_methods {
23 7     7   17 my $self = shift;
24 7         19 my $class = ref $self;
25              
26 4     4   30 no strict 'refs';
  4         6  
  4         186  
27 4     4   23 no warnings 'redefine';
  4         18  
  4         2287  
28 7         34 for my $method ($self->_preambles) {
29 16         113 *{"$class\::$method"} = sub {
30 8     8   1604 my $self = shift;
31 8         72 $self->{preambles}{$method};
32             }
33 16         59 }
34              
35 7         20 for my $method (keys %{ $self->_mappings }) {
  7         30  
36 11         33 my $key = $self->_mappings->{$method};
37 11         107 *{"$class\::$method"} = sub {
38 13     13   31912 my ($self, $name) = @_;
39 13         252 $self->{$key}{$name};
40 11         97 };
41 11         62 *{"$class\::${method}s"} = sub {
42 5     5   16439 my $self = shift;
43 5         11 values %{ $self->{$key} };
  5         33  
44 11         44 };
45 11         75 *{"$class\::${method}_count"} = sub {
46 3     3   2522 my $self = shift;
47 3         8 scalar values %{ $self->{$key} };
  3         21  
48 11         55 };
49             }
50             }
51              
52             sub _handle {
53 7     7   22 my ($self, $file) = @_;
54              
55 7         14 my $handle;
56 7 100       59 if ($file =~ /\.gz$/) {
57 4         2512 require IO::Uncompress::Gunzip;
58 4 100       165905 $handle = IO::Uncompress::Gunzip->new($file) or croak "Failed to read $file";
59             }
60             else {
61 3         1335 require IO::File;
62 3 100       25123 $handle = IO::File->new($file, 'r') or croak "Failed to read $file";
63 2         372 binmode $handle;
64             }
65 5         9661 $handle;
66             }
67              
68             1;
69              
70             __END__