File Coverage

blib/lib/HTML/Template/Dumper/Data_Dumper.pm
Criterion Covered Total %
statement 23 24 95.8
branch 3 6 50.0
condition 2 4 50.0
subroutine 6 6 100.0
pod 0 2 0.0
total 34 42 80.9


line stmt bran cond sub pod time code
1              
2             =head1 COPYRIGHT
3              
4             Copyright 2003, American Society of Agronomy. All rights reserved.
5              
6             This program is free software; you can redistribute it and/or modify
7             it under the terms of either:
8              
9             a) the GNU General Public License as published by the Free Software
10             Foundation; either version 2, or (at your option) any later version, or
11              
12             b) the "Artistic License" which comes with Perl.
13              
14             =cut
15              
16              
17             package HTML::Template::Dumper::Data_Dumper;
18 2     2   7673 use strict;
  2         9  
  2         69  
19 2     2   13 use warnings;
  2         4  
  2         61  
20 2     2   3338 use Data::Dumper;
  2         20289  
  2         176  
21 2     2   21 use base 'HTML::Template::Dumper::Format';
  2         4  
  2         1122  
22              
23             our $VERSION = 0.1;
24              
25              
26             #
27             # Code taken from Data::Serializer::Data::Dumper
28             #
29             sub dump
30             {
31              
32 21     21 0 25 my $self = shift;
33 21   50     46 my $val = shift || return;
34 21         30 local $Data::Dumper::Indent = 0;
35 21         21 local $Data::Dumper::Purity = 1;
36 21         23 local $Data::Dumper::Terse = 1;
37 21         43 return Data::Dumper::Dumper($val);
38             }
39              
40             sub parse
41             {
42 1     1 0 12 my $self = shift;
43 1   50     4 my $val = shift || return;
44 1         5 my $M = "";
45             # Disambiguate hashref (perl may treat it as a block)
46 1 50       164 my $N = eval($val =~ /^\{/ ? '+'.$val : $val);
47 1 50       13 return $M ? $M : $N unless $@;
    50          
48 0           die "HTML::Template::Dumper::Data_Dumper error: $@" .
49             "\twhile evaluating:\n $val";
50             }
51              
52             # avoid used only once warnings
53             {
54             local $Data::Dumper::Terse;
55             }
56              
57             1;
58             __END__