home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Format.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-30  |  2.8 KB  |  125 lines

  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@kfs.org>
  11. #
  12. # COPYRIGHT
  13. #   Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
  14. #   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
  15. #
  16. #   This module is free software; you can redistribute it and/or
  17. #   modify it under the same terms as Perl itself.
  18. #
  19. #----------------------------------------------------------------------------
  20. #
  21. # $Id: Format.pm,v 2.64 2004/01/13 16:20:38 abw Exp $
  22. #
  23. #============================================================================
  24.  
  25. package Template::Plugin::Format;
  26.  
  27. require 5.004;
  28.  
  29. use strict;
  30. use vars qw( @ISA $VERSION );
  31. use base qw( Template::Plugin );
  32. use Template::Plugin;
  33.  
  34. $VERSION = sprintf("%d.%02d", q$Revision: 2.64 $ =~ /(\d+)\.(\d+)/);
  35.  
  36.  
  37. sub new {
  38.     my ($class, $context, $format) = @_;;
  39.     return defined $format
  40.     ? make_formatter($format)
  41.     : \&make_formatter;
  42. }
  43.  
  44.  
  45. sub make_formatter {
  46.     my $format = shift;
  47.     $format = '%s' unless defined $format;
  48.     return sub { 
  49.     my @args = @_;
  50.     push(@args, '') unless @args;
  51.     return sprintf($format, @args); 
  52.     }
  53. }
  54.  
  55.  
  56. 1;
  57.  
  58. __END__
  59.  
  60.  
  61. #------------------------------------------------------------------------
  62. # IMPORTANT NOTE
  63. #   This documentation is generated automatically from source
  64. #   templates.  Any changes you make here may be lost.
  65. #   The 'docsrc' documentation source bundle is available for download
  66. #   from http://www.template-toolkit.org/docs.html and contains all
  67. #   the source templates, XML files, scripts, etc., from which the
  68. #   documentation for the Template Toolkit is built.
  69. #------------------------------------------------------------------------
  70.  
  71. =head1 NAME
  72.  
  73. Template::Plugin::Format - Plugin to create formatting functions
  74.  
  75. =head1 SYNOPSIS
  76.  
  77.     [% USE format %]
  78.     [% commented = format('# %s') %]
  79.     [% commented('The cat sat on the mat') %]
  80.     
  81.     [% USE bold = format('<b>%s</b>') %]
  82.     [% bold('Hello') %]
  83.  
  84. =head1 DESCRIPTION
  85.  
  86. The format plugin constructs sub-routines which format text according to
  87. a printf()-like format string.
  88.  
  89. =head1 AUTHOR
  90.  
  91. Andy Wardley E<lt>abw@andywardley.comE<gt>
  92.  
  93. L<http://www.andywardley.com/|http://www.andywardley.com/>
  94.  
  95.  
  96.  
  97.  
  98. =head1 VERSION
  99.  
  100. 2.64, distributed as part of the
  101. Template Toolkit version 2.13, released on 30 January 2004.
  102.  
  103. =head1 COPYRIGHT
  104.  
  105.   Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  106.   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  107.  
  108. This module is free software; you can redistribute it and/or
  109. modify it under the same terms as Perl itself.
  110.  
  111. =head1 SEE ALSO
  112.  
  113. L<Template::Plugin|Template::Plugin>
  114.  
  115. =cut
  116.  
  117. # Local Variables:
  118. # mode: perl
  119. # perl-indent-level: 4
  120. # indent-tabs-mode: nil
  121. # End:
  122. #
  123. # vim: expandtab shiftwidth=4:
  124.