| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Any::Renderer::Data::Dumper; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Dumper.pm,v 1.9 2006/08/23 19:41:16 johna Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
32164
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
78
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use vars qw($VERSION); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
75
|
|
|
7
|
2
|
|
|
2
|
|
2306
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
16945
|
|
|
|
2
|
|
|
|
|
228
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = sprintf"%d.%03d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/; |
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
23
|
use constant FORMAT_NAME => 'Data::Dumper'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
771
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
|
14
|
|
|
|
|
|
|
{ |
|
15
|
7
|
|
|
7
|
1
|
1031
|
my ( $class, $format, $options ) = @_; |
|
16
|
7
|
100
|
|
|
|
32
|
die("Invalid format $format") unless($format eq FORMAT_NAME); |
|
17
|
|
|
|
|
|
|
|
|
18
|
6
|
|
50
|
|
|
17
|
$options ||= {}; |
|
19
|
6
|
|
|
|
|
26
|
my $self = { |
|
20
|
|
|
|
|
|
|
'options' => $options, |
|
21
|
|
|
|
|
|
|
'varname' => delete $options->{VariableName}, |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
6
|
|
100
|
|
|
37
|
$options->{DumperOptions} ||= {}; |
|
25
|
6
|
|
|
|
|
8
|
foreach my $opt(keys %{$options->{DumperOptions}}) { |
|
|
6
|
|
|
|
|
22
|
|
|
26
|
2
|
100
|
|
|
|
39
|
die("Data::Dumper does not support a $opt method") unless(Data::Dumper->can($opt)); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
15
|
bless $self, $class; |
|
30
|
|
|
|
|
|
|
|
|
31
|
5
|
|
|
|
|
16
|
return $self; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub render |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
11
|
|
|
11
|
1
|
1587
|
my ( $self, $data ) = @_; |
|
37
|
|
|
|
|
|
|
|
|
38
|
11
|
|
|
|
|
29
|
TRACE ( "Rendering w/Data::Dumper" ); |
|
39
|
11
|
|
|
|
|
25
|
DUMP ( $data ); |
|
40
|
|
|
|
|
|
|
|
|
41
|
11
|
|
|
|
|
70
|
my $o = Data::Dumper->new([ $data ], [ $self->{ 'varname' } ]); |
|
42
|
11
|
|
|
|
|
300
|
$o->Sortkeys(1); |
|
43
|
11
|
|
|
|
|
59
|
foreach my $opt(keys %{$self->{options}{DumperOptions}}) { |
|
|
11
|
|
|
|
|
42
|
|
|
44
|
1
|
|
|
|
|
7
|
$o->$opt($self->{options}{DumperOptions}{$opt}); #Fire corresponding methods |
|
45
|
|
|
|
|
|
|
} |
|
46
|
11
|
|
|
|
|
45
|
return $o->Dump(); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub requires_template |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
2
|
|
|
2
|
1
|
23624
|
return 0; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub available_formats |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
3
|
|
|
3
|
1
|
509
|
return [ FORMAT_NAME ]; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
11
|
|
|
11
|
0
|
12
|
sub TRACE {} |
|
60
|
11
|
|
|
11
|
0
|
12
|
sub DUMP {} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Any::Renderer::Data::Dumper - render data structures through Data::Dumper |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Any::Renderer; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my %options = ('DumperOptions' => {'Indent' => 1}); |
|
73
|
|
|
|
|
|
|
my $format = "Data::Dumper"; |
|
74
|
|
|
|
|
|
|
my $r = new Any::Renderer ( $format, \%options ); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $data_structure = [...]; # arbitrary structure |
|
77
|
|
|
|
|
|
|
my $string = $r->render ( $data_structure ); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Any::Renderer::Data::Dumper renders any Perl data structure passed to it into |
|
82
|
|
|
|
|
|
|
a string representation via Data::Dumper. For example: |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
perl -MAny::Renderer -e "print Any::Renderer->new('Data::Dumper')->render({a => 1, b => [2,3]})" |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
results in: |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$VAR1 = { |
|
89
|
|
|
|
|
|
|
'a' => 1, |
|
90
|
|
|
|
|
|
|
'b' => [ |
|
91
|
|
|
|
|
|
|
2, |
|
92
|
|
|
|
|
|
|
3 |
|
93
|
|
|
|
|
|
|
] |
|
94
|
|
|
|
|
|
|
}; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 FORMATS |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over 4 |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item Data::Dumper |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 METHODS |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item $r = new Any::Renderer::Data::Dumper($format, \%options) |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
C<$format> must be C. |
|
111
|
|
|
|
|
|
|
See L for a description of valid C<%options>. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item $string = $r->render($data_structure) |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The main method. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item $bool = Any::Renderer::Data::Dumper::requires_template($format) |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
False in this case. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item $list_ref = Any::Renderer::Data::Dumper::available_formats() |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Just the one - C. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 OPTIONS |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over 4 |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item VariableName |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Name of the perl variable the structure is assigned to. Defaults to C<$VAR1>. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item DumperOptions |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This hashref of options is mapped to Data::Dumper methods (Indent, Purity, Useqq, etc.). For example: |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
perl -MAny::Renderer -e "print Any::Renderer->new('Data::Dumper', {DumperOptions => {Indent=>0}})->render({a => 1, b => [2,3]})" |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
results in: |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$VAR1 = {'a' => 1,'b' => [2,3]}; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
See L for the list of I. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L, L |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 VERSION |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$Revision: 1.9 $ on $Date: 2006/08/23 19:41:16 $ by $Author: johna $ |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 AUTHOR |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Matt Wilson and John Alden |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
(c) BBC 2006. This program is free software; you can redistribute it and/or modify it under the GNU GPL. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |