blib/lib/Template/Plugin/Dumper.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 55 CC 3 SCAR 16.1
CC
3
Cov
0%
get_dump_obj
12.0
new
2.0
dump
2.0
CRAP 5.0
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 = '3.100';
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 Sortkeys );
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  
44 bless {
45 _CONTEXT => $context,
46 params => $params || {},
47 }, $class;
48 }
49  
50 sub get_dump_obj {
51 my $self = shift;
52  
53 my $dumper_obj = Data::Dumper->new( \@_ );
54  
55 my $params = $self->{ params };
56  
57 foreach my $arg ( @DUMPER_ARGS ) {
58 my $val = exists $params->{ lc $arg } ? $params->{ lc $arg }
59 : $params->{ $arg };
60  
61 $dumper_obj->$arg( $val ) if defined $val;
62 }
63  
64 return $dumper_obj;
65 }
66  
67 sub dump { scalar shift->get_dump_obj( @_ )->Dump() }
68  
69 sub dump_html {
70 my $self = shift;
71  
72 my $content = $self->dump( @_ );
73  
74 for ($content) {
75 s/&/&amp;/g;
76 s/</&lt;/g;
77 s/>/&gt;/g;
78 s/\n/<br>\n/g;
79 }
80  
81 return $content;
82 }
83  
84 1;
85  
86 __END__