File Coverage

blib/lib/Pinto/IndexReader.pm
Criterion Covered Total %
statement 35 35 100.0
branch 5 6 83.3
condition n/a
subroutine 8 8 100.0
pod n/a
total 48 49 97.9


line stmt bran cond sub pod time code
1             # ABSTRACT: The package index of a repository
2              
3             package Pinto::IndexReader;
4              
5 51     51   345 use Moose;
  51         110  
  51         422  
6 51     51   321617 use MooseX::Types::Moose qw(HashRef);
  51         130  
  51         530  
7 51     51   225583 use MooseX::MarkAsMethods (autoclean => 1);
  51         116  
  51         461  
8              
9 51     51   186526 use IO::Zlib;
  51         184743  
  51         322  
10              
11 51     51   2858 use Pinto::Types qw(File);
  51         130  
  51         525  
12 51     51   292128 use Pinto::Util qw(throw);
  51         130  
  51         17436  
13              
14             #------------------------------------------------------------------------
15              
16             our $VERSION = '0.13'; # VERSION
17              
18             #------------------------------------------------------------------------
19              
20             has index_file => (
21             is => 'ro',
22             isa => File,
23             required => 1,
24             );
25              
26             has packages => (
27             is => 'ro',
28             isa => HashRef,
29             builder => '_build_packages',
30             lazy => 1,
31             );
32              
33             #------------------------------------------------------------------------------
34              
35             sub _build_packages {
36 35     35   109 my ($self) = @_;
37              
38 35         1023 my $file = $self->index_file->stringify;
39 35 50       1655 my $fh = IO::Zlib->new($file, 'rb') or throw "Failed to open index file $file: $!";
40 35         78089 my $index_data = $self->__read_index($fh);
41 35         172 close $fh;
42              
43 35         8826 return $index_data;
44             }
45              
46             #------------------------------------------------------------------------------
47              
48             sub __read_index {
49 35     35   113 my ($self, $fh) = @_;
50              
51 35         76 my $inheader = 1;
52 35         80 my $packages = {};
53              
54 35         227 while (<$fh>) {
55              
56 23382 100       2381880 if ($inheader) {
57 315 100       1161 $inheader = 0 if not m/ \S /x;
58 315         805 next;
59             }
60              
61 23067         31905 chomp;
62 23067         60101 my ($package, $version, $path) = split;
63 23067         124104 $packages->{$package} = {name => $package, version => $version, path => $path};
64             }
65              
66 35         5283 return $packages
67             }
68              
69             #------------------------------------------------------------------------
70              
71             __PACKAGE__->meta->make_immutable;
72              
73             #------------------------------------------------------------------------
74             1;
75              
76             __END__
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =for :stopwords Jeffrey Ryan Thalhammer
83              
84             =head1 NAME
85              
86             Pinto::IndexReader - The package index of a repository
87              
88             =head1 VERSION
89              
90             version 0.13
91              
92             =head1 AUTHOR
93              
94             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =cut