Spoon/ContentObject.pm

filter: Statementstmt 61.4% 43 / 70 Branchbran 27.2% 6 / 22 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 64.7% 11 / 17 Podpod 0.0% 0 / 14 totaltotal 45.5% 62 / 136 CC 15 SCAR 15.0
CC
15
Cov
51%
store
12.0
store_content
6.9
assert_writable
6.0
CRAP 4.5
« Spoon/Utils.pm ↑ Summary Spoon/Base.pm »
1 package Spoon::ContentObject;
2 2 ▶use Spoon::DataObject -Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 stub 'content';
5 2 stub 'metadata';
6 2 const is_readable => 1;
7 2 const is_writable => 1;
8  
9 4 ▶sub force {
Subroutine force: called CC=3 SCAR=11.0
Pod undocumented
10 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2 4
11 2 $self->{force} = shift;
12 2 return $self;
13 }
14 2 ▶ $self->{force} ||= 0;
Condition50%1/2
$self->{"force"} ||= 0
l!l
20
MC/DC0%0/1
$self->{"force"} ||= 0
$self->{"force"}
Truth table50%1/2
A
A= $self->{"force"}
Aresult
11
00
15 }
16  
17 0 ▶sub database_directory {
Subroutine database_directory: not called CC=1 SCAR=6.9
Pod undocumented
18 0 join '/', $self->hub->config->database_directory, $self->class_id;
19 }
20  
21 14 ▶sub file_path {
Subroutine file_path: called CC=1 SCAR=0.0
Pod undocumented
22 14 join '/', $self->database_directory, $self->id;
23 }
24  
25 4 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod undocumented
26 4 -e $self->file_path;
27 }
28  
29 4 ▶sub deleted {
Subroutine deleted: called CC=1 SCAR=0.0
Pod undocumented
30 4 -z $self->file_path;
31 }
32  
33 4 ▶sub active {
Subroutine active: called CC=2 SCAR=8.1
Pod undocumented
34 4 ▶ return $self->exists && not $self->deleted;
Condition33%1/3
$self->exists && !$self->deleted
!ll&&!rl&&r
004
MC/DC0%0/2
$self->exists && !$self->deleted
$self->exists !$self->deleted
Truth table33%1/3
A && not(B)
A= $self->existsB= !$self->deleted
ABresult
0X0
100
111
35 }
36  
37 4 ▶sub assert_readable {
Subroutine assert_readable: called CC=2 SCAR=9.2
Pod undocumented
38 4 ▶ if (not $self->is_readable) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->is_readable) 0 4 4
39 0 my $id = $self->id;
40 0 die "$id is not readable";
41 }
42 }
43  
44 0 ▶sub assert_writable {
Subroutine assert_writable: not called CC=2 SCAR=17.9
Pod undocumented
45 0 ▶ if (not $self->is_writable) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->is_writable) 0 0 0
46 0 my $id = $self->id;
47 0 die "$id is not writable";
48 }
49 }
50  
51 0 ▶sub load {
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
52 0 $self->load_content;
53 0 $self->load_metadata;
54 0 return $self;
55 }
56  
57 4 ▶sub load_content {
Subroutine load_content: called CC=2 SCAR=7.0
Pod undocumented
58 4 $self->assert_readable;
59 4 ▶ my $content = $self->active
Branch: 1 branch
BranchTrueFalseTotal
$self->active ? : 4 0 4
60 ? io($self->file_path)->utf8->all
61 : '';
62 4 $self->content($content);
63 4 return $self;
64 }
65  
66 0 ▶sub load_metadata {
Subroutine load_metadata: not called CC=2 SCAR=17.9
Pod undocumented
67 my $metadata = $self->{metadata}
68 0 ▶ or die "No metadata object in content object";
Branch: 1 branch
BranchTrueFalseTotal
my $metadata = $self->{"metadata"} or die "No metadata object in content object" 0 0 0
69 0 $metadata->load;
70 0 return $self;
71 }
72  
73 0 ▶sub store {
Subroutine store: not called CC=3 SCAR=24.8
Pod undocumented
74 0 $self->assert_writable;
75 0 ▶ $self->store_content or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->store_content or return 0 0 0
76 0 $self->store_metadata;
77 0 ▶ return if $self->force;
Branch: 1 branch
BranchTrueFalseTotal
if $self->force 0 0 0
78 0 return $self;
79 }
80  
81 2 ▶sub store_content {
Subroutine store_content: called CC=5 SCAR=19.3
Pod undocumented
82 2 my $content = $self->content;
83 2 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 2 0 2
84 2 $content =~ s/\r//g;
85 2 $content =~ s/\n*\z/\n/;
86 }
87 2 my $file = io->file($self->file_path)->utf8;
88 2 ▶ unless ($self->force) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->force) 0 2 2
89 0 ▶ return if $file->exists and
Branch: 1 branch
BranchTrueFalseTotal
if $file->exists and $content eq $file->all 0 0 0
Condition0%0/3
$file->exists and $content eq $file->all
!ll&&!rl&&r
000
MC/DC0%0/2
$file->exists and $content eq $file->all
$file->exists $content eq $file->all
Truth table0%0/3
A and B
A= $file->existsB= $content eq $file->all
ABresult
0X0
100
111
90 $content eq $file->all;
91 }
92 2 $file->print($content);
93 2 return $self;
94 }
95  
96 0 ▶sub store_metadata {
Subroutine store_metadata: not called CC=2 SCAR=17.9
Pod undocumented
97 my $metadata = $self->{metadata}
98 0 ▶ or die "No metadata for content object";
Branch: 1 branch
BranchTrueFalseTotal
my $metadata = $self->{"metadata"} or die "No metadata for content object" 0 0 0
99 0 $metadata->store;
100 0 return $self;
101 }
102  
103 2 __DATA__
« Spoon/Utils.pm ↑ Summary Spoon/Base.pm »