line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Serializer::Persistent; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
32
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
5
|
2
|
|
|
2
|
|
11
|
use vars qw($VERSION @ISA); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
111
|
|
6
|
2
|
|
|
2
|
|
14
|
use IO::File; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
687
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
15
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
849
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _store { |
13
|
630
|
|
|
630
|
|
1048
|
my $self = (shift); |
14
|
630
|
|
|
|
|
1059
|
my $data = (shift); |
15
|
630
|
|
|
|
|
1176
|
my $file_or_fh = (shift); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
630
|
100
|
|
|
|
1614
|
if (ref($file_or_fh)) { |
19
|
|
|
|
|
|
|
#it is a file handle so print straight to it |
20
|
126
|
|
|
|
|
486
|
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
|
504
|
|
|
|
|
1278
|
my ($mode,$perm) = @_; |
25
|
504
|
50
|
|
|
|
1274
|
unless (defined $mode) { |
26
|
504
|
|
|
|
|
987
|
$mode = O_CREAT|O_WRONLY; |
27
|
|
|
|
|
|
|
} |
28
|
504
|
50
|
|
|
|
1167
|
unless (defined $perm) { |
29
|
504
|
|
|
|
|
775
|
$perm = 0600; |
30
|
|
|
|
|
|
|
} |
31
|
504
|
|
|
|
|
2932
|
my $fh = new IO::File; |
32
|
504
|
50
|
|
|
|
18944
|
$fh->open($file_or_fh, $mode,$perm) || croak "Cannot write to $file_or_fh: $!"; |
33
|
504
|
|
|
|
|
54285
|
print $fh $self->{parent}->serialize($data), "\n"; |
34
|
504
|
|
|
|
|
2611
|
$fh->close(); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _retrieve { |
39
|
630
|
|
|
630
|
|
1193
|
my $self = (shift); |
40
|
630
|
|
|
|
|
1216
|
my $file_or_fh = (shift); |
41
|
630
|
100
|
|
|
|
1724
|
if (ref($file_or_fh)) { |
42
|
|
|
|
|
|
|
#it is a file handle so read straight from it |
43
|
126
|
|
|
|
|
2574
|
my $input = join('', <$file_or_fh>); |
44
|
126
|
|
|
|
|
566
|
chomp($input); |
45
|
126
|
|
|
|
|
583
|
return $self->{parent}->deserialize($input); |
46
|
|
|
|
|
|
|
#We didn't open the filehandle, so we shouldn't close it. |
47
|
|
|
|
|
|
|
} else { |
48
|
504
|
|
|
|
|
2885
|
my $fh = new IO::File; |
49
|
504
|
50
|
|
|
|
17386
|
$fh->open($file_or_fh, O_RDONLY) || croak "Cannot read from $file_or_fh: $!"; |
50
|
504
|
|
|
|
|
39818
|
my $input = join('', <$fh>); |
51
|
504
|
|
|
|
|
2079
|
chomp($input); |
52
|
504
|
|
|
|
|
2172
|
$fh->close; |
53
|
504
|
|
|
|
|
9238
|
return $self->{parent}->deserialize($input); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=pod |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Data::Serializer::Persistent - Provide means of persistently storing serialized data in a file |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Data::Serializer::Persistent |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Used internally to L<Data::Serializer(3)>, does not currently have any public methods |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 EXAMPLES |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=over 4 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item Please see L<Data::Serializer::Cookbook(3)> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 METHODS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Neil Neely <F<neil@neely.cx>>. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
http://neil-neely.blogspot.com/ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 BUGS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Please report all bugs here: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
http://rt.cpan.org/Public/Dist/Display.html?Name=Data-Serializer |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Copyright (c) 2011 Neil Neely. All rights reserved. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
104
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.2 or, |
105
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
See http://www.perl.com/language/misc/Artistic.html |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SEE ALSO |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
perl(1), Data::Serializer(3), IO::File(3). |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|