| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Asset; |
|
2
|
12
|
|
|
12
|
|
3312
|
use Mojo::Base -base; |
|
|
12
|
|
|
|
|
28
|
|
|
|
12
|
|
|
|
|
64
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
12
|
|
|
12
|
|
1452
|
use Mojo::Asset::Memory; |
|
|
12
|
|
|
|
|
25
|
|
|
|
12
|
|
|
|
|
119
|
|
|
5
|
12
|
|
|
12
|
|
259
|
use Mojo::URL; |
|
|
12
|
|
|
|
|
22
|
|
|
|
12
|
|
|
|
|
85
|
|
|
6
|
12
|
|
|
12
|
|
266
|
use Mojo::File; |
|
|
12
|
|
|
|
|
32
|
|
|
|
12
|
|
|
|
|
433
|
|
|
7
|
12
|
|
|
12
|
|
70
|
use Mojolicious::Plugin::AssetPack::Util qw(diag has_ro DEBUG); |
|
|
12
|
|
|
|
|
37
|
|
|
|
12
|
|
|
|
|
11069
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has checksum => sub { Mojolicious::Plugin::AssetPack::Util::checksum(shift->content) }; |
|
10
|
|
|
|
|
|
|
has format => sub { |
|
11
|
|
|
|
|
|
|
my $self = shift; |
|
12
|
|
|
|
|
|
|
my $name |
|
13
|
|
|
|
|
|
|
= $self->url =~ /^https?:/ |
|
14
|
|
|
|
|
|
|
? Mojo::URL->new($self->url)->path->[-1] |
|
15
|
|
|
|
|
|
|
: (split m!(\\|/)!, $self->url)[-1]; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
return $name =~ /\.(\w+)$/ ? lc $1 : ''; |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has minified => sub { shift->url =~ /\bmin\b/ ? 1 : 0 }; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has _asset => sub { |
|
23
|
|
|
|
|
|
|
my $self = shift; |
|
24
|
|
|
|
|
|
|
return $self->content(delete $self->{content})->_asset if $self->{content}; |
|
25
|
|
|
|
|
|
|
return Mojo::Asset::File->new(path => delete $self->{path}) if $self->{path}; |
|
26
|
|
|
|
|
|
|
return Mojo::Asset::Memory->new; |
|
27
|
|
|
|
|
|
|
}; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has_ro name => sub { |
|
30
|
|
|
|
|
|
|
my $self = shift; |
|
31
|
|
|
|
|
|
|
my $name; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if ($self->url =~ /^https?:/) { |
|
34
|
|
|
|
|
|
|
my $url = Mojo::URL->new($self->url); |
|
35
|
|
|
|
|
|
|
my $qs = $url->query->to_string; |
|
36
|
|
|
|
|
|
|
$name = $url->path->[-1]; |
|
37
|
|
|
|
|
|
|
$qs =~ s!\W!_!g; |
|
38
|
|
|
|
|
|
|
$name =~ s!\.\w+$!!; |
|
39
|
|
|
|
|
|
|
$name .= "_$qs" if $qs; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
else { |
|
42
|
|
|
|
|
|
|
$name = (split m!(\\|/)!, $self->url)[-1]; |
|
43
|
|
|
|
|
|
|
$name =~ s!\.\w+$!!; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $name; |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has_ro 'url'; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub asset { |
|
52
|
18
|
|
|
18
|
1
|
40
|
my $self = shift; |
|
53
|
18
|
|
|
|
|
70
|
my $orig = $self->_asset; |
|
54
|
18
|
|
|
|
|
115
|
my $clone = $orig->new; |
|
55
|
|
|
|
|
|
|
|
|
56
|
18
|
100
|
|
|
|
210
|
if ($orig->is_file) { |
|
57
|
12
|
|
|
|
|
73
|
$clone->cleanup(0)->path($orig->path); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
else { |
|
60
|
6
|
|
|
|
|
49
|
$clone->auto_upgrade(0)->mtime($orig->mtime)->add_chunk($orig->slurp); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
18
|
|
|
|
|
448
|
return $clone; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub content { |
|
67
|
39
|
|
|
39
|
1
|
75
|
my $self = shift; |
|
68
|
39
|
100
|
|
|
|
119
|
return $self->_asset->slurp unless @_; |
|
69
|
19
|
50
|
|
|
|
99
|
return $self->_asset($_[0]->_asset) if UNIVERSAL::isa($_[0], __PACKAGE__); |
|
70
|
19
|
100
|
|
|
|
107
|
return $self->_asset($_[0]) if UNIVERSAL::isa($_[0], 'Mojo::Asset'); |
|
71
|
1
|
|
|
|
|
11
|
return $self->_asset(Mojo::Asset::Memory->new->add_chunk($_[0])); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub path { |
|
75
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
76
|
0
|
0
|
|
|
|
0
|
return $self->_asset(Mojo::Asset::File->new(path => $_[0])) if $_[0]; |
|
77
|
0
|
0
|
|
|
|
0
|
return Mojo::File->new($self->_asset->path) if $self->_asset->isa('Mojo::Asset::File'); |
|
78
|
0
|
|
|
|
|
0
|
return undef; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
0
|
1
|
0
|
sub size { $_[0]->_asset->size } |
|
82
|
|
|
|
|
|
|
|
|
83
|
72
|
|
|
72
|
1
|
220
|
sub url_for { $_[1]->url_for(assetpack => $_[0]->TO_JSON); } |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub FROM_JSON { |
|
86
|
0
|
|
|
0
|
1
|
0
|
my ($self, $attrs) = @_; |
|
87
|
0
|
|
|
|
|
0
|
$self->$_($attrs->{$_}) for grep { defined $attrs->{$_} } qw(checksum format minified); |
|
|
0
|
|
|
|
|
0
|
|
|
88
|
0
|
|
|
|
|
0
|
$self; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub TO_JSON { |
|
92
|
74
|
|
|
74
|
1
|
138
|
return {map { ($_ => $_[0]->$_) } qw(checksum format minified name url)}; |
|
|
370
|
|
|
|
|
1448
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=encoding utf8 |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Mojolicious::Plugin::AssetPack::Asset - An asset |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L represents an asset. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Mojolicious::Plugin::AssetPack::Asset; |
|
110
|
|
|
|
|
|
|
my $asset = Mojolicious::Plugin::AssetPack::Asset->new(url => "..."); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 checksum |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$str = $self->checksum; |
|
117
|
|
|
|
|
|
|
$self = $self->checksum($str); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The L of L. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 format |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$str = $self->format; |
|
124
|
|
|
|
|
|
|
$self = $self->format($str); |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The format of L. Defaults to the extension of L or empty string. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 minified |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$bool = $self->minified; |
|
131
|
|
|
|
|
|
|
$self = $self->minified($bool); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Will be set to true if either L contains "min" or if a pipe has |
|
134
|
|
|
|
|
|
|
minified L. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 name |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$str = $self->name; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns the basename of L, without extension. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 url |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$str = $self->url; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns the location of the asset. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 METHODS |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 asset |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$asset = $self->asset; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Returns a new L or L object, with the |
|
155
|
|
|
|
|
|
|
content or path from this object. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This method is EXPERIMENTAL. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 content |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$bytes = $self->content; |
|
162
|
|
|
|
|
|
|
$self = $self->content($bytes); |
|
163
|
|
|
|
|
|
|
$self = $self->content(Mojo::Asset::Memory->new); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Used to get or set the content of this asset. The default will be built from |
|
166
|
|
|
|
|
|
|
passing L to L. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 path |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
$str = $self->path; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Returns a L object that holds the location to the asset on disk or |
|
173
|
|
|
|
|
|
|
C if this asset is in memory. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 size |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$int = $self->size; |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns the size of the asset in bytes. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 url_for |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
$url = $self->url_for($c); |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Returns a L object for this asset. C<$c> need to be a |
|
186
|
|
|
|
|
|
|
L. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 FROM_JSON |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
$self = $self->FROM_JSON($hash_ref); |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The opposite of L. Will set the read/write L from the |
|
193
|
|
|
|
|
|
|
values in C<$hash_ref>. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 TO_JSON |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$hash_ref = $self->FROM_JSON; |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
The opposite of L. Will generate a hash ref from L. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L. |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |