File Coverage

blib/lib/Data/HTMLDumper.pm
Criterion Covered Total %
statement 33 39 84.6
branch 3 4 75.0
condition n/a
subroutine 10 12 83.3
pod 0 4 0.0
total 46 59 77.9


line stmt bran cond sub pod time code
1             package Data::HTMLDumper;
2 10     10   269814 use strict; use warnings;
  10     10   26  
  10         527  
  10         59  
  10         23  
  10         1908  
3              
4             require Exporter;
5              
6             our @ISA = qw(Exporter);
7              
8             our %EXPORT_TAGS = ( 'all' => [ qw(
9             Dumper
10             ) ] );
11              
12             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
13              
14             our @EXPORT = qw(
15             Dumper
16             );
17              
18             our $VERSION = '0.08';
19              
20 10     10   9325 use Data::HTMLDumper::Output;
  10         27  
  10         297  
21 10     10   13332 use Data::Dumper ();
  10         135701  
  10         299  
22 10     10   27443 use Parse::RecDescent;
  10         594783  
  10         90  
23              
24             our $actions = new Data::HTMLDumper::Output();
25             our $Maxdepth;
26             our $Varname;
27             our $Sortkeys;
28              
29             tie $Maxdepth, 'SpecialVars', \$Data::Dumper::Maxdepth;
30             tie $Varname, 'SpecialVars', \$Data::Dumper::Varname;
31             tie $Sortkeys, 'SpecialVars', \$Data::Dumper::Sortkeys;
32              
33             sub actions {
34 273     273 0 332342 my $class = shift;
35 273         354 my $new_val = shift;
36              
37 273 100       607 $actions = $new_val if (defined $new_val);
38 273         1457 return $actions;
39             }
40              
41             #$::RD_HINT = 1;
42             #$::RD_TRACE = 1;
43              
44             my $grammar = q{
45             { our $actions = sub { return Data::HTMLDumper::actions(); } }
46             output : expression(s) { &{$actions}->output($item[1]) }
47              
48             expression : SIGIL ID_NAME '=' item ';' {
49             &{$actions}->expression(%item);
50             }
51             |
52              
53             item : value COMMA(?) { &{$actions}->item_value ($item{value},
54             $arg[0]) }
55             | array COMMA(?) { &{$actions}->item_array ($item{array}) }
56             | hash COMMA(?) { &{$actions}->item_hash ($item{hash} ) }
57             | object COMMA(?) { &{$actions}->item_object($item{object})}
58             | inside_out_object COMMA(?) {
59             &{$actions}->item_inside_out_object(
60             $item{inside_out_object}
61             );
62             }
63              
64             array : '[' item(s) ']' { &{$actions}->array($item{'item(s)'}) }
65             | '[' ']' { &{$actions}->array_empty() }
66              
67             hash : '{' pair(s) '}' { &{$actions}->hash($item{'pair(s)'}) }
68             | '{' '}' { &{$actions}->hash_empty() }
69              
70             pair : string '=>' item['make_row'] {
71             &{$actions}->pair($item{string}, $item{item});
72             }
73              
74             object : 'bless(' item string ')' {
75             &{$actions}->object($item{item}, $item{string});
76             }
77              
78             inside_out_object : 'bless(' do_block COMMA string ')' {
79             &{$actions}->inside_out_object($item{do_block}, $item{string});
80             }
81              
82             do_block : 'do' '{' NOT_BRACE '}' { $item{NOT_BRACE}; }
83              
84             NOT_BRACE : /[^\}]*/ { $item[1]; }
85              
86             value : string | NUMBER | 'undef'
87            
88             string : TICK text TICK { &{$actions}->string($item{text}) }
89              
90             KEY_NAME : /[.\w\d_]+/
91              
92             ID_NAME : /\w[\w\d_]*/
93              
94             NUMBER : /[+-]?(\d\.?\d*|\d*.\d+)/
95              
96             SIGIL : '$' | '@' | '%'
97              
98             text : text_letter(s) {local $" = "", "@{$item{'text_letter(s)'}}" }
99              
100             text_letter : ESCAPED_TICK
101             | NON_TICK
102            
103             NON_TICK : /[^'\\\]*/
104              
105             ESCAPED_TICK : /(\\\')/ { "'" }
106              
107             COMMA : ','
108              
109             TICK : "'"
110             };
111              
112             # do_block : 'do' '{' /[^}]*/ '}' { $item[3]; }
113              
114             my $parse = new Parse::RecDescent($grammar);
115              
116             sub Dumper {
117 18     18 0 8561 my $original_output = Data::Dumper::Dumper(@_);
118 18         2115 my $output = $parse->output($original_output);
119 18         912 return $output;
120             }
121              
122             sub new {
123 0     0 0 0 my $class = shift;
124 0         0 my $dumper = Data::Dumper->new(@_);
125              
126 0         0 return bless {dumper => $dumper}, $class;
127             }
128              
129             sub Dump {
130 1     1 0 2 my $invocant = shift;
131 1         2 my $original_output;
132             my $output;
133              
134 1 50       5 if (ref $invocant) { $original_output = $invocant->{dumper}->Dump(@_); }
  0         0  
135 1         36 else { $original_output = Data::Dumper->Dump(@_); }
136              
137 1         120 return $parse->output($original_output);
138             }
139              
140             package SpecialVars;
141              
142             sub TIESCALAR {
143 30     30   212 my $class = shift;
144 30         56 my $dumper_var = shift;
145              
146 30         86 return bless $dumper_var, $class;
147             }
148              
149             sub FETCH {
150 0     0   0 my $self = shift;
151              
152 0         0 return $$self;
153             }
154              
155             sub STORE {
156 1     1   14 my $self = shift;
157 1         2 my $value = shift;
158              
159 1         9 $$self = $value;
160             }
161              
162             1;
163             __END__