Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / Template / Plugin / Format.pm
1 #============================================================= -*-Perl-*-
2 #
3 # Template::Plugin::Format
4 #
5 # DESCRIPTION
6 #
7 #   Simple Template Toolkit Plugin which creates formatting functions.
8 #
9 # AUTHOR
10 #   Andy Wardley   <abw@wardley.org>
11 #
12 # COPYRIGHT
13 #   Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
14 #
15 #   This module is free software; you can redistribute it and/or
16 #   modify it under the same terms as Perl itself.
17 #
18 #============================================================================
19
20 package Template::Plugin::Format;
21
22 use strict;
23 use warnings;
24 use base 'Template::Plugin';
25
26 our $VERSION = 2.70;
27
28
29 sub new {
30     my ($class, $context, $format) = @_;;
31     return defined $format
32         ? make_formatter($format)
33         : \&make_formatter;
34 }
35
36
37 sub make_formatter {
38     my $format = shift;
39     $format = '%s' unless defined $format;
40     return sub { 
41         my @args = @_;
42         push(@args, '') unless @args;
43         return sprintf($format, @args); 
44     }
45 }
46
47
48 1;
49
50 __END__
51
52 =head1 NAME
53
54 Template::Plugin::Format - Plugin to create formatting functions
55
56 =head1 SYNOPSIS
57
58     [% USE format %]
59     [% commented = format('# %s') %]
60     [% commented('The cat sat on the mat') %]
61     
62     [% USE bold = format('<b>%s</b>') %]
63     [% bold('Hello') %]
64
65 =head1 DESCRIPTION
66
67 The format plugin constructs sub-routines which format text according to
68 a C<printf()>-like format string.
69
70 =head1 AUTHOR
71
72 Andy Wardley E<lt>abw@wardley.orgE<gt> L<http://wardley.org/>
73
74 =head1 COPYRIGHT
75
76 Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
77
78 This module is free software; you can redistribute it and/or
79 modify it under the same terms as Perl itself.
80
81 =head1 SEE ALSO
82
83 L<Template::Plugin>
84
85 =cut
86
87 # Local Variables:
88 # mode: perl
89 # perl-indent-level: 4
90 # indent-tabs-mode: nil
91 # End:
92 #
93 # vim: expandtab shiftwidth=4: