line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
32799
|
use strict; |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
97
|
|
2
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
164
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Footprintless::Resource::UrlProvider; |
5
|
|
|
|
|
|
|
$Footprintless::Resource::UrlProvider::VERSION = '1.29'; |
6
|
|
|
|
|
|
|
# ABSTRACT: A resource provider for resources retrieved by URL |
7
|
|
|
|
|
|
|
# PODNAME: Footprintless::Resource::UrlProvider |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
17
|
use parent qw(Footprintless::Resource::Provider); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
18
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
177
|
use Carp; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
168
|
|
12
|
4
|
|
|
4
|
|
413
|
use Footprintless::Resource::Url; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
86
|
|
13
|
4
|
|
|
|
|
129
|
use Footprintless::Util qw( |
14
|
|
|
|
|
|
|
temp_file |
15
|
4
|
|
|
4
|
|
19
|
); |
|
4
|
|
|
|
|
8
|
|
16
|
4
|
|
|
4
|
|
19
|
use Log::Any; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
19
|
|
17
|
4
|
|
|
4
|
|
1708
|
use URI; |
|
4
|
|
|
|
|
15034
|
|
|
4
|
|
|
|
|
1180
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _download { |
22
|
19
|
|
|
19
|
|
75
|
my ( $self, $resource, %options ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
19
|
|
|
|
|
31
|
my $file; |
25
|
19
|
100
|
|
|
|
49
|
if ( $options{to} ) { |
26
|
12
|
|
|
|
|
21
|
$file = $options{to}; |
27
|
12
|
100
|
|
|
|
202
|
if ( -d $file ) { |
28
|
6
|
|
|
|
|
32
|
my @segments = $resource->get_uri()->path_segments(); |
29
|
6
|
|
|
|
|
564
|
$file = File::Spec->catfile( $file, $segments[$#segments] ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
7
|
|
|
|
|
14
|
my @suffix; |
34
|
7
|
50
|
|
|
|
40
|
if ( $resource->get_url() =~ /.*(\.\S*)$/ ) { |
35
|
7
|
|
|
|
|
182
|
$logger->tracef( 'preserving extension [%s] for resource %s', $1, $resource ); |
36
|
7
|
|
|
|
|
178
|
push( @suffix, suffix => $1 ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
47
|
$file = temp_file(@suffix); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
19
|
|
|
|
|
126
|
my $response = $self->{agent}->get( $resource->get_uri(), ':content_file' => "$file" ); |
43
|
19
|
50
|
|
|
|
126746
|
croak( 'download failed: ', $response->message() ) |
44
|
|
|
|
|
|
|
unless ( $response->is_success() ); |
45
|
|
|
|
|
|
|
|
46
|
19
|
|
|
|
|
392
|
return $file; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _init { |
50
|
11
|
|
|
11
|
|
30
|
my ($self) = @_; |
51
|
|
|
|
|
|
|
|
52
|
11
|
|
|
|
|
75
|
$self->{agent} = $self->{factory}->agent(); |
53
|
|
|
|
|
|
|
|
54
|
11
|
|
|
|
|
62
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub resource { |
58
|
22
|
|
|
22
|
1
|
112
|
my ( $self, $spec ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
22
|
50
|
|
|
|
176
|
return $spec if ( UNIVERSAL::isa( $spec, 'Footprintless::Resource::Url' ) ); |
61
|
|
|
|
|
|
|
|
62
|
22
|
100
|
|
|
|
156
|
return Footprintless::Resource::Url->new( ref($spec) ? $spec->{url} : $spec ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub supports { |
66
|
22
|
|
|
22
|
1
|
55
|
my ( $self, $resource ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
22
|
|
|
|
|
64
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |