lib/Data/Dumper/Store.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 91.6% 11 / 12 Podpod 100% 6 / 6 totaltotal 83.3% 75 / 90 CC 10 SCAR 10.0
CC
10
Cov
84%
init
5.2
_init
4.0
get
2.0
CRAP 2.7
↑ Summary
1 package Data::Dumper::Store;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 $Data::Dumper::Purity = 1;
10 1 $Data::Dumper::Terse = 1;
11  
12 =head1 NAME
13  
14 Data::Dumper::Store - persistent key-value storage engine based on Data::Dumper serialization mechanism and flat files.
15  
16 =head1 VERSION
17  
18 Version 1.01
19  
20 =cut
21  
22 1 our $VERSION = '1.01';
23  
24 7 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
25 7 my ($class, %opts) = @_;
26  
27 7 ▶ defined $opts{file} or die "File is not specified";
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{"file"} or die "File is not specified" 6 1 7
28  
29 my $self = {
30 file => $opts{file},
31 6 data => {},
32 };
33 6 _init($self);
34  
35 6 return bless $self, $class;
36 }
37  
38 6 ▶sub _init {
Subroutine _init: called CC=4 SCAR=14.0
39 6 my ($self) = @_;
40  
41 6 ▶ return unless -e $self->{file};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->{"file"} 1 5 6
42 open my $fh, '<', $self->{file}
43 5 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->{"file"} or return 5 0 5
44 5 my $text = do { local $/; <$fh> };
45 5 my $data = eval($text);
46  
47 5 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
48  
49 5 $self->{data} = $data;
50 }
51  
52 2 ▶sub init {
Subroutine init: called CC=4 SCAR=16.4
Pod documented
53 2 my ($self, $data) = @_;
54  
55 2 ▶ defined $data && ref $data && ref $data eq 'HASH' or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $data and ref $data and ref $data eq "HASH" or return 2 0 2
Condition33%2/6
defined $data and ref $data and ref $data eq "HASH"
!ll&&!rl&&r
002
defined $data and ref $data
!ll&&!rl&&r
002
MC/DC0%0/3
defined $data and ref $data and ref $data eq "HASH"
defined $data ref $data ref $data eq "HASH"
Truth table25%1/4
A and B and C
A= defined $dataB= ref $dataC= ref $data eq "HASH"
ABCresult
0XX0
10X0
1100
1111
56 2 $self->{data} = $data;
57  
58 2 return $self;
59 }
60  
61 2 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
62 2 my ($self, $key, $val) = @_;
63  
64 2 $self->{data}{$key} = $val;
65  
66 2 return $self;
67 }
68  
69 5 ▶sub get {
Subroutine get: called CC=2 SCAR=7.1
Pod documented
70 5 my ($self, $key) = @_;
71  
72 5 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 5 5
73  
74 5 return $self->{data}{$key};
75 }
76  
77 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod documented
78 0 my ($self) = @_;
79  
80 0 return Dumper $self->{data};
81 }
82  
83 7 ▶sub commit {
Subroutine commit: called CC=2 SCAR=7.0
Pod documented
84 7 my ($self) = @_;
85  
86 7 ▶ open my $fh, ">", $self->{file} or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->{"file"} or return 7 0 7
87  
88 7 print {$fh} Dumper $self->{data};
89 7 close $fh;
90  
91 7 return 1;
92 }
93  
94 6 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
95 6 my ($self) = @_;
96  
97 6 $self->commit();
98 }
99  
100 1 1;
101  
102 __END__
↑ Summary