NAME

IPC::PrettyPipe::Render::Template::Tiny - rendering backend using Template::Tiny

VERSION

version 0.12

SYNOPSIS

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 );

DESCRIPTION

IPC::PrettyPipe::Render::Template::Tiny implements the IPC::PrettyPipe::Renderer role, providing a rendering backend for IPC::PrettyPipe using the Template::Tiny module.

ATTRIBUTES

pipe

The IPC::PrettyPipe object to render.

pipe

$pipe = $renderer->pipe;
$renderer->pipe( $pipe );

Retrieve or set the IPC::PrettyPipe object to render.

colors

A color specification; see "Rendered Colors".

cmd_template

A Template::Tiny template to generate output for commands. See "Rendering Templates".

pipe_template

A Template::Tiny template to generate output for pipes. See "Rendering Templates".

METHODS

new

$renderer = IPC::PrettyPipe::Render::Template::Tiny->new( %attr );

Construct a new renderer. Typically this is done automatically by IPC::PrettyPipe.

colors

$colors = $renderer->colors;
$renderer->colors( $colors );

Retrieve or set the colors to be output; see "Rendered Colors".

cmd_template

$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

$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".

render

$renderer->render( %options );

The following options are available:

  • colorize

    If true (the default) the output is colorized using Term::AnsiColor.

CONFIGURATION

Rendering Templates

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.

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.

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:

[% 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.

Rendered Colors

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',
    },
},

BUGS

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.

SOURCE

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

SEE ALSO

Please see those modules/websites for more information related to this module.

AUTHOR

Diab Jerius <djerius@cpan.org>

COPYRIGHT AND LICENSE

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