| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
4
|
|
|
4
|
|
21372
|
use strict; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
92
|
|
|
2
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
147
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Footprintless::Resource::UrlProvider; |
|
5
|
|
|
|
|
|
|
$Footprintless::Resource::UrlProvider::VERSION = '1.28'; |
|
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
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
179
|
use Carp; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
157
|
|
|
12
|
4
|
|
|
4
|
|
344
|
use Footprintless::Resource::Url; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
78
|
|
|
13
|
4
|
|
|
|
|
120
|
use Footprintless::Util qw( |
|
14
|
|
|
|
|
|
|
temp_file |
|
15
|
4
|
|
|
4
|
|
16
|
); |
|
|
4
|
|
|
|
|
8
|
|
|
16
|
4
|
|
|
4
|
|
18
|
use Log::Any; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
17
|
|
|
17
|
4
|
|
|
4
|
|
1721
|
use URI; |
|
|
4
|
|
|
|
|
15403
|
|
|
|
4
|
|
|
|
|
1119
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _download { |
|
22
|
19
|
|
|
19
|
|
67
|
my ( $self, $resource, %options ) = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
19
|
|
|
|
|
41
|
my $file; |
|
25
|
19
|
100
|
|
|
|
43
|
if ( $options{to} ) { |
|
26
|
12
|
|
|
|
|
21
|
$file = $options{to}; |
|
27
|
12
|
100
|
|
|
|
192
|
if ( -d $file ) { |
|
28
|
6
|
|
|
|
|
39
|
my @segments = $resource->get_uri()->path_segments(); |
|
29
|
6
|
|
|
|
|
531
|
$file = File::Spec->catfile( $file, $segments[$#segments] ); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
else { |
|
33
|
7
|
|
|
|
|
21
|
my @suffix; |
|
34
|
7
|
50
|
|
|
|
34
|
if ( $resource->get_url() =~ /.*(\.\S*)$/ ) { |
|
35
|
7
|
|
|
|
|
51
|
$logger->tracef( 'preserving extension [%s] for resource %s', $1, $resource ); |
|
36
|
7
|
|
|
|
|
138
|
push( @suffix, suffix => $1 ); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
25
|
$file = temp_file(@suffix); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
19
|
|
|
|
|
89
|
my $response = $self->{agent}->get( $resource->get_uri(), ':content_file' => "$file" ); |
|
43
|
19
|
50
|
|
|
|
111766
|
croak( 'download failed: ', $response->message() ) |
|
44
|
|
|
|
|
|
|
unless ( $response->is_success() ); |
|
45
|
|
|
|
|
|
|
|
|
46
|
19
|
|
|
|
|
253
|
return $file; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _init { |
|
50
|
11
|
|
|
11
|
|
23
|
my ($self) = @_; |
|
51
|
|
|
|
|
|
|
|
|
52
|
11
|
|
|
|
|
55
|
$self->{agent} = $self->{factory}->agent(); |
|
53
|
|
|
|
|
|
|
|
|
54
|
11
|
|
|
|
|
66
|
return $self; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub resource { |
|
58
|
22
|
|
|
22
|
1
|
95
|
my ( $self, $spec ) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
22
|
50
|
|
|
|
141
|
return $spec if ( UNIVERSAL::isa( $spec, 'Footprintless::Resource::Url' ) ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
22
|
100
|
|
|
|
146
|
return Footprintless::Resource::Url->new( ref($spec) ? $spec->{url} : $spec ); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub supports { |
|
66
|
22
|
|
|
22
|
1
|
45
|
my ( $self, $resource ) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
22
|
|
|
|
|
57
|
return 1; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |