Package Info

perl-String-Formatter


Build sprintf-like functions of your own


Unspecified

String::Formatter is a tool for building sprintf-like formatting routines. It supports named or positional formatting, custom conversions, fixed string interpolation, and simple width-matching out of the box. It is easy to alter its behavior to write new kinds of format string expanders. For most cases, it should be easy to build all sorts of formatters out of the options built into String::Formatter.

Normally, String::Formatter will be used to import a sprintf-like routine referred to as "'stringf'", but which can be given any name you like. This routine acts like sprintf in that it takes a string and some inputs and returns a new string:

my $output = stringf "Some %a format %s for you to %u.\n", { ... };

This routine is actually a wrapper around a String::Formatter object created by importing stringf. In the following code, the entire hashref after "stringf" is passed to String::Formatter's constructor (the 'new' method), save for the '-as' key and any other keys that start with a dash.

use String::Formatter stringf => { -as => 'fmt_time', codes => { ... }, format_hunker => ..., input_processor => ..., }, stringf => { -as => 'fmt_date', codes => { ... }, string_replacer => ..., hunk_formatter => ..., }, ;

As you can see, this will generate two stringf routines, with different behaviors, which are installed with different names. Since the behavior of these routines is based on the 'format' method of a String::Formatter object, the rest of the documentation will describe the way the object behaves.

There's also a 'named_stringf' export, which behaves just like the 'stringf' export, but defaults to the 'named_replace' and 'require_named_input' arguments. There's a 'method_stringf' export, which defaults 'method_replace' and 'require_single_input'. Finally, a 'indexed_stringf', which defaults to 'indexed_replaced' and 'require_arrayref_input'. For more on these, keep reading, and check out the cookbook.

String::Formatter::Cookbook provides a number of recipes for ways to put String::Formatter to use.


License: GPL-1.0-or-later
URL: https://metacpan.org/release/String-Formatter

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
1.235-bp156.2.1 info GA Release 2023-07-22 15 SP6
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter
1.235-bp155.1.4 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter
1.234-bp154.1.31 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter
0.102084-bp153.1.12 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter
0.102084-bp152.3.16 info GA Release 2020-04-17 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter
0.102084-bp151.3.1 info GA Release 2019-07-16 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter
0.102084-bp151.2.12 info GA Release 2019-05-18 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter
0.102084-bp150.2.4 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-String-Formatter