Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / Template / Plugin / Dumper.pm
1 #==============================================================================
2
3 # Template::Plugin::Dumper
4 #
5 # DESCRIPTION
6 #
7 # A Template Plugin to provide a Template Interface to Data::Dumper
8 #
9 # AUTHOR
10 #   Simon Matthews <sam@tt2.org>
11 #
12 # COPYRIGHT
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 package Template::Plugin::Dumper;
21
22 use strict;
23 use warnings;
24 use base 'Template::Plugin';
25 use Data::Dumper;
26
27 our $VERSION = 2.70;
28 our $DEBUG   = 0 unless defined $DEBUG;
29 our @DUMPER_ARGS = qw( Indent Pad Varname Purity Useqq Terse Freezer
30                        Toaster Deepcopy Quotekeys Bless Maxdepth );
31 our $AUTOLOAD;
32
33 #==============================================================================
34 #                      -----  CLASS METHODS -----
35 #==============================================================================
36
37 #------------------------------------------------------------------------
38 # new($context, \@params)
39 #------------------------------------------------------------------------
40
41 sub new {
42     my ($class, $context, $params) = @_;
43     my ($key, $val);
44     $params ||= { };
45
46
47     foreach my $arg (@DUMPER_ARGS) {
48         no strict 'refs';
49         if (defined ($val = $params->{ lc $arg })
50             or defined ($val = $params->{ $arg })) {
51             ${"Data\::Dumper\::$arg"} = $val;
52         }
53     }
54
55     bless { 
56         _CONTEXT => $context, 
57     }, $class;
58 }
59
60 sub dump {
61     my $self = shift;
62     my $content = Dumper @_;
63     return $content;
64 }
65
66
67 sub dump_html {
68     my $self = shift;
69     my $content = Dumper @_;
70     for ($content) {
71         s/&/&amp;/g;
72         s/</&lt;/g;
73         s/>/&gt;/g;
74         s/\n/<br>\n/g;
75     }
76     return $content;
77 }
78
79 1;
80
81 __END__
82
83 =head1 NAME
84
85 Template::Plugin::Dumper - Plugin interface to Data::Dumper
86
87 =head1 SYNOPSIS
88
89     [% USE Dumper %]
90     
91     [% Dumper.dump(variable) %]
92     [% Dumper.dump_html(variable) %]
93
94 =head1 DESCRIPTION
95
96 This is a very simple Template Toolkit Plugin Interface to the L<Data::Dumper>
97 module.  A C<Dumper> object will be instantiated via the following directive:
98
99     [% USE Dumper %]
100
101 As a standard plugin, you can also specify its name in lower case:
102
103     [% USE dumper %]
104
105 The C<Data::Dumper> C<Pad>, C<Indent> and C<Varname> options are supported
106 as constructor arguments to affect the output generated.  See L<Data::Dumper>
107 for further details.
108
109     [% USE dumper(Indent=0, Pad="<br>") %]
110
111 These options can also be specified in lower case.
112
113     [% USE dumper(indent=0, pad="<br>") %]
114
115 =head1 METHODS
116
117 There are two methods supported by the C<Dumper> object.  Each will
118 output into the template the contents of the variables passed to the
119 object method.
120
121 =head2 dump()
122
123 Generates a raw text dump of the data structure(s) passed
124
125     [% USE Dumper %]
126     [% Dumper.dump(myvar) %]
127     [% Dumper.dump(myvar, yourvar) %]
128
129 =head2 dump_html()
130
131 Generates a dump of the data structures, as per L<dump()>, but with the 
132 characters E<lt>, E<gt> and E<amp> converted to their equivalent HTML
133 entities and newlines converted to E<lt>brE<gt>.
134
135     [% USE Dumper %]
136     [% Dumper.dump_html(myvar) %]
137
138 =head1 AUTHOR
139
140 Simon Matthews E<lt>sam@tt2.orgE<gt>
141
142 =head1 COPYRIGHT
143
144 Copyright (C) 2000 Simon Matthews.  All Rights Reserved.
145
146 This module is free software; you can redistribute it and/or
147 modify it under the same terms as Perl itself.
148
149 =head1 SEE ALSO
150
151 L<Template::Plugin>, L<Data::Dumper>
152