line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Pipe::Jpeg; |
2
|
1
|
|
|
1
|
|
5
|
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
122
|
use Mojolicious::Plugin::AssetPack::Util qw(diag DEBUG); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
315
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has app => 'jpegoptim'; |
6
|
|
|
|
|
|
|
has app_args => sub { |
7
|
|
|
|
|
|
|
my $self = shift; |
8
|
|
|
|
|
|
|
return [DEBUG ? ('-v') : ('-q'), qw(-f --stdin --stdout)] if $self->app eq 'jpegoptim'; |
9
|
|
|
|
|
|
|
return []; |
10
|
|
|
|
|
|
|
}; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub process { |
13
|
1
|
|
|
1
|
1
|
5
|
my ($self, $assets) = @_; |
14
|
1
|
|
|
|
|
6
|
my $store = $self->assetpack->store; |
15
|
1
|
|
|
|
|
5
|
my $file; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
return $assets->each( |
18
|
|
|
|
|
|
|
sub { |
19
|
1
|
|
|
1
|
|
10
|
my ($asset, $index) = @_; |
20
|
1
|
|
|
|
|
10
|
my $attrs = $asset->TO_JSON; |
21
|
1
|
|
|
|
|
4
|
$attrs->{key} = sprintf '%s-min', $self->app; |
22
|
1
|
|
|
|
|
7
|
$attrs->{minified} = 1; |
23
|
1
|
50
|
33
|
|
|
6
|
return if $asset->format !~ /^jpe?g$/ or $asset->minified; |
24
|
1
|
50
|
|
|
|
14
|
return unless $self->assetpack->minify; |
25
|
0
|
0
|
|
|
|
|
return $asset->content($file)->minified(1) if $file = $store->load($attrs); |
26
|
0
|
|
|
|
|
|
diag 'Process "%s", with checksum %s.', $asset->url, $attrs->{checksum} if DEBUG; |
27
|
0
|
|
|
|
|
|
$asset->content($store->save($self->_run_app($asset), $attrs))->FROM_JSON($attrs); |
28
|
|
|
|
|
|
|
} |
29
|
1
|
|
|
|
|
8
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _install_jpegoptim { |
33
|
0
|
|
|
0
|
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
my $class = ref $self; |
35
|
0
|
|
|
|
|
|
die "$class requires https://github.com/tjko/jpegoptim"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=encoding utf8 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Mojolicious::Plugin::AssetPack::Pipe::Jpeg - Crush JPEG image files |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
L can be used to crush "jpeg" image |
49
|
|
|
|
|
|
|
files. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This pipe is EXPERIMENTAL. Feedback wanted. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 app |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$str = $self->app; |
58
|
|
|
|
|
|
|
$self = $self->app("jpegoptim"); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Can be used to set a custom application instead of "jpegoptim". |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 app_args |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$array = $self->app_args; |
65
|
|
|
|
|
|
|
$self = $self->app_args([qw(-f --stdin --stdout)]); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Can be used to set custom L arguments. The special C<$input> string in |
68
|
|
|
|
|
|
|
the argument list will be replaced with the path to a temp file holding the |
69
|
|
|
|
|
|
|
image data. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
If no C<$input> element is found in the L list, then STDIN and |
72
|
|
|
|
|
|
|
STDOUT will be used instead. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 process |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
See L. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
L. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |