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   17 use strict;
  3         4  
  3         91  
4 3     3   10 use warnings;
  3         4  
  3         52  
5 3     3   9 use Carp;
  3         3  
  3         472  
6              
7             sub new {
8 6     6 1 2727 my $class = shift;
9 6         32 my $self = bless { preambles => {} }, $class;
10              
11 6         435 $self->_install_methods;
12 6         13 $self->{$_} = {} for keys %{ $self->_mappings };
  6         21  
13              
14 6 50       32 $self->_parse(@_) if @_;
15              
16 4         284 $self;
17             }
18              
19 0     0   0 sub _mappings {+{}}
20 4     4   10 sub _preambles {}
21              
22             sub _install_methods {
23 6     6   9 my $self = shift;
24 6         9 my $class = ref $self;
25              
26 3     3   16 no strict 'refs';
  3         2  
  3         68  
27 3     3   9 no warnings 'redefine';
  3         401  
  3         1171  
28 6         21 for my $method ($self->_preambles) {
29 16         70 *{"$class\::$method"} = sub {
30 8     8   476 my $self = shift;
31 8         34 $self->{preambles}{$method};
32             }
33 16         38 }
34              
35 6         8 for my $method (keys %{ $self->_mappings }) {
  6         22  
36 10         19 my $key = $self->_mappings->{$method};
37 10         45 *{"$class\::$method"} = sub {
38 12     12   8185 my ($self, $name) = @_;
39 12         49 $self->{$key}{$name};
40 10         38 };
41 10         36 *{"$class\::${method}s"} = sub {
42 5     5   4131 my $self = shift;
43 5         8 values %{ $self->{$key} };
  5         27  
44 10         25 };
45 10         49 *{"$class\::${method}_count"} = sub {
46 3     3   410 my $self = shift;
47 3         4 scalar values %{ $self->{$key} };
  3         15  
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       25 if ($file =~ /\.gz$/) {
57 3         14333 require IO::Uncompress::Gunzip;
58 3 100       112857 $handle = IO::Uncompress::Gunzip->new($file) or croak "Failed to read $file";
59             }
60             else {
61 3         1227 require IO::File;
62 3 100       14126 $handle = IO::File->new($file, 'r') or croak "Failed to read $file";
63 2         167 binmode $handle;
64             }
65 4         3549 $handle;
66             }
67              
68             1;
69              
70             __END__