| 1 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Footprintless::ResourceManager; | ||||||||||
| 5 | 4 | $Footprintless::ResourceManager::VERSION = '1.29'; | |||||||||
| 6 | # ABSTRACT: A manager for finding and retrieving resources | ||||||||||
| 7 | # PODNAME: Footprintless::ResourceManager | ||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | use parent qw(Footprintless::MixableBase); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 4 | ▶ | use Footprintless::Mixins qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | _entity | ||||||||||
| 14 | 4 | ); | |||||||||
| 15 | 4 | ▶ | use Footprintless::Resource::Maven; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 4 | ▶ | use Footprintless::Resource::Url; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 4 | ▶ | use Footprintless::Util qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | dynamic_module_new | ||||||||||
| 19 | 4 | ); | |||||||||
| 20 | |||||||||||
| 21 | 20 | ▶ | sub download { | ||||||||
|
Subroutine
download: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 22 | 20 | my ( $self, $resource, @options ) = @_; | |||||||||
| 23 | |||||||||||
| 24 | 20 | foreach my $provider ( @{ $self->{providers} } ) { | |||||||||
| 25 | 38 | ▶ | if ( $provider->supports($resource) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 20 | return $provider->download( $resource, @options ); | |||||||||
| 27 | } | ||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | croak("unsupported resource type [$resource]"); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 15 | ▶ | sub _init { | ||||||||
|
Subroutine
_init: called CC=3 SCAR=11.0
| |||||||||||
| 34 | 15 | my ( $self, @options ) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 15 | $self->{providers} = (); | |||||||||
| 37 | 15 | my $providers = $self->_entity('footprintless.resource_manager.providers'); | |||||||||
| 38 | 15 | ▶ | if ($providers) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 5 | foreach my $provider_module (@$providers) { | |||||||||
| 40 | push( | ||||||||||
| 41 | 6 | @{ $self->{providers} }, | |||||||||
| 42 | dynamic_module_new( | ||||||||||
| 43 | $provider_module, $self->{factory}, $self->{coordinate}, @options | ||||||||||
| 44 | 6 | ) | |||||||||
| 45 | ); | ||||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | else { | ||||||||||
| 49 | 10 | eval { | |||||||||
| 50 | # Maven::Agent may not be available... | ||||||||||
| 51 | push( | ||||||||||
| 52 | 10 | @{ $self->{providers} }, | |||||||||
| 53 | dynamic_module_new( | ||||||||||
| 54 | 'Footprintless::Resource::MavenProvider', | ||||||||||
| 55 | $self->{factory}, $self->{coordinate}, @options | ||||||||||
| 56 | 10 | ) | |||||||||
| 57 | ); | ||||||||||
| 58 | }; | ||||||||||
| 59 | |||||||||||
| 60 | push( | ||||||||||
| 61 | 10 | @{ $self->{providers} }, | |||||||||
| 62 | dynamic_module_new( | ||||||||||
| 63 | 'Footprintless::Resource::UrlProvider', $self->{factory}, | ||||||||||
| 64 | $self->{coordinate}, @options | ||||||||||
| 65 | 10 | ) | |||||||||
| 66 | ); | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 13 | return $self; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 7 | ▶ | sub resource { | ||||||||
|
Subroutine
resource: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 73 | 7 | my ( $self, $spec ) = @_; | |||||||||
| 74 | |||||||||||
| 75 | 7 | foreach my $provider ( @{ $self->{providers} } ) { | |||||||||
| 76 | 10 | ▶ | if ( $provider->supports($spec) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 7 | return $provider->resource($spec); | |||||||||
| 78 | } | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | croak("unsupported resource: $spec"); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 4 | 1; | |||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||