File Coverage

blib/lib/Pinto/Locator/Multiplex.pm
Criterion Covered Total %
statement 51 51 100.0
branch 10 10 100.0
condition n/a
subroutine 11 11 100.0
pod 0 5 0.0
total 72 77 93.5


line stmt bran cond sub pod time code
1             # ABSTRACT: Find a package/distribution target among CPAN-like repositories
2              
3             package Pinto::Locator::Multiplex;
4              
5 51     51   787 use Moose;
  51         104  
  51         383  
6 51     51   322132 use MooseX::Types::Moose qw(ArrayRef);
  51         56887  
  51         599  
7 51     51   233111 use MooseX::MarkAsMethods (autoclean => 1);
  51         122  
  51         468  
8              
9 51     51   195975 use Pinto::Locator::Mirror;
  51         260  
  51         2260  
10 51     51   20959 use Pinto::Locator::Stratopan;
  51         203  
  51         2225  
11 51     51   422 use Pinto::Constants qw(:stratopan);
  51         107  
  51         3902  
12              
13             #------------------------------------------------------------------------------
14              
15             our $VERSION = '0.13'; # VERSION
16              
17             #-----------------------------------------------------------------------------
18              
19             extends qw(Pinto::Locator);
20              
21             #------------------------------------------------------------------------------
22              
23             has locators => (
24             is => 'ro',
25             isa => ArrayRef['Pinto::Locator'],
26             writer => '_set_locators',
27             default => sub { [] },
28             lazy => 1,
29             );
30              
31             #------------------------------------------------------------------------------
32              
33             sub assemble {
34 37     37 0 2608 my ($self, @uris) = @_;
35              
36 37         102 my @locators;
37 37         142 for my $uri (@uris) {
38 49         288 my $class = $self->locator_class_for_uri($uri);
39             # Ick: This assumes all Locators have same attribute interface
40 49         1761 my %args = ( uri => $uri, cache_dir => $self->cache_dir );
41 49         1677 push @locators, $class->new( %args );
42             }
43              
44 37         1487 $self->_set_locators(\@locators);
45 37         921 return $self;
46             }
47              
48             #------------------------------------------------------------------------------
49              
50             sub locate_package {
51 68     68 0 339 my ($self, %args) = @_;
52              
53 68         185 my @all_found;
54 68         165 for my $locator ( @{ $self->locators } ) {
  68         2102  
55 76 100       772 next unless my $found = $locator->locate_package(%args);
56 55         219 push @all_found, $found;
57 55 100       293 last unless $args{cascade};
58             }
59              
60 68 100       995 return if not @all_found;
61 53         294 @all_found = reverse sort {$a->{version} <=> $b->{version}} @all_found;
  2         24  
62 53         523 return $all_found[0];
63             }
64              
65             #------------------------------------------------------------------------------
66              
67             sub locate_distribution {
68 6     6 0 25 my ($self, %args) = @_;
69              
70 6         17 for my $locator ( @{ $self->locators } ) {
  6         189  
71 8 100       47 next unless my $found = $locator->locate_distribution(%args);
72 5         7318 return $found;
73             }
74              
75 1         17 return;
76             }
77              
78             #------------------------------------------------------------------------------
79              
80             sub locator_class_for_uri {
81 49     49 0 133 my ($self, $uri) = @_;
82              
83 49         154 my $baseclass = 'Pinto::Locator';
84 49 100       386 my $subclass = $uri eq $PINTO_STRATOPAN_CPAN_URI ? 'Stratopan' : 'Mirror';
85              
86 49         3797 return $baseclass . '::' . $subclass;
87             }
88              
89             #------------------------------------------------------------------------------
90              
91              
92             sub refresh {
93 2     2 0 11 my ($self) = @_;
94              
95 2         7 $_->refresh for @{ $self->locators };
  2         83  
96              
97 2         12 return $self;
98             }
99              
100             #------------------------------------------------------------------------------
101              
102             __PACKAGE__->meta->make_immutable;
103              
104             #------------------------------------------------------------------------------
105              
106             1;
107              
108             __END__
109              
110             =pod
111              
112             =encoding UTF-8
113              
114             =for :stopwords Jeffrey Ryan Thalhammer
115              
116             =head1 NAME
117              
118             Pinto::Locator::Multiplex - Find a package/distribution target among CPAN-like repositories
119              
120             =head1 VERSION
121              
122             version 0.13
123              
124             =head1 AUTHOR
125              
126             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
127              
128             =head1 COPYRIGHT AND LICENSE
129              
130             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
131              
132             This is free software; you can redistribute it and/or modify it under
133             the same terms as the Perl 5 programming language system itself.
134              
135             =cut