The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Rsync::Config::Renderer - rsync config rendering

VERSION

0.1.2

DESCRIPTION

Rsync::Config::Renderer is the module used to indent all output generated by Rsync::Config . Is also the base class for all other modules.

SYNOPSIS

    use Rsync::Config::Renderer;
    my $renderer = Rsync::Config::Renderer->new(
                        indent => 1, indent_char => "\t" );
    print $renderer->indent_string, q{foobar};
    # prints: "<TAB>foobar";

    $renderer->indent(4)->indent_char(q{.});
    print $renderer->indent_string, q{foobar};
    # prints: "....foobar";

    print $renderer->render( 'foobar', 22, 'baz' );
    # prints:
    # ....foobar
    # ....22
    # ....baz

SUBROUTINES/METHODS

new

    my $renderer = Rsync::Config::Renderer->new(%options);

Class contructor.

Returns a Rsync::Config::Renderer object.

Currently recognized options are: indent (default: 0) and indent_char (default: \t). Each option is described with its respective accessor/mutator.

All other passed options are silently loaded into the generated object, but currently no accessors are being automatically created for them.

indent

    my $current_indent = $renderer->indent;
    $renderer->indent(4);

Both accessor and mutator, indent can be used to get the current indentation level or to change it.

If no arguments are provided, it will return the current indentation level.

If arguments are provided, first is considered to be the new indentation level and applied to the current object, all others being ignored.

As mutator, the current object will be returned (useful for method chaining).

To disable indenting, pass a value of 0 (digit zero).

If invalid value is passed for setting the indentation level, a fatal error is threw. Valid values are non-negative integers.

It can also be called as a class method, returning the default indentation level. In this case, no mutator mode is possible.

indent_char

    my $current_indent_char = $renderer->indent_char;
    $renderer->indent_char(q{.});

Both accessor and mutator, indent_char can be used to get the current indentation "character" or to change it.

If no arguments are provided, it will return the current indentation "character".

If arguments are provided, first is considered to be the new indentation character and applied to the current object, all others being ignored.

As mutator, the current object will be returned (useful for method chaining).

If invalid value is passed for setting the indentation "character", a fatal error is threw. Valid value is any non-empty sequence of characters.

It can also be called as a class method, returning the default indentation character. In this case, no mutator mode is possible.

render

    print $renderer->render(@lines, { prefix => "* ", suffix => ".\n" });

Crude rendering method. Returns the lines (as scalar or list, depeding on calling context), indented appropriately.

Options may be passed in a hash reference. All options recognized by new are handled by render with the same effect.

The particular options to render are prefix (default: none) and suffix (default: \n), which are the strings to be prepended and respectively appended to each line.

It can also be called as a class method.

indent_string($indent, $indent_char)

    my $indent_str = $renderer->indent_string();
    my $indent_str = $renderer->indent_string($indent, $indent_char);
    my $indent_str = Rsync::Config::Renderer->indent_string();
    my $indent_str = Rsync::Config::Renderer->indent_string(
                                              $indent, $indent_char);

Returns a string containing the current indentation.

If $indent and $indent_char are provided, they will override current object's attributes.

It can also be called as a class method.

DEPENDENCIES

Exception::Class.

DIAGNOSTICS

Invalid value: need a non-negative integer!

Occurs when passing invalid values to indent. Self-explanatory.

Invalid value: need a non-empty string!

Occurs when passing invalid values to indent_char. Self-explanatory.

CONFIGURATION AND ENVIRONMENT

This module does not use any configuration files or environment variables.

INCOMPATIBILITIES

None known to the author.

BUGS AND LIMITATIONS

No bugs known to the author.

SEE ALSO

Rsync::Config.

AUTHOR

Manuel SUBREDU <diablo@packages.ro>.

LICENSE AND COPYRIGHT

Copyright (c) 2006, Manuel SUBREDU <diablo@packages.ro>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.