blib/lib/Pinto/IndexReader.pm

filter: Statementstmt 100% 40 / 40 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 98.2% 55 / 56 CC 5 SCAR 7.7
CC
5
Cov
98%
__read_index
4.0
_build_packages
2.0
BEGIN
1.0
CRAP 2.2
« blib/lib/Pinto/Action/Log.pm ↑ Summary blib/lib/Pinto/Chrome.pm »
1 # ABSTRACT: The package index of a repository
2  
3 package Pinto::IndexReader;
4  
5 60 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 60 ▶use MooseX::Types::Moose qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 60 ▶use MooseX::MarkAsMethods (autoclean => 1);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 60 ▶use IO::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 60 ▶use Pinto::Types qw(File);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 60 ▶use Pinto::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #------------------------------------------------------------------------
15  
16 60 our $VERSION = '0.14'; # VERSION
17  
18 #------------------------------------------------------------------------
19  
20 60 has index_file => (
21 is => 'ro',
22 isa => File,
23 required => 1,
24 );
25  
26 60 has packages => (
27 is => 'ro',
28 isa => HashRef,
29 builder => '_build_packages',
30 lazy => 1,
31 );
32  
33 #------------------------------------------------------------------------------
34  
35 1 ▶sub _build_packages {
Subroutine _build_packages: called CC=2 SCAR=7.0
36 1 my ($self) = @_;
37  
38 1 my $file = $self->index_file->stringify;
39 1 ▶ my $fh = IO::Zlib->new($file, 'rb') or throw "Failed to open index file $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::Zlib"->new($file, "rb") or throw("Failed to open index file ${file}: $!") 1 0 1
40 1 my $index_data = $self->__read_index($fh);
41 1 close $fh;
42  
43 1 return $index_data;
44 }
45  
46 #------------------------------------------------------------------------------
47  
48 1 ▶sub __read_index {
Subroutine __read_index: called CC=4 SCAR=13.9
49 1 my ($self, $fh) = @_;
50  
51 1 my $inheader = 1;
52 1 my $packages = {};
53  
54 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 796 1 797
55  
56 796 ▶ if ($inheader) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inheader) 9 787 796
57 9 ▶ $inheader = 0 if not m/ \S /x;
Branch: 1 branch
BranchTrueFalseTotal
unless / \S /x 1 8 9
58 9 next;
59 }
60  
61 787 chomp;
62 787 my ($package, $version, $path) = split;
63 787 $packages->{$package} = {name => $package, version => $version, path => $path};
64 }
65  
66 1 return $packages
67 }
68  
69 #------------------------------------------------------------------------
70  
71 60 __PACKAGE__->meta->make_immutable;
72  
73 #------------------------------------------------------------------------
74 60 1;
75  
76 __END__
« blib/lib/Pinto/Action/Log.pm ↑ Summary blib/lib/Pinto/Chrome.pm »