1Text::Sprintf::Named(3)User Contributed Perl DocumentatioTnext::Sprintf::Named(3)
2
3
4

NAME

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

VERSION

9       version 0.0403
10

SYNOPSIS

12           use Text::Sprintf::Named;
13
14           my $formatter =
15               Text::Sprintf::Named->new(
16                   {fmt => "Hello %(name)s! Today is %(day)s!"}
17               );
18
19           # Returns "Hello Ayeleth! Today is Sunday!"
20           $formatter->format({args => {'name' => "Ayeleth", 'day' => "Sunday"}});
21
22           # Returns "Hello John! Today is Thursday!"
23           $formatter->format({args => {'name' => "John", 'day' => "Thursday"}});
24
25           # Or alternatively using the non-OOP interface:
26
27           use Text::Sprintf::Named qw(named_sprintf);
28
29           # Prints "Hello Sophie!" (and a newline).
30           print named_sprintf("Hello %(name)s!\n", { name => 'Sophie' });
31
32           # Same, but with a flattened parameter list (not inside a hash reference)
33           print named_sprintf("Hello %(name)s!\n", name => 'Sophie');
34

DESCRIPTION

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

VERSION

44       version 0.0403
45

FUNCTIONS

47   my $formatter = Text::Sprintf::Named->new({fmt => $format})
48       Creates a new object which formats according to the $format format.
49
50   $formatter->format({args => \%bindings})
51       Returns the formatting string as formatted using the named parameters
52       pointed to by the "args" parameter.
53
54   $self->calc_param({%args})
55       This method is used to calculate the parameter for the conversion. It
56       can be over-rided by subclasses so it will behave differently. An
57       example can be found in "t/02-override-param-retrieval.t" where it is
58       used to call the accessors of an object for values.
59
60       %args contains:
61
62       ·   named_params
63
64           The named paramters.
65
66       ·   name
67
68           The name of the conversion.
69
70   named_sprintf($format, {%parameters})
71   named_sprintf($format, %parameters)
72       This is a convenience function to directly format a string with the
73       named parameters, which can be specified inside a (non-blessed) hash
74       reference or as a flattened hash. See the synopsis for an example.
75

AUTHOR

77       Shlomi Fish, "shlomif@cpan.org" , <http://www.shlomifish.org/>
78

BUGS

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

SUPPORT

87       You can find documentation for this module with the perldoc command.
88
89           perldoc Text::Sprintf::Named
90
91       You can also look for information at:
92
93       ·   AnnoCPAN: Annotated CPAN documentation
94
95           <http://annocpan.org/dist/Text::Sprintf::Named>
96
97       ·   CPAN Ratings
98
99           <http://cpanratings.perl.org/d/Text::Sprintf::Named>
100
101       ·   RT: CPAN's request tracker
102
103           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text::Sprintf::Named>
104
105       ·   Search CPAN
106
107           <http://search.cpan.org/dist/Text::Sprintf::Named>
108
109       ·   Subversion Repository
110
111           <http://svn.berlios.de/svnroot/repos/web-cpan/Text-Sprintf/trunk/>
112

ACKNOWLEDGEMENTS

114       The (possibly ad-hoc) regex for matching the optional digits+symbols
115       parameters' prefix of the sprintf conversion was originally written by
116       Bart Lateur (BARTL on CPAN) for his String::Sprintf module.
117
118       The syntax was borrowed directly from PythonXs "%" operator when used
119       with its dictionaries as the right-hand argument. A quick web search
120       did not yield good documentation about it (and I came with the idea of
121       a named sprintf without knowing that Python had it, only ran into the
122       fact that Python had it by web-searching).
123

SIMILAR MODULES

