« lib/Mojolicious/Plugin/AssetPack/Pipe/CombineFile.pm
↑ Summary
lib/Mojolicious/Plugin/AssetPack/Pipe/HTML.pm »
| 1 | package Mojolicious::Plugin::AssetPack::Che; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use Mojo::Base 'Mojolicious::Plugin::AssetPack'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Mojolicious::Plugin::AssetPack::Util qw( DEBUG diag checksum );# | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Mojo::URL; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | has [qw(config app)] => undef, weak=>1; | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | has revision => sub { my $app = shift->app; $app->config('revision') // $app->config('version') // $app->config('версия') // ''; }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.1
Condition37%3/8
(($app->config("revision") // $app->config("version")) // $app->config("\x{432}\x{435}\x{440}\x{441}\x{438}\x{44f}")) // ""
($app->config("revision") // $app->config("version")) // $app->config("\x{432}\x{435}\x{440}\x{441}\x{438}\x{44f}")
$app->config("revision") // $app->config("version")
MC/DC0%0/3
(($app->config("revision") // $app->config("version")) // $app->config("\x{432}\x{435}\x{440}\x{441}\x{438}\x{44f}")) // ""
$app->config("revision")
$app->config("version")
$app->config("\x{432}\x{435}\x{440}\x{441}\x{438}\x{44f}")
Truth table25%1/4
A // B // C
A= $app->config("revision")B= $app->config("version")C= $app->config("\x{432}\x{435}\x{440}\x{441}\x{438}\x{44f}")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=7 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | my ($self, $app, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | $self->config($config); | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | $self->app($app); | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | #~ Scalar::Util::weaken($self->{app}); | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | Mojo::File->new($app->home->rel_file('assets'), 'cache')->remove_tree({keep_root => 1}); | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | $self->SUPER::register($app, $config); | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # Patch the asset route | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | $self->route; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | $app->routes->find('assetpack')->pattern->defaults->{cb} = $self->serve_cb(); | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | $self->store->_types->type(html => ['text/html;charset=UTF-8']);# Restore deleted Jan | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | $self->store->default_headers($config->{default_headers}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | if $config->{default_headers}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | my $process = $config->{process}; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | $self->process(ref eq 'ARRAY' ? @$_ : $_) #($_->[0], map Mojo::URL->new($_), @$_[1..$#$_]) | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | for ref $process eq 'HASH' ? map([$_=> ref $process->{$_} eq 'ARRAY' ? @{$process->{$_}} : $process->{$_}], keys %$process) : ref $process eq 'ARRAY' ? @$process : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # redefine for nested topics | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=8 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | my ($self, $topic, @input) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | utf8::encode($topic); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | $self->route unless $self->{route_added}++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | return $self->_process_from_def($topic) unless @input; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | my $assets = Mojo::Collection->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | for my $url (@input) { | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 12 | utf8::encode($url); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 12 | ▶ | if (my $nested = $self->processed($url)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | push @$assets, @$nested; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 12 | ▶ | my $asset = Scalar::Util::blessed($url) ? $url : $self->store->asset($url); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | ▶ | die qq(Could not find input asset "$url" .) unless Scalar::Util::blessed($asset); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 12 | push @$assets, $asset; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return $self->tap(sub { $_->{input}{$topic} = $assets }) if $self->{lazy}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | return $self->_process($topic => $assets); | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | #!!! me frozen at parent version 2.02 | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | ▶ | sub processed { $_[0]->{by_topic}{$_[1]} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
processed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | sub serve_cb { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_cb: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 10 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 10 | my $checksum = $c->stash('checksum'); | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | ▶ | if (($c->req->headers->accept_encoding // '') =~ /gzip/i && (my $asset = $self->{by_checksum}{$checksum})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
($c->req->headers->accept_encoding // "") =~ /gzip/iu and my $asset = $self->{"by_checksum"}{$checksum}
$c->req->headers->accept_encoding // ""
MC/DC50%1/2
($c->req->headers->accept_encoding // "") =~ /gzip/iu and my $asset = $self->{"by_checksum"}{$checksum}
$c->req->headers->accept_encoding
my $asset = $self->{"by_checksum"}{$checksum}
Truth table66%2/3
A and B
A= $c->req->headers->accept_encodingB= my $asset = $self->{"by_checksum"}{$checksum}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 9 | my $checksum_gzip = checksum($asset->url.$self->revision.'.gzip'); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | $asset = $self->{by_checksum}{$checksum_gzip} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%6/8
$asset = $self->{"by_checksum"}{$checksum_gzip} and $c->res->headers->content_encoding("gzip") and 1 and $self->store->serve_asset($c, $asset)
$asset = $self->{"by_checksum"}{$checksum_gzip} and $c->res->headers->content_encoding("gzip") and 1
$asset = $self->{"by_checksum"}{$checksum_gzip} and $c->res->headers->content_encoding("gzip")
MC/DC33%1/3
$asset = $self->{"by_checksum"}{$checksum_gzip} and $c->res->headers->content_encoding("gzip") and 1 and $self->store->serve_asset($c, $asset)
$asset = $self->{"by_checksum"}{$checksum_gzip}
$c->res->headers->content_encoding("gzip")
$self->store->serve_asset($c, $asset)
Truth table50%2/4
A and B and C
A= $asset = $self->{"by_checksum"}{$checksum_gzip}B= $c->res->headers->content_encoding("gzip")C= $self->store->serve_asset($c, $asset)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | and $c->res->headers->content_encoding('gzip') | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | and (DEBUG ? diag("Sent GZIPed topic [%s]", $asset->url) : 1)#$self->minify ? $self->app->log->info('') : | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | and $self->store->serve_asset($c, $asset) | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | and return $c->rendered; | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | Mojolicious::Plugin::AssetPack::_serve($c, @_); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Доброго всем | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =head1 Mojolicious::Plugin::AssetPack::Che | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ¡ ¡ ¡ ALL GLORY TO GLORIA ! ! ! | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | Mojolicious::Plugin::AssetPack::Che - Child of Mojolicious::Plugin::AssetPack for little bit code. | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | Can process assets during register plugin. | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | Can nested assets. | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | Can pipe HTML files with L<Mojolicious::Plugin::AssetPack::Pipe::HTML>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | Can compile Vue templates L<Mojolicious::Plugin::AssetPack::Pipe::VueTemplateCompiler>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Can pipe CSS, JS, JSON, HTML with L<Mojolicious::Plugin::AssetPack::Pipe::CombineFile> into disk cache. This pipe can also gzip and cache gzipped assets. | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | Since parent version 1.28. | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Version 2.106 (test on base Mojolicious::Plugin::AssetPack v2.10) | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | our $VERSION = '2.106'; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | See parent module L<Mojolicious::Plugin::AssetPack> for full documentation. | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | On register the plugin C<config> can contain additional optional argument B<process>: | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $app->plugin('AssetPack::Che', | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | pipes => [qw(Sass Css JavaScriptPacker HTML CombineFile)], | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | CombineFile => { gzip => {min_size => 1000},}, # pipe options | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | HTML => {minify_opts=>{remove_newlines => 1,}},# pipe based on HTML::Packer | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | JavaScriptPacker => {minify_opts=>{}},# pipe based on JavaScript::Packer | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | process => [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ['foo.js' => qw(path/to/foo1.js path/to/foo2.js)], | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ['bar.js' => qw(foo.js path/to/bar1.js path/to/bar2.js)], # nested topic | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ['foo.html' => qw(path/to/foo1.html path/to/foo2.html)], | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ... | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | L<Mojolicious::Plugin::AssetPack> | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | Михаил Че (Mikhail Che), C<< <mche[-at-]cpan.org> >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =head1 BUGS / CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | Please report any bugs or feature requests at L<https://github.com/mche/Mojolicious-Plugin-AssetPack-Che/issues>. Pull requests also welcome. | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | Copyright 2016-2020 Mikhail Che. | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | 1; # End of Mojolicious::Plugin::AssetPack::Che | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||