line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Handler::Http; |
2
|
1
|
|
|
1
|
|
414
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
146
|
use Mojolicious::Types; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
18
|
use Mojolicious::Plugin::AssetPack::Asset; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
50
|
1
|
|
31
|
use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
368
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub asset_for { |
8
|
1
|
|
|
1
|
1
|
14
|
my ($self, $url, $assetpack) = @_; |
9
|
1
|
|
|
|
|
1
|
my $name = do { local $_ = "$url"; s![^\w-]!_!g; $_ }; |
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
155
|
|
|
1
|
|
|
|
|
3
|
|
10
|
1
|
|
|
|
|
1
|
my ($asset, $e, $tx, $ext); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# already downloaded |
13
|
1
|
50
|
|
|
|
33
|
return $asset if $asset = $assetpack->_packed(qr{^$name\.\w+$}); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
6
|
$tx = $assetpack->ua->get($url); |
16
|
1
|
|
50
|
|
|
11483
|
$ext = Mojolicious::Types->new->detect($tx->res->headers->content_type // 'text/plain'); |
17
|
1
|
50
|
|
|
|
273
|
die "Asset $url could not be fetched: $e->{message}" if $e = $tx->error; |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
18
|
$ext = $ext->[0] if ref $ext; |
20
|
1
|
0
|
33
|
|
|
8
|
$ext = $tx->req->url->path =~ m!\.(\w+)$! ? $1 : 'txt' if !$ext or $ext eq 'bin'; |
|
|
50
|
|
|
|
|
|
21
|
1
|
|
|
|
|
7
|
$assetpack->_app->log->info("Asset $url was saved as $name.$ext"); |
22
|
1
|
|
|
|
|
216
|
$assetpack->_asset("$name.$ext")->spurt($tx->res->body); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=encoding utf8 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Mojolicious::Plugin::AssetPack::Handler::Http - DEPRECATED |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
L will be DEPRECATED. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 asset_for |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SEE ALSO |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
L. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |