blib/lib/Template/Plugin/Dumpvar.pm

filter: Statementstmt 64.0% 16 / 25 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 56.8% 25 / 44 CC 3 SCAR 10.7
CC
3
Cov
53%
new
6.0
dump_html
6.0
dump
2.0
CRAP 2.9
↑ Summary
1 package Template::Plugin::Dumpvar;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Template::Plugin::Dumpvar - Dump template data in the same style as the
8 debugger
9  
10 =head1 SYNOPSIS
11  
12 [% USE Dumpvar %]
13
14 [% Dumpvar.dump(this) %]
15 [% Dumpvar.dump_html(theother) %]
16  
17 =head1 DESCRIPTION
18  
19 When dumping data in templates, the obvious first choice is to use the
20 L<Data::Dumper> plugin L<Template::Plugin::Dumper>. But personally, I think
21 the layout is ugly and hard to read. It's designed to be parsed back in by
22 perl, not to necesarily be easy on the eye.
23  
24 The dump style used in the debugger, however, IS designed to be easier on
25 the eye. The dumpvar.pl script it uses to do this has been cloned for general
26 use as L<Devel::Dumpvar>. This module is a drop in replacement for
27 Template::Plugin::Dumper that uses Devel::Dumpvar in place of Data::Dumper.
28  
29 The only difference is that this module only dumps one scalar, reference, or
30 object at a time.
31  
32 =head1 METHODS
33  
34 =cut
35  
36 1 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use Devel::Dumpvar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use base 'Template::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 $VERSION = '1.03';
44 }
45  
46  
47  
48  
49  
50 #####################################################################
51 # Constructor
52  
53 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
54 0 ▶ my $class = ref $_[0] || $_[0];
Condition0%0/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
55 0 bless {
56 Dumpvar => Devel::Dumpvar->new( to => 'return' ),
57 }, $class;
58 }
59  
60 =pod
61  
62 =head2 dump $something
63  
64 Dumps a single structure via L<Devel::Dumpvar>. Does not escape for HTML.
65  
66 =cut
67  
68 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod documented
69 0 $_[0]->{Dumpvar}->dump( $_[1] );
70 }
71  
72 =pod
73  
74 =head2 dump_html $something
75  
76 As above, but also escapes and formats for HTML
77  
78 =cut
79  
80 0 ▶sub dump_html {
Subroutine dump_html: not called CC=2 SCAR=17.9
Pod documented
81 0 ▶ $_ = $_[0]->dump($_[1]) or return $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ = $_[0]->dump($_[1]) or return $_ 0 0 0
82  
83 # Escape for HTML
84 0 s/&/&amp;/g;
85 0 s/</&lt;/g;
86 0 s/>/&gt;/g;
87 0 s/\n/<br>\n/g;
88  
89 0 $_;
90 }
91  
92 1 1;
93  
94 =pod
95  
96 =head1 SUPPORT
97  
98 Bugs should be submitted via the CPAN bug tracker, located at
99  
100 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Plugin-Dumpvar>
101  
102 For other issues, or commercial enhancement or support, contact the author.
103  
104 =head1 AUTHOR
105  
106 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
107  
108 =head1 COPYRIGHT
109  
110 Copyright 2004 - 2008 Adam Kennedy.
111  
112 This program is free software; you can redistribute
113 it and/or modify it under the same terms as Perl itself.
114  
115 The full text of the license can be found in the
116 LICENSE file included with this module.
117  
118 =cut
↑ Summary