line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Serializer::Persistent; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
75
|
|
4
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
155
|
|
5
|
2
|
|
|
2
|
|
13
|
use vars qw($VERSION @ISA); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
130
|
|
6
|
2
|
|
|
2
|
|
13
|
use IO::File; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
510
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
21
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1065
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _store { |
13
|
595
|
|
|
595
|
|
793
|
my $self = (shift); |
14
|
595
|
|
|
|
|
834
|
my $data = (shift); |
15
|
595
|
|
|
|
|
720
|
my $file_or_fh = (shift); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
595
|
100
|
|
|
|
1738
|
if (ref($file_or_fh)) { |
19
|
|
|
|
|
|
|
#it is a file handle so print straight to it |
20
|
119
|
|
|
|
|
503
|
print $file_or_fh $self->{parent}->serialize($data), "\n"; |
21
|
|
|
|
|
|
|
#We didn't open the filehandle, so we shouldn't close it. |
22
|
|
|
|
|
|
|
} else { |
23
|
|
|
|
|
|
|
#it is a file, so open it |
24
|
476
|
|
|
|
|
895
|
my ($mode,$perm) = @_; |
25
|
476
|
50
|
|
|
|
1193
|
unless (defined $mode) { |
26
|
476
|
|
|
|
|
726
|
$mode = O_CREAT|O_WRONLY; |
27
|
|
|
|
|
|
|
} |
28
|
476
|
50
|
|
|
|
1101
|
unless (defined $perm) { |
29
|
476
|
|
|
|
|
734
|
$perm = 0600; |
30
|
|
|
|
|
|
|
} |
31
|
476
|
|
|
|
|
3166
|
my $fh = new IO::File; |
32
|
476
|
50
|
|
|
|
16535
|
$fh->open($file_or_fh, $mode,$perm) || croak "Cannot write to $file_or_fh: $!"; |
33
|
476
|
|
|
|
|
66733
|
print $fh $self->{parent}->serialize($data), "\n"; |
34
|
476
|
|
|
|
|
2129
|
$fh->close(); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _retrieve { |
39
|
595
|
|
|
595
|
|
828
|
my $self = (shift); |
40
|
595
|
|
|
|
|
911
|
my $file_or_fh = (shift); |
41
|
595
|
100
|
|
|
|
1383
|
if (ref($file_or_fh)) { |
42
|
|
|
|
|
|
|
#it is a file handle so read straight from it |
43
|
119
|
|
|
|
|
2118
|
my $input = join('', <$file_or_fh>); |
44
|
119
|
|
|
|
|
288
|
chomp($input); |
45
|
119
|
|
|
|
|
503
|
return $self->{parent}->deserialize($input); |
46
|
|
|
|
|
|
|
#We didn't open the filehandle, so we shouldn't close it. |
47
|
|
|
|
|
|
|
} else { |
48
|
476
|
|
|
|
|
2886
|
my $fh = new IO::File; |
49
|
476
|
50
|
|
|
|
15071
|
$fh->open($file_or_fh, O_RDONLY) || croak "Cannot read from $file_or_fh: $!"; |
50
|
476
|
|
|
|
|
38880
|
my $input = join('', <$fh>); |
51
|
476
|
|
|
|
|
1178
|
chomp($input); |
52
|
476
|
|
|
|
|
1448
|
$fh->close; |
53
|
476
|
|
|
|
|
8029
|
return $self->{parent}->deserialize($input); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |