Storage/Filesystem.pm

filter: Statementstmt 32.6% 17 / 52 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.8% 6 / 14 Podpod 100% 8 / 8 totaltotal 30.3% 31 / 102 CC 14 SCAR 31.1
CC
14
Cov
22%
commit
56.0
connect
30.0
cache_get
12.0
CRAP 22.4
↑ Summary Storage/DBIC.pm »
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::Storage::Filesystem;
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $Data::Storage::Filesystem::VERSION = '1.102720';
8 }
9 # ABSTRACT: Base class for filesystem-based storages
10 1 ▶use parent qw(Data::Storage Class::Accessor::Complex);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use constant DEFAULTS => (mode => '0664');
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 __PACKAGE__
13 ->mk_hash_accessors(qw(trans_cache))
14 ->mk_scalar_accessors(qw(fspath mode));
15  
16 0 ▶sub connect {
Subroutine connect: not called CC=5 SCAR=34.0
Pod documented
17 0 my $self = shift;
18 0 ▶ die sprintf "invalid target directory: '%s'", $self->fspath
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->fspath and -d $self->fspath and -w _ 0 0 0
Condition0%0/8
defined $self->fspath and -d $self->fspath and -w _
!ll&&!rl&&r
000
defined $self->fspath and -d $self->fspath
!ll&&!rl&&r
000
$self->fspath || ''
l!l
00
MC/DC0%0/3
defined $self->fspath and -d $self->fspath and -w _
defined $self->fspath -d $self->fspath -w _
MC/DC0%0/1
$self->fspath || ''
$self->fspath
Truth table0%0/4
A and B and C
A= defined $self->fspathB= -d $self->fspathC= -w _
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/2
A
A= $self->fspath
Aresult
11
00
19 || ''
20 unless defined $self->fspath && -d $self->fspath && -w _;
21 }
22  
23 # we will keep this very simple and naive for now,
24 # just fulfilling our current, very limited needs.
25 # hence: no fooling around, i.e. changing the base
26 # directory while operating etc.
27 0 ▶sub cache_put {
Subroutine cache_put: not called CC=2 SCAR=17.9
Pod documented
28 0 my ($self, $key, $rec) = @_;
29 0 ▶ $self->trans_cache->{$key} = ref $rec ? $rec : [$rec];
Branch: 1 branch
BranchTrueFalseTotal
ref $rec ? : 0 0 0
30 }
31  
32 0 ▶sub cache_get {
Subroutine cache_get: not called CC=3 SCAR=24.8
Pod documented
33 0 my ($self, $key) = @_;
34 my $rec =
35 exists $self->trans_cache->{$key}
36 0 ▶ ? $self->trans_cache->{$key}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->trans_cache->{$key} ? : 0 0 0
37 : [];
38 0 ▶ wantarray ? @$rec : $rec->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
39 }
40  
41 0 ▶sub cache_rmv {
Subroutine cache_rmv: not called CC=1 SCAR=6.9
Pod documented
42 0 my ($self, $key) = @_;
43 0 delete $self->trans_cache->{$key};
44 }
45  
46 0 ▶sub cache_lst {
Subroutine cache_lst: not called CC=1 SCAR=6.9
Pod documented
47 0 map { @$_ } shift->trans_cache_values;
48 }
49  
50 0 ▶sub rollback {
Subroutine rollback: not called CC=1 SCAR=6.9
Pod documented
51 0 shift->trans_cache_clear;
52 }
53  
54 0 ▶sub commit {
Subroutine commit: not called CC=7 SCAR=40.3
Pod documented
55 0 my $self = shift;
56 0 ▶ return 1 unless scalar $self->trans_cache_keys;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar $self->trans_cache_keys 0 0 0
57 0 my $failed;
58 0 for my $rec ($self->cache_lst) {
59 0 my $handle;
60 0 ▶ open($handle, sprintf ">%s", $rec->filename) || do {
Branch: 1 branch
BranchTrueFalseTotal
open $handle, sprintf(">%s", $rec->filename) or do { ++$failed; last } 0 0 0
61 0 ++$failed;
62 0 last;
63 };
64 0 print $handle $rec->data;
65 0 ▶ close($handle) || do {
Branch: 1 branch
BranchTrueFalseTotal
close $handle or do { ++$failed; last } 0 0 0
66 0 ++$failed;
67 0 last;
68 };
69 0 chmod $rec->mode, $rec->filename;
70 0 $rec->stored(1);
71 }
72 0 ▶ if ($failed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($failed) 0 0 0
73 0 unlink $_->filename for (grep { $_->stored } $self->cache_lst);
74 0 $self->rollback;
75 0 return 0;
76 }
77 0 $self->rollback;
78 0 1;
79 }
80  
81 0 ▶sub signature {
Subroutine signature: not called CC=1 SCAR=6.9
Pod documented
82 0 my $self = shift;
83 0 sprintf "%s,fspath=%s", $self->SUPER::signature(), $self->fspath;
84 }
85 1 1;
86  
87  
88 __END__
↑ Summary Storage/DBIC.pm »