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