| 1 | # ABSTRACT: Find a package/distribution target among CPAN-like repositories | ||||||||||
| 2 | |||||||||||
| 3 | package Pinto::Locator::Multiplex; | ||||||||||
| 4 | |||||||||||
| 5 | 58 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 58 | ▶ | use MooseX::Types::Moose qw(ArrayRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 58 | ▶ | use MooseX::MarkAsMethods (autoclean => 1); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 58 | ▶ | use Pinto::Locator::Mirror; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 58 | ▶ | use Pinto::Locator::Stratopan; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 58 | ▶ | use Pinto::Constants qw(:stratopan); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | #------------------------------------------------------------------------------ | ||||||||||
| 14 | |||||||||||
| 15 | 58 | our $VERSION = '0.14'; # VERSION | |||||||||
| 16 | |||||||||||
| 17 | #----------------------------------------------------------------------------- | ||||||||||
| 18 | |||||||||||
| 19 | 58 | extends qw(Pinto::Locator); | |||||||||
| 20 | |||||||||||
| 21 | #------------------------------------------------------------------------------ | ||||||||||
| 22 | |||||||||||
| 23 | has locators => ( | ||||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | isa => ArrayRef['Pinto::Locator'], | ||||||||||
| 26 | writer => '_set_locators', | ||||||||||
| 27 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 28 | 58 | lazy => 1, | |||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | #------------------------------------------------------------------------------ | ||||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | sub assemble { | ||||||||
|
Subroutine
assemble: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 34 | 1 | my ($self, @uris) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 1 | my @locators; | |||||||||
| 37 | 1 | for my $uri (@uris) { | |||||||||
| 38 | 1 | my $class = $self->locator_class_for_uri($uri); | |||||||||
| 39 | # Ick: This assumes all Locators have same attribute interface | ||||||||||
| 40 | 1 | my %args = ( uri => $uri, cache_dir => $self->cache_dir ); | |||||||||
| 41 | 1 | push @locators, $class->new( %args ); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 1 | $self->_set_locators(\@locators); | |||||||||
| 45 | 1 | return $self; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | #------------------------------------------------------------------------------ | ||||||||||
| 49 | |||||||||||
| 50 | 5 | ▶ | sub locate_package { | ||||||||
|
Subroutine
locate_package: called CC=5 SCAR=21.6
Pod
undocumented
| |||||||||||
| 51 | 5 | my ($self, %args) = @_; | |||||||||
| 52 | |||||||||||
| 53 | 5 | my @all_found; | |||||||||
| 54 | 5 | for my $locator ( @{ $self->locators } ) { | |||||||||
| 55 | 5 | ▶ | next unless my $found = $locator->locate_package(%args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | push @all_found, $found; | |||||||||
| 57 | 0 | ▶ | last unless $args{cascade}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 5 | ▶ | return if not @all_found; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | @all_found = reverse sort {$a->{version} <=> $b->{version}} @all_found; | |||||||||
| 62 | 0 | return $all_found[0]; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | #------------------------------------------------------------------------------ | ||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | sub locate_distribution { | ||||||||
|
Subroutine
locate_distribution: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 68 | 0 | my ($self, %args) = @_; | |||||||||
| 69 | |||||||||||
| 70 | 0 | for my $locator ( @{ $self->locators } ) { | |||||||||
| 71 | 0 | ▶ | next unless my $found = $locator->locate_distribution(%args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | return $found; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 0 | return; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | #------------------------------------------------------------------------------ | ||||||||||
| 79 | |||||||||||
| 80 | 1 | ▶ | sub locator_class_for_uri { | ||||||||
|
Subroutine
locator_class_for_uri: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 81 | 1 | my ($self, $uri) = @_; | |||||||||
| 82 | |||||||||||
| 83 | 1 | my $baseclass = 'Pinto::Locator'; | |||||||||
| 84 | 1 | ▶ | my $subclass = $uri eq $PINTO_STRATOPAN_CPAN_URI ? 'Stratopan' : 'Mirror'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | |||||||||||
| 86 | 1 | return $baseclass . '::' . $subclass; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | #------------------------------------------------------------------------------ | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub refresh { | ||||||||
|
Subroutine
refresh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 93 | 0 | my ($self) = @_; | |||||||||
| 94 | |||||||||||
| 95 | 0 | $_->refresh for @{ $self->locators }; | |||||||||
| 96 | |||||||||||
| 97 | 0 | return $self; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | #------------------------------------------------------------------------------ | ||||||||||
| 101 | |||||||||||
| 102 | 58 | __PACKAGE__->meta->make_immutable; | |||||||||
| 103 | |||||||||||
| 104 | #------------------------------------------------------------------------------ | ||||||||||
| 105 | |||||||||||
| 106 | 58 | 1; | |||||||||
| 107 | |||||||||||
| 108 | __END__ | ||||||||||