IPC::PrettyPipe::Render::Template::Tiny - rendering backend using Template::Tiny
version 0.12
use IPC::PrettyPipe::DSL; my $pipe = ppipe 'ls'; $pipe->renderer( 'Template::Tiny' ); # or, more explicitly my $renderer = IPC::PrettyPipe::Render::Template::Tiny->new; $pipe->renderer( $renderer );
IPC::PrettyPipe::Render::Template::Tiny implements the IPC::PrettyPipe::Renderer role, providing a rendering backend for IPC::PrettyPipe using the Template::Tiny module.
The IPC::PrettyPipe object to render.
$pipe = $renderer->pipe; $renderer->pipe( $pipe );
Retrieve or set the IPC::PrettyPipe object to render.
A color specification; see "Rendered Colors".
A Template::Tiny template to generate output for commands. See "Rendering Templates".
A Template::Tiny template to generate output for pipes. See "Rendering Templates".
$renderer = IPC::PrettyPipe::Render::Template::Tiny->new( %attr );
Construct a new renderer. Typically this is done automatically by IPC::PrettyPipe.
$colors = $renderer->colors; $renderer->colors( $colors );
Retrieve or set the colors to be output; see "Rendered Colors".
$cmd_template = $renderer->cmd_template; $renderer->cmd_template( $cmd_template );
Retrieve or set the Template::Tiny template used to generate output for commands. See "Rendering Templates".
$pipe_template = $renderer->pipe_template; $renderer->pipe_template( $pipe_template );
Retrieve or set the Template::Tiny template used to generate output for pipes. See "Rendering Templates".
$renderer->render( %options );
The following options are available:
colorize
If true (the default) the output is colorized using Term::AnsiColor.
Because pipes may be nested and Template::Tiny cannot handle recursive logic, there are two templates, cmd_template for commands and pipe_template for pipes.
cmd_template
pipe_template
Template::Tiny also doesn't support loop constructs, so the IPC::PrettyPipe streams and cmds methods return IPC::PrettyPipe::Queue objects, which provide methods for determining if the lists are empty.
[% IF pipe.streams.empty %][% ELSE %](\t\\ [% END -%]
Note that Template::Tiny resolves object methods with the same syntax as it resolves hash entries.
Iteration looks like this:
[%- FOREACH cmd IN pipe.cmds.elements %] [% END %]
An IPC::PrettyPipe::Queue::Element has additional methods which indicates whether it is the first or last in its queue.
[%- IF cmd.first %] [% ELSE %]\t\\ | [% END %]
The templates are passed the following parameters:
indent
Indentation is performed via tab stops. indent is augmented with additional tab characters (\t) for nested pipes.
\t
pipe
This is passed only to the pipe_template.
pipe is the IPC::PrettyPipe object.
cmd
This is passed only to the cmd_template
cmd is the IPC::PrettyPipe::Cmd object.
cmds
This is passed only to the pipe_template. It contains the rendered commands in the pipe.
color
This is the hashref specified by the colors attribute or method. It contains an additional element reset which can be used to reset all colors at once. Here's an example bit of template to output and colorize a command:
colors
reset
[% color.cmd.cmd %][% cmd.cmd %][% color.reset %]
Use the default templates (encoded into the source file for IPC::PrettyPipe::Render::Template::Tiny) as a basis for exploration.
The colors attribute and method may be used to change the colors used to render the pipeline. Colors are stored as a hashref with the following default contents:
cmd => { cmd => 'blue', stream => { spec => 'red', file => 'green', }, arg => { name => 'red', sep => 'yellow', value => 'green', }, }, pipe => { stream => { spec => 'red', file => 'green', }, },
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=IPC-PrettyPipe or by email to bug-IPC-PrettyPipe@rt.cpan.org.
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
The development version is on github at https://github.com/djerius/ipc-prettypipe and may be cloned from git://github.com/djerius/ipc-prettypipe.git
Please see those modules/websites for more information related to this module.
IPC::PrettyPipe
Diab Jerius <djerius@cpan.org>
This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
To install IPC::PrettyPipe, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::PrettyPipe
CPAN shell
perl -MCPAN -e shell install IPC::PrettyPipe
For more information on module installation, please visit the detailed CPAN module installation guide.