Text::Sprintf::Named - sprintf-like function with named conversions


Text-Sprintf-Named documentation  | view source Contained in the Text-Sprintf-Named distribution.

Index


NAME

Top

Text::Sprintf::Named - sprintf-like function with named conversions

VERSION

Top

Version 0.0301

SYNOPSIS

Top

    use Text::Sprintf::Named;

    my $formatter =
        Text::Sprintf::Named->new(
            {fmt => "Hello %(name)s! Today is %(day)s!"}
        );

    # Returns "Hello Ayeleth! Today is Sunday!"
    $formatter->format({args => {'name' => "Ayeleth", 'day' => "Sunday"}});

    # Returns "Hello John! Today is Thursday!"
    $formatter->format({args => {'name' => "John", 'day' => "Thursday"}});

DESCRIPTION

Top

Text::Sprintf::Named provides a sprintf equivalent with named conversions. Named conversions are sprintf field specifiers (like "%s" or "%4d") only they are associated with the key of an associative array of parameters. So for example "%(name)s" will emit the 'name' parameter as a string, and "%(num)4d" will emit the 'num' parameter as a variable with a width of 4.

FUNCTIONS

Top

my $formatter = Text::Sprintf::Named->new({fmt => $format})

Creates a new object which formats according to the $format format.

$formatter->format({args => \%bindings})

Returns the formatting string as formatted using the named parameters pointed to by the args parameter.

$self->calc_param({%args})

This method is used to calculate the parameter for the conversion. It can be over-rided by subclasses so it will behave differently. An example can be found in t/02-override-param-retrieval.t where it is used to call the accessors of an object for values.

%args contains:

* named_params

The named paramters.

* name

The name of the conversion.

AUTHOR

Top

Shlomi Fish, shlomif@cpan.org , http://www.shlomifish.org/

BUGS

Top

Please report any bugs or feature requests to bug-text-sprintf-named at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text::Sprintf::Named. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Text::Sprintf::Named

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Text::Sprintf::Named

* CPAN Ratings

http://cpanratings.perl.org/d/Text::Sprintf::Named

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text::Sprintf::Named

* Search CPAN

http://search.cpan.org/dist/Text::Sprintf::Named

* Subversion Repository

http://svn.berlios.de/svnroot/repos/web-cpan/Text-Sprintf/trunk/

ACKNOWLEDGEMENTS

Top

The (possibly ad-hoc) regex for matching the optional digits+symbols parameters' prefix of the sprintf conversion was originally written by Bart Lateur (BARTL on CPAN) for his String::Sprintf module.

COPYRIGHT & LICENSE

Top


Text-Sprintf-Named documentation  | view source Contained in the Text-Sprintf-Named distribution.