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   46 use strict;
  4         8  
  4         145  
4 4     4   23 use warnings;
  4         8  
  4         128  
5 4     4   24 use Carp;
  4         11  
  4         1089  
6              
7             sub new {
8 7     7 1 4188 my $class = shift;
9 7         31 my $self = bless { preambles => {} }, $class;
10              
11 7         69 $self->_install_methods;
12 7         17 $self->{$_} = {} for keys %{ $self->_mappings };
  7         24  
13              
14 7 50       51 $self->_parse(@_) if @_;
15              
16 5         505 $self;
17             }
18              
19 0     0   0 sub _mappings {+{}}
20       5     sub _preambles {}
21              
22             sub _install_methods {
23 7     7   13 my $self = shift;
24 7         22 my $class = ref $self;
25              
26 4     4   40 no strict 'refs';
  4         10  
  4         195  
27 4     4   29 no warnings 'redefine';
  4         9  
  4         2321  
28 7         30 for my $method ($self->_preambles) {
29 16         110 *{"$class\::$method"} = sub {
30 8     8   781 my $self = shift;
31 8         45 $self->{preambles}{$method};
32             }
33 16         40 }
34              
35 7         14 for my $method (keys %{ $self->_mappings }) {
  7         30  
36 11         37 my $key = $self->_mappings->{$method};
37 11         71 *{"$class\::$method"} = sub {
38 13     13   13358 my ($self, $name) = @_;
39 13         72 $self->{$key}{$name};
40 11         52 };
41 11         54 *{"$class\::${method}s"} = sub {
42 5     5   6516 my $self = shift;
43 5         11 values %{ $self->{$key} };
  5         34  
44 11         35 };
45 11         66 *{"$class\::${method}_count"} = sub {
46 3     3   673 my $self = shift;
47 3         5 scalar values %{ $self->{$key} };
  3         17  
48 11         43 };
49             }
50             }
51              
52             sub _handle {
53 7     7   28 my ($self, $file) = @_;
54              
55 7         15 my $handle;
56 7 100       34 if ($file =~ /\.gz$/) {
57 4         6626 require IO::Uncompress::Gunzip;
58 4 100       210040 $handle = IO::Uncompress::Gunzip->new($file) or croak "Failed to read $file";
59             }
60             else {
61 3         1786 require IO::File;
62 3 100       22316 $handle = IO::File->new($file, 'r') or croak "Failed to read $file";
63 2         252 binmode $handle;
64             }
65 5         7156 $handle;
66             }
67              
68             1;
69              
70             __END__