125       Text::sprintfn is a newer module which only provides a procedural
126       interface that allows one to mix positional and named arguments, with
127       some other interesting features.
128
129       String::Formatter is a comprehensive module that allows one to define
130       custom sprintf-like functions (IXm not sure whether it has named
131       conversions).  Its license is the GNU General Public Licence version 2
132       (GPLv2), which is both restrictive and incompatible with version 3 of
133       the GPL and with many other open-source licenses.
134
135       String::Sprintf appears to allow one to provide custom sprintf/printf
136       formats (without providing named conversions).
137
138       For the lighter side, there is Acme::StringFormat, which provides a "%"
139       operator to format a string.
140
142       Copyright 2006 Shlomi Fish, all rights reserved.
143
144       This program is released under the following license: MIT/X11:
145
146       <http://www.opensource.org/licenses/mit-license.php>
147

AUTHOR

149       Shlomi Fish <shlomif@cpan.org>
150
152       This software is Copyright (c) 2018 by Shlomi Fish.
153
154       This is free software, licensed under:
155
156         The MIT (X11) License
157

BUGS

159       Please report any bugs or feature requests on the bugtracker website
160       <https://github.com/shlomif/text-sprintf-named/issues>
161
162       When submitting a bug or request, please include a test-file or a patch
163       to an existing test-file that illustrates the bug or desired feature.
164

SUPPORT

166   Perldoc
167       You can find documentation for this module with the perldoc command.
168
169         perldoc Text::Sprintf::Named
170
171   Websites
172       The following websites have more information about this module, and may
173       be of help to you. As always, in addition to those websites please use
174       your favorite search engine to discover more resources.
175
176       ·   MetaCPAN
177
178           A modern, open-source CPAN search engine, useful to view POD in
179           HTML format.
180
181           <https://metacpan.org/release/Text-Sprintf-Named>
182
183       ·   Search CPAN
184
185           The default CPAN search engine, useful to view POD in HTML format.
186
187           <http://search.cpan.org/dist/Text-Sprintf-Named>
188
189       ·   RT: CPAN's Bug Tracker
190
191           The RT ( Request Tracker ) website is the default bug/issue
192           tracking system for CPAN.
193
194           <https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Sprintf-Named>
195
196       ·   AnnoCPAN
197
198           The AnnoCPAN is a website that allows community annotations of Perl
199           module documentation.
200
201           <http://annocpan.org/dist/Text-Sprintf-Named>
202
203       ·   CPAN Ratings
204
205           The CPAN Ratings is a website that allows community ratings and
206           reviews of Perl modules.
207
208           <http://cpanratings.perl.org/d/Text-Sprintf-Named>
209
210       ·   CPANTS
211
212           The CPANTS is a website that analyzes the Kwalitee ( code metrics )
213           of a distribution.
214
215           <http://cpants.cpanauthors.org/dist/Text-Sprintf-Named>
216
217       ·   CPAN Testers
218
219           The CPAN Testers is a network of smoke testers who run automated
220           tests on uploaded CPAN distributions.
221
222           <http://www.cpantesters.org/distro/T/Text-Sprintf-Named>
223
224       ·   CPAN Testers Matrix
225
226           The CPAN Testers Matrix is a website that provides a visual
227           overview of the test results for a distribution on various
228           Perls/platforms.
229
230           <http://matrix.cpantesters.org/?dist=Text-Sprintf-Named>
231
232       ·   CPAN Testers Dependencies
233
234           The CPAN Testers Dependencies is a website that shows a chart of
235           the test results of all dependencies for a distribution.
236
237           <http://deps.cpantesters.org/?module=Text::Sprintf::Named>
238
239   Bugs / Feature Requests
240       Please report any bugs or feature requests by email to
241       "bug-text-sprintf-named at rt.cpan.org", or through the web interface
242       at
243       <https://rt.cpan.org/Public/Bug/Report.html?Queue=Text-Sprintf-Named>.
244       You will be automatically notified of any progress on the request by
245       the system.
246
247   Source Code
248       The code is open to the world, and available for you to hack on. Please
249       feel free to browse it and play with it, or whatever. If you want to
250       contribute patches, please send me a diff or prod me to pull from your
251       repository :)
252
253       <https://github.com/shlomif/text-sprintf-named>
254
255         git clone https://bitbucket.org/shlomif/perl-text-sprintf
256
257
258
259perl v5.28.0                      2018-07-15           Text::Sprintf::Named(3)
Impressum