1Mojolicious::Plugin::AsUsseetrPaCcokn:t:rPiibpuet(e3d)PMeorjlolDiocciuomuesn:t:aPtliuognin::AssetPack::Pipe(3)
2
3
4

NAME

6       Mojolicious::Plugin::AssetPack::Pipe - Base class for a pipe
7

SYNOPSIS

9   Write a custom pipe
10         package MyApp::MyCoolPipe;
11         use Mojo::Base "Mojolicious::Plugin::AssetPack::Pipe";
12         use Mojolicious::Plugin::AssetPack::Util qw(diag DEBUG);
13
14         sub process {
15           my ($self, $assets) = @_;
16
17           # Normally a Mojolicious::Plugin::AssetPack::Store object
18           my $store = $self->assetpack->store;
19
20           # Loop over Mojolicious::Plugin::AssetPack::Asset objects
21           $assets->each(
22             sub {
23               my ($asset, $index) = @_;
24
25               # Skip every file that is not css
26               return if $asset->format ne "css";
27
28               # Change $attr if this pipe will modify $asset attributes
29               my $attr    = $asset->TO_JSON;
30               my $content = $asset->content;
31
32               # Private name to load/save meta data under
33               $attr->{key} = "coolpipe";
34
35               # Return asset if already processed
36               if ($content !~ /white/ and $file = $store->load($attr)) {
37                 return $asset->content($file);
38               }
39
40               # Process asset content
41               diag q(Replace white with red in "%s".), $asset->url if DEBUG;
42               $content =~ s!white!red!g;
43               $asset->content($store->save(\$content, $attr))->minified(1);
44             }
45           );
46         }
47
48   Use the custom pipe
49         use Mojolicious::Lite;
50         plugin AssetPack => {pipes => [qw(MyApp::MyCoolPipe Css)]};
51
52       Note that the above will not load the other default pipes, such as
53       Mojolicious::Plugin::AssetPack::Pipe::JavaScript.
54

DESCRIPTION

56       This is the base class for all pipe classes.
57

ATTRIBUTES

59   assetpack
60         $obj = $self->assetpack;
61
62       Holds a Mojolicious::Plugin::AssetPack object.
63
64   topic
65         $str = $self->topic;
66         $self = $self->topic("app.css");
67
68       Returns the name of the current asset topic.
69

METHODS

71   after_process
72         $self->after_process(Mojo::Collection->new);
73
74       "process" in Mojolicious::Plugin::AssetPack will call this method
75       before any of the pipe "process" method is called.
76
77       Note that this method is not defined in
78       Mojolicious::Plugin::AssetPack::Pipe!
79
80   app
81         $obh = $self->app;
82
83       Returns the Mojolicious application object.
84
85   before_process
86         $self->before_process(Mojo::Collection->new);
87
88       "process" in Mojolicious::Plugin::AssetPack will call this method after
89       all of the pipes "process" method is called.
90
91       Note that this method is not defined in
92       Mojolicious::Plugin::AssetPack::Pipe!
93
94   process
95         $self->process(Mojo::Collection->new);
96
97       A method used to process the assets.  Each of the element in the
98       collection will be a Mojolicious::Plugin::AssetPack::Asset object or an
99       object with the same API.
100
101       This method need to be defined in the subclass.
102
103   run
104         $self->run([som_app => @args], \$stdin, \$stdout, ...);
105
106       See "run3" in IPC::Run3 for details about the arguments. This method
107       will try to call "_install_some_app()" unless "som_app" was found in
108       PATH. This method could then try to install the application and must
109       return the path to the installed application.
110

SEE ALSO

112       • Mojolicious::Plugin::AssetPack
113
114       • Mojolicious::Plugin::AssetPack::Asset
115
116       • Mojolicious::Plugin::AssetPack::Store
117
118       • Mojolicious::Plugin::AssetPack::Util
119
120
121
122perl v5.34.0                      2021-0M7o-j2o2licious::Plugin::AssetPack::Pipe(3)
Impressum