Serializer/Persistent.pm

filter: Statementstmt 100% 43 / 43 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 93.5% 58 / 62 CC 7 SCAR 11.1
CC
7
Cov
93%
_store
5.1
_retrieve
3.0
BEGIN
1.0
CRAP 3.0
« Serializer/Raw.pm ↑ Summary Serializer/XML/Dumper.pm »
1 package Data::Serializer::Persistent;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 $VERSION = '0.01';
11  
12 630 ▶sub _store {
Subroutine _store: called CC=5 SCAR=16.2
13 630 my $self = (shift);
14 630 my $data = (shift);
15 630 my $file_or_fh = (shift);
16  
17  
18 630 ▶ if (ref($file_or_fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file_or_fh) { } 126 504 630
19 #it is a file handle so print straight to it
20 126 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 my ($mode,$perm) = @_;
25 504 ▶ unless (defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mode) 504 0 504
26 504 $mode = O_CREAT|O_WRONLY;
27 }
28 504 ▶ unless (defined $perm) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $perm) 504 0 504
29 504 $perm = 0600;
30 }
31 504 my $fh = new IO::File;
32 504 ▶ $fh->open($file_or_fh, $mode,$perm) || croak "Cannot write to $file_or_fh: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->open($file_or_fh, $mode, $perm) or croak("Cannot write to ${file_or_fh}: $!") 504 0 504
33 504 print $fh $self->{parent}->serialize($data), "\n";
34 504 $fh->close();
35 }
36 }
37  
38 630 ▶sub _retrieve {
Subroutine _retrieve: called CC=3 SCAR=11.0
39 630 my $self = (shift);
40 630 my $file_or_fh = (shift);
41 630 ▶ if (ref($file_or_fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file_or_fh) { } 126 504 630
42 #it is a file handle so read straight from it
43 126 my $input = join('', <$file_or_fh>);
44 126 chomp($input);
45 126 return $self->{parent}->deserialize($input);
46 #We didn't open the filehandle, so we shouldn't close it.
47 } else {
48 504 my $fh = new IO::File;
49 504 ▶ $fh->open($file_or_fh, O_RDONLY) || croak "Cannot read from $file_or_fh: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->open($file_or_fh, 0) or croak("Cannot read from ${file_or_fh}: $!") 504 0 504
50 504 my $input = join('', <$fh>);
51 504 chomp($input);
52 504 $fh->close;
53 504 return $self->{parent}->deserialize($input);
54 }
55 }
56  
57  
58  
59 2 1;
60 __END__
« Serializer/Raw.pm ↑ Summary Serializer/XML/Dumper.pm »