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 / Dumper.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-30  |  4.4 KB  |  180 lines

  1. #==============================================================================
  2. # Template::Plugin::Dumper
  3. #
  4. # DESCRIPTION
  5. #
  6. # A Template Plugin to provide a Template Interface to Data::Dumper
  7. #
  8. # AUTHOR
  9. #   Simon Matthews <sam@knowledgepool.com>
  10. #
  11. # COPYRIGHT
  12. #
  13. #   Copyright (C) 2000 Simon Matthews.  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. # $Id: Dumper.pm,v 2.64 2004/01/13 16:20:38 abw Exp $
  21. #==============================================================================
  22.  
  23. package Template::Plugin::Dumper;
  24.  
  25. require 5.004;
  26.  
  27. use strict;
  28. use Template::Plugin;
  29. use Data::Dumper;
  30.  
  31. use vars qw( $VERSION $DEBUG @DUMPER_ARGS $AUTOLOAD );
  32. use base qw( Template::Plugin );
  33.  
  34. $VERSION = sprintf("%d.%02d", q$Revision: 2.64 $ =~ /(\d+)\.(\d+)/);
  35. $DEBUG   = 0 unless defined $DEBUG;
  36. @DUMPER_ARGS = qw( Indent Pad Varname Purity Useqq Terse Freezer
  37.                    Toaster Deepcopy Quotekeys Bless Maxdepth );
  38.  
  39. #==============================================================================
  40. #                      -----  CLASS METHODS -----
  41. #==============================================================================
  42.  
  43. #------------------------------------------------------------------------
  44. # new($context, \@params)
  45. #------------------------------------------------------------------------
  46.  
  47. sub new {
  48.     my ($class, $context, $params) = @_;
  49.     my ($key, $val);
  50.     $params ||= { };
  51.  
  52.  
  53.     foreach my $arg (@DUMPER_ARGS) {
  54.     no strict 'refs';
  55.     if (defined ($val = $params->{ lc $arg })
  56.         or defined ($val = $params->{ $arg })) {
  57.         ${"Data\::Dumper\::$arg"} = $val;
  58.     }
  59.     }
  60.  
  61.     bless { 
  62.     _CONTEXT => $context, 
  63.     }, $class;
  64. }
  65.  
  66. sub dump {
  67.     my $self = shift;
  68.     my $content = Dumper @_;
  69.     return $content;
  70. }
  71.  
  72.  
  73. sub dump_html {
  74.     my $self = shift;
  75.     my $content = Dumper @_;
  76.     for ($content) {
  77.     s/&/&/g;
  78.     s/</</g;
  79.     s/>/>/g;
  80.     s/\n/<br>\n/g;
  81.     }
  82.     return $content;
  83. }
  84.  
  85. 1;
  86.  
  87. __END__
  88.  
  89.  
  90. #------------------------------------------------------------------------
  91. # IMPORTANT NOTE
  92. #   This documentation is generated automatically from source
  93. #   templates.  Any changes you make here may be lost.
  94. #   The 'docsrc' documentation source bundle is available for download
  95. #   from http://www.template-toolkit.org/docs.html and contains all
  96. #   the source templates, XML files, scripts, etc., from which the
  97. #   documentation for the Template Toolkit is built.
  98. #------------------------------------------------------------------------
  99.  
  100. =head1 NAME
  101.  
  102. Template::Plugin::Dumper - Plugin interface to Data::Dumper
  103.  
  104. =head1 SYNOPSIS
  105.  
  106.     [% USE Dumper %]
  107.  
  108.     [% Dumper.dump(variable) %]
  109.     [% Dumper.dump_html(variable) %]
  110.  
  111. =head1 DESCRIPTION
  112.  
  113. This is a very simple Template Toolkit Plugin Interface to the Data::Dumper
  114. module.  A Dumper object will be instantiated via the following directive:
  115.  
  116.     [% USE Dumper %]
  117.  
  118. As a standard plugin, you can also specify its name in lower case:
  119.  
  120.     [% USE dumper %]
  121.  
  122. The Data::Dumper 'Pad', 'Indent' and 'Varname' options are supported
  123. as constructor arguments to affect the output generated.  See L<Data::Dumper>
  124. for further details.
  125.  
  126.     [% USE dumper(Indent=0, Pad="<br>") %]
  127.  
  128. These options can also be specified in lower case.
  129.  
  130.     [% USE dumper(indent=0, pad="<br>") %]
  131.  
  132. =head1 METHODS
  133.  
  134. There are two methods supported by the Dumper object.  Each will
  135. output into the template the contents of the variables passed to the
  136. object method.
  137.  
  138. =head2 dump()
  139.  
  140. Generates a raw text dump of the data structure(s) passed
  141.  
  142.     [% USE Dumper %]
  143.     [% Dumper.dump(myvar) %]
  144.     [% Dumper.dump(myvar, yourvar) %]
  145.  
  146. =head2 dump_html()
  147.  
  148. Generates a dump of the data structures, as per dump(), but with the 
  149. characters E<lt>, E<gt> and E<amp> converted to their equivalent HTML
  150. entities and newlines converted to E<lt>brE<gt>.
  151.  
  152.     [% USE Dumper %]
  153.     [% Dumper.dump_html(myvar) %]
  154.  
  155. =head1 AUTHOR
  156.  
  157. Simon Matthews E<lt>sam@knowledgepool.comE<gt>
  158.  
  159. =head1 VERSION
  160.  
  161. 2.64, distributed as part of the
  162. Template Toolkit version 2.13, released on 30 January 2004.
  163.  
  164.  
  165.  
  166. =head1 COPYRIGHT
  167.  
  168. Copyright (C) 2000 Simon Matthews All Rights Reserved.
  169.  
  170. This module is free software; you can redistribute it and/or
  171. modify it under the same terms as Perl itself.
  172.  
  173. =head1 SEE ALSO
  174.  
  175. L<Template::Plugin|Template::Plugin>, L<Data::Dumper|Data::Dumper>
  176.  
  177.