line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# recurse2txt routines |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# version 1.03, 5-19-06, michael@bizsystems.com |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
#use strict; |
8
|
|
|
|
|
|
|
#use diagnostics; |
9
|
7
|
|
|
7
|
|
6657
|
use overload; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
71
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# generate a unique signature for a particular hash |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Data::Dumper actually does much more than this, however, it |
14
|
|
|
|
|
|
|
# does not stringify hash's in a consistent manner. i.e. no SORT |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# The routine below, while not covering recursion loops, non ascii |
17
|
|
|
|
|
|
|
# characters, etc.... does produce text that can be eval'd and is |
18
|
|
|
|
|
|
|
# consistent with each rendering. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
sub Dumper { |
21
|
18
|
50
|
|
18
|
|
12880
|
return "undef\n" unless defined $_[0]; |
22
|
18
|
|
|
|
|
50
|
my $ref = ref $_[0]; |
23
|
18
|
50
|
|
|
|
55
|
return "not a reference\n" unless $ref; |
24
|
18
|
50
|
66
|
|
|
100
|
unless ($ref eq 'HASH' or $ref eq 'ARRAY') { |
25
|
0
|
|
|
|
|
0
|
($ref) = (overload::StrVal($_[0]) =~ /^(?:.*\=)?([^=]*)\(/); |
26
|
|
|
|
|
|
|
} |
27
|
18
|
|
|
|
|
191
|
my $p = { |
28
|
|
|
|
|
|
|
depth => 0, |
29
|
|
|
|
|
|
|
elements => 0, |
30
|
|
|
|
|
|
|
}; |
31
|
18
|
|
|
|
|
51
|
bless $p,__PACKAGE__; |
32
|
18
|
|
|
|
|
25
|
my $data; |
33
|
18
|
100
|
|
|
|
62
|
if ($ref eq 'HASH') { |
|
|
50
|
|
|
|
|
|
34
|
10
|
|
|
|
|
53
|
$data = $p->hash_recurse($_[0],"\n"); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif ($ref eq 'ARRAY') { |
37
|
8
|
|
|
|
|
35
|
$data = $p->array_recurse($_[0]); |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
|
|
|
|
0
|
return $ref ." unsupported\n"; |
40
|
|
|
|
|
|
|
} |
41
|
18
|
|
|
|
|
310
|
$data =~ s/,\n$/;\n/; |
42
|
18
|
|
|
|
|
221
|
return $p->{elements} ."\t= ". $data; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# input: pointer to hash, terminator |
46
|
|
|
|
|
|
|
# returns: data |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
sub hash_recurse { |
49
|
45
|
|
|
45
|
|
159
|
my($p,$ptr,$n) = @_; |
50
|
45
|
50
|
|
|
|
107
|
$n = '' unless $n; |
51
|
45
|
|
|
|
|
81
|
my $data = "{\n"; |
52
|
45
|
|
|
|
|
200
|
foreach my $key (sort keys %$ptr) { |
53
|
121
|
|
|
|
|
246
|
$data .= "\t'". $key ."'\t=> "; |
54
|
121
|
|
|
|
|
650
|
$data .= _dump($p,$ptr->{$key},"\n"); |
55
|
|
|
|
|
|
|
} |
56
|
45
|
|
|
|
|
161
|
$data .= '},'.$n; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# generate a unique signature for a particular array |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# input: pointer to array, terminator |
62
|
|
|
|
|
|
|
# returns: data |
63
|
|
|
|
|
|
|
sub array_recurse { |
64
|
8
|
|
|
8
|
|
13
|
my($p,$ptr,$n) = @_; |
65
|
8
|
50
|
|
|
|
22
|
$n = '' unless $n; |
66
|
8
|
|
|
|
|
10
|
my $data = '['; |
67
|
8
|
|
|
|
|
16
|
foreach my $item (@$ptr) { |
68
|
148
|
|
|
|
|
245
|
$data .= _dump($p,$item); |
69
|
|
|
|
|
|
|
} |
70
|
8
|
|
|
|
|
26
|
$data .= "],\n"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# input: self, item, append |
74
|
|
|
|
|
|
|
# return: data |
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
sub _dump { |
77
|
269
|
|
|
269
|
|
519
|
my($p,$item,$n) = @_; |
78
|
269
|
|
|
|
|
615
|
$p->{elements}++; |
79
|
269
|
100
|
|
|
|
531
|
$n = '' unless $n; |
80
|
269
|
|
|
|
|
347
|
my $ref = ref $item; |
81
|
269
|
100
|
|
|
|
1030
|
if ($ref eq 'HASH') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
82
|
35
|
|
|
|
|
96
|
return tabout($p->hash_recurse($item,"\n")); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif($ref eq 'ARRAY') { |
85
|
0
|
|
|
|
|
0
|
return $p->array_recurse($item,$n); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif($ref eq 'SCALAR') { |
88
|
0
|
|
|
|
|
0
|
return q|\$SCALAR,|.$n; |
89
|
|
|
|
|
|
|
} |
90
|
234
|
|
|
|
|
299
|
elsif ($ref eq 'GLOB') { |
91
|
0
|
|
|
|
|
0
|
my $g = *{$item}; |
|
0
|
|
|
|
|
0
|
|
92
|
0
|
|
|
|
|
0
|
return "\\$g" .','.$n; |
93
|
|
|
|
|
|
|
} |
94
|
234
|
|
|
|
|
965
|
elsif(do {my $g = \$item; ref $g eq 'GLOB'}) { |
95
|
0
|
|
|
|
|
0
|
return "$item" .','.$n; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif($ref eq 'CODE') { |
98
|
0
|
|
|
|
|
0
|
return q|sub {'DUMMY'},|.$n; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
elsif (defined $item) { |
101
|
234
|
|
|
|
|
401
|
return wrap_data($item) .','.$n; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
0
|
return 'undef,'.$n; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub tabout { |
109
|
35
|
|
|
35
|
|
146
|
my @data = split(/\n/,shift); |
110
|
35
|
|
|
|
|
59
|
my $data = shift @data; |
111
|
35
|
|
|
|
|
51
|
$data .= "\n"; |
112
|
35
|
|
|
|
|
61
|
foreach(@data) { |
113
|
97
|
|
|
|
|
200
|
$data .= "\t$_\n"; |
114
|
|
|
|
|
|
|
} |
115
|
35
|
|
|
|
|
362
|
$data; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub wrap_data { |
119
|
234
|
|
|
234
|
|
282
|
my $data = shift; |
120
|
234
|
100
|
100
|
|
|
1779
|
return ($data =~ /\D/ || $data =~ /^$/) |
121
|
|
|
|
|
|
|
? q|'|. $data .q|'| |
122
|
|
|
|
|
|
|
: $data; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |