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