| 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
| |||||||||||
| 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
| |||||||||||
| 55 | |||||||||||
| 56 | 796 | ▶ | if ($inheader) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 9 | ▶ | $inheader = 0 if not m/ \S /x; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||