blib/lib/Pinto/Locator/Mirror.pm

filter: Statementstmt 65.3% 51 / 78 Branchbran 10.0% 1 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.6% 13 / 15 Podpod 0.0% 0 / 3 totaltotal 61.3% 65 / 106 CC 7 SCAR 19.2
CC
7
Cov
59%
locate_distribution
20.0
locate_package
12.2
refresh
2.0
CRAP 6.8
« blib/lib/Pinto/Action/Unpin.pm ↑ Summary blib/lib/Pinto/Chrome/Net.pm »
1 # ABSTRACT: The package index of a repository
2  
3 package Pinto::Locator::Mirror;
4  
5 59 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 59 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 59 ▶use MooseX::Types::Moose qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 59 ▶use MooseX::MarkAsMethods (autoclean => 1);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 59 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 59 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 59 ▶use Pinto::Types qw(Uri File);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 59 ▶use Pinto::Util qw(throw debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 59 ▶use Pinto::IndexReader;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 59 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #------------------------------------------------------------------------
20  
21 59 our $VERSION = '0.14'; # VERSION
22  
23 #------------------------------------------------------------------------
24  
25 59 extends qw(Pinto::Locator);
26  
27 #------------------------------------------------------------------------
28  
29 59 with qw(Pinto::Role::UserAgent);
30  
31 #------------------------------------------------------------------------
32  
33 59 has index_file => (
34 is => 'ro',
35 isa => File,
36 builder => '_build_index_file',
37 clearer => '_clear_index_file',
38 lazy => 1,
39 );
40  
41 has reader => (
42 is => 'ro',
43 isa => 'Pinto::IndexReader',
44 1 ▶ default => sub { Pinto::IndexReader->new(index_file => $_[0]->index_file)},
Subroutine __ANON__: called CC=1 SCAR=0.0
45 59 clearer => '_clear_reader',
46 lazy => 1,
47 );
48  
49 #------------------------------------------------------------------------------
50  
51 1 ▶sub _build_index_file {
Subroutine _build_index_file: called CC=1 SCAR=0.0
52 1 my ($self) = @_;
53  
54 1 my $uri = $self->uri->canonical->as_string;
55 1 $uri =~ s{ /*$ }{}mx; # Remove trailing slash
56 1 $uri = URI->new($uri); # Reconstitute as URI object (why?)
57  
58 1 my $details_filename = '02packages.details.txt.gz';
59 1 my $cache_dir = $self->cache_dir->subdir( URI::Escape::uri_escape($uri) );
60 1 my $destination = $cache_dir->file($details_filename);
61 1 my $source = URI->new( "$uri/modules/$details_filename" );
62  
63 1 $self->mirror($source => $destination);
64  
65 1 return $destination;
66 }
67  
68 #------------------------------------------------------------------------
69  
70 5 ▶sub locate_package {
Subroutine locate_package: called CC=4 SCAR=25.0
Pod undocumented
71 5 my ($self, %args) = @_;
72  
73 5 my $target = $args{target};
74  
75 5 ▶ return unless my $found = $self->reader->packages->{$target->name};
Branch: 1 branch
BranchTrueFalseTotal
unless my $found = $self->reader->packages->{$target->name} 5 0 5
76 0 ▶ return unless $target->is_satisfied_by( $found->{version} );
Branch: 1 branch
BranchTrueFalseTotal
unless $target->is_satisfied_by($found->{"version"}) 0 0 0
77  
78 # Indexes from a Pinto repository have fake records for core modules, so
79 # installers can decide if they need to update a dual-life module. If we
80 # get one of those fake records, then we pretend we didn't see it. So if
81 # we really do need a perl, some other upstream source will provide it.
82  
83 0 ▶ if ( $found->{path} =~ m{^F/FA/FAKE/perl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found->{"path"} =~ m[^F/FA/FAKE/perl]) 0 0 0
84 0 my ($uri, $path) = ($self->uri, $found->{path});
85 0 debug "Skipping fake perl found on $uri at $path";
86 0 return;
87 }
88  
89 0 $found = { %$found }; # Shallow clone
90 0 $found->{package} = delete $found->{name};
91 0 $found->{uri} = URI->new($self->uri . "/authors/id/$found->{path}");
92 0 $found->{version} = version->parse($found->{version});
93 0 delete $found->{path};
94  
95 0 return $found;
96 }
97  
98 #------------------------------------------------------------------------
99  
100 0 ▶sub locate_distribution {
Subroutine locate_distribution: not called CC=4 SCAR=30.0
Pod undocumented
101 0 my ($self, %args) = @_;
102  
103 0 my $target = $args{target};
104 0 my $path = $target->path;
105  
106 0 my @extensions = qw(tar.gz tar.bz2 tar gz tgz bz2 zip z);
107 0 my $has_extension = $path =~ m/[.](?:tar|gz|tgz|zip|z|bz2)$/i;
108 0 ▶ my @paths_to_try = $has_extension ? ($path) : map { "$path.$_" } @extensions;
Branch: 1 branch
BranchTrueFalseTotal
$has_extension ? : 0 0 0
109  
110 0 for my $path (@paths_to_try) {
111 0 my $uri = URI->new($self->uri . '/authors/id/' . $path);
112 0 ▶ return {uri => $uri} if $self->head($uri)->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $self->head($uri)->is_success 0 0 0
113 }
114  
115 0 return;
116 }
117  
118 #------------------------------------------------------------------------
119  
120 0 ▶sub refresh {
Subroutine refresh: not called CC=1 SCAR=6.9
Pod undocumented
121 0 my ($self) = @_;
122  
123 0 $self->index_file->remove;
124 0 $self->_clear_index_file;
125 0 $self->_clear_reader;
126  
127 0 return $self;
128 }
129 #------------------------------------------------------------------------
130  
131 59 __PACKAGE__->meta->make_immutable;
132  
133 #------------------------------------------------------------------------
134 59 1;
135  
136 __END__
« blib/lib/Pinto/Action/Unpin.pm ↑ Summary blib/lib/Pinto/Chrome/Net.pm »