blib/lib/Acme/CPANAuthors/Utils/CPANIndex.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 86 SCAR 24.8
CC
3
Cov
0%
new
6.0
_handle
6.0
_mappings
2.0
CRAP 12.0
1 package Acme::CPANAuthors::Utils::CPANIndex;
2  
3 use strict;
4 use warnings;
5 use Carp;
6  
7 sub new {
8 my $class = shift;
9 my $self = bless { preambles => {} }, $class;
10  
11 $self->_install_methods;
12 $self->{$_} = {} for keys %{ $self->_mappings };
13  
14 $self->_parse(@_) if @_;
15  
16 $self;
17 }
18  
19 sub _mappings {+{}}
20 sub _preambles {}
21  
22 sub _install_methods {
23 my $self = shift;
24 my $class = ref $self;
25  
26 no strict 'refs';
27 no warnings 'redefine';
28 for my $method ($self->_preambles) {
29 *{"$class\::$method"} = sub {
30 my $self = shift;
31 $self->{preambles}{$method};
32 }
33 }
34  
35 for my $method (keys %{ $self->_mappings }) {
36 my $key = $self->_mappings->{$method};
37 *{"$class\::$method"} = sub {
38 my ($self, $name) = @_;
39 $self->{$key}{$name};
40 };
41 *{"$class\::${method}s"} = sub {
42 my $self = shift;
43 values %{ $self->{$key} };
44 };
45 *{"$class\::${method}_count"} = sub {
46 my $self = shift;
47 scalar values %{ $self->{$key} };
48 };
49 }
50 }
51  
52 sub _handle {
53 my ($self, $file) = @_;
54  
55 my $handle;
56 if ($file =~ /\.gz$/) {
57 require IO::Uncompress::Gunzip;
58 $handle = IO::Uncompress::Gunzip->new($file) or croak "Failed to read $file";
59 }
60 else {
61 require IO::File;
62 $handle = IO::File->new($file, 'r') or croak "Failed to read $file";
63 binmode $handle;
64 }
65 $handle;
66 }
67  
68 1;
69  
70 __END__