line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Session::Serialize::DataDumper; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1593
|
use parent 'Data::Session::Base'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
15
|
|
4
|
2
|
|
|
2
|
|
138
|
no autovivification; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
5
|
2
|
|
|
2
|
|
91
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
65
|
|
6
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
4052
|
use Data::Dumper; |
|
2
|
|
|
|
|
23294
|
|
|
2
|
|
|
|
|
183
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
2728
|
use Safe; |
|
2
|
|
|
|
|
98264
|
|
|
2
|
|
|
|
|
435
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
26
|
use Scalar::Util qw(blessed reftype refaddr); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
382
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
13
|
use vars qw( %overloaded ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
6045
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
require overload; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.16'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ----------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub freeze |
23
|
|
|
|
|
|
|
{ |
24
|
24
|
|
|
24
|
0
|
43
|
my($self, $data) = @_; |
25
|
24
|
|
|
|
|
241
|
my($d) = Data::Dumper -> new([$data], ["D"]); |
26
|
|
|
|
|
|
|
|
27
|
24
|
|
|
|
|
973
|
$d -> Deepcopy(0); |
28
|
24
|
|
|
|
|
212
|
$d -> Indent(0); |
29
|
24
|
|
|
|
|
274
|
$d -> Purity(1); |
30
|
24
|
|
|
|
|
164
|
$d -> Quotekeys(1); |
31
|
24
|
|
|
|
|
174
|
$d -> Terse(0); |
32
|
24
|
|
|
|
|
159
|
$d -> Useqq(0); |
33
|
|
|
|
|
|
|
|
34
|
24
|
|
|
|
|
174
|
return $d ->Dump; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} # End of freeze. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# ----------------------------------------------- |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new |
41
|
|
|
|
|
|
|
{ |
42
|
53
|
|
|
53
|
1
|
148
|
my($class) = @_; |
43
|
|
|
|
|
|
|
|
44
|
53
|
|
|
|
|
392
|
return bless({}, $class); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} # End of new. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# ----------------------------------------------- |
49
|
|
|
|
|
|
|
# We need to do this because the values we get back from the safe compartment |
50
|
|
|
|
|
|
|
# will have packages defined from the safe compartment's *main instead of |
51
|
|
|
|
|
|
|
# the one we use. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _scan |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
# $_ gets aliased to each value from @_ which are aliases of the values in |
56
|
|
|
|
|
|
|
# the current data structure. |
57
|
|
|
|
|
|
|
|
58
|
26
|
|
|
26
|
|
80
|
for (@_) |
59
|
|
|
|
|
|
|
{ |
60
|
26
|
50
|
|
|
|
149
|
if (blessed $_) |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
0
|
|
|
|
0
|
if (overload::Overloaded($_) ) |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
|
|
0
|
my($address) = refaddr $_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# If we already rebuilt and reblessed this item, use the cached |
67
|
|
|
|
|
|
|
# copy so our ds is consistent with the one we serialized. |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
0
|
if (exists $overloaded{$address}) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
0
|
$_ = $overloaded{$address}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
|
|
0
|
my($reftype) = reftype $_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
0
|
|
|
0
|
if ($reftype eq "HASH") |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
0
|
$_ = $overloaded{$address} = bless { %$_ }, ref $_; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif ($reftype eq "ARRAY") |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
0
|
$_ = $overloaded{$address} = bless [ @$_ ], ref $_; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ($reftype eq "SCALAR" || $reftype eq "REF") |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
|
|
0
|
$_ = $overloaded{$address} = bless \do{my $o = $$_}, ref $_; |
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
|
|
0
|
die __PACKAGE__ . ". Do not know how to reconstitute blessed object of base type $reftype"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
0
|
bless $_, ref $_; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
26
|
|
|
|
|
82
|
return @_; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} # End of _scan. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# ----------------------------------------------- |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub thaw |
109
|
|
|
|
|
|
|
{ |
110
|
26
|
|
|
26
|
0
|
56
|
my($self, $data) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# To make -T happy. |
113
|
|
|
|
|
|
|
|
114
|
26
|
|
|
|
|
173
|
my($safe_string) = $data =~ m/^(.*)$/s; |
115
|
26
|
|
|
|
|
254
|
my($rv) = Safe -> new -> reval($safe_string); |
116
|
|
|
|
|
|
|
|
117
|
26
|
50
|
|
|
|
56716
|
if ($@) |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
|
|
|
|
0
|
die __PACKAGE__ . ". Couldn't thaw. $@"; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
26
|
|
|
|
|
2952
|
_walk($rv); |
123
|
|
|
|
|
|
|
|
124
|
26
|
|
|
|
|
101
|
return $rv; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} # End of thaw. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# ----------------------------------------------- |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _walk |
131
|
|
|
|
|
|
|
{ |
132
|
26
|
|
|
26
|
|
100
|
my(@filter) = _scan(shift); |
133
|
|
|
|
|
|
|
|
134
|
26
|
|
|
|
|
55
|
local %overloaded; |
135
|
|
|
|
|
|
|
|
136
|
26
|
|
|
|
|
35
|
my(%seen); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# We allow the value assigned to a key to be undef. |
139
|
|
|
|
|
|
|
# Hence the defined() test is not in the while(). |
140
|
|
|
|
|
|
|
|
141
|
26
|
|
|
|
|
159
|
while (@filter) |
142
|
|
|
|
|
|
|
{ |
143
|
26
|
50
|
|
|
|
161
|
defined(my $x = shift @filter) or next; |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
0
|
|
|
|
$seen{refaddr $x || ''}++ and next; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# The original syntax my($r) = reftype($x) or next led to if ($r...) |
148
|
|
|
|
|
|
|
# issuing an uninit warning when $r was undef. |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
0
|
|
|
|
my($r) = reftype($x) || next; |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
0
|
|
|
|
if ($r eq "HASH") |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
# We use this form to make certain we have aliases |
155
|
|
|
|
|
|
|
# to the values in %$x and not copies. |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
push @filter, _scan(@{$x}{keys %$x}); |
|
0
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
elsif ($r eq "ARRAY") |
160
|
|
|
|
|
|
|
{ |
161
|
0
|
|
|
|
|
|
push @filter, _scan(@$x); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
elsif ($r eq "SCALAR" || $r eq "REF") |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
|
|
|
push @filter, _scan($$x); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} # End of _walk. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# ----------------------------------------------- |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=pod |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 NAME |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L - A persistent session manager |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 Synopsis |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
See L for details. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 Description |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L allows L to manipulate sessions with L. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
To use this module do this: |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=over 4 |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item o Specify a driver of type DataDumper as Data::Session -> new(type=> '... serialize:DataDumper') |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=back |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
The Data::Dumper options used are: |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
$d -> Deepcopy(0); |
200
|
|
|
|
|
|
|
$d -> Indent(0); |
201
|
|
|
|
|
|
|
$d -> Purity(1); |
202
|
|
|
|
|
|
|
$d -> Quotekeys(1); |
203
|
|
|
|
|
|
|
$d -> Terse(0); |
204
|
|
|
|
|
|
|
$d -> Useqq(0); |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 Case-sensitive Options |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
See L for important information. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 Method: new() |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Creates a new object of type L. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
C takes a hash of key/value pairs, some of which might mandatory. Further, some combinations |
215
|
|
|
|
|
|
|
might be mandatory. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
The keys are listed here in alphabetical order. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
They are lower-case because they are (also) method names, meaning they can be called to set or get the value |
220
|
|
|
|
|
|
|
at any time. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=over 4 |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item o verbose => $integer |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Print to STDERR more or less information. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Typical values are 0, 1 and 2. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
This key is normally passed in as Data::Session -> new(verbose => $integer). |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
This key is optional. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 Method: freeze($data) |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Returns $data frozen by L. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 Method: thaw($data) |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Returns $data thawed by L. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 Support |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Log a bug on RT: L. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 Author |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
L was written by Ron Savage Iron@savage.net.auE> in 2010. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Home page: L. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 Copyright |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Australian copyright (c) 2010, Ron Savage. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
All Programs of mine are 'OSI Certified Open Source Software'; |
259
|
|
|
|
|
|
|
you can redistribute them and/or modify them under the terms of |
260
|
|
|
|
|
|
|
The Artistic License, a copy of which is available at: |
261
|
|
|
|
|
|
|
http://www.opensource.org/licenses/index.html |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=cut |