blib/lib/Bootylicious/Document.pm

filter: Statementstmt 91.4% 75 / 82 Branchbran 75.0% 12 / 16 Conditioncond 40.0% 4 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.0% 23 / 25 Podpod 0.0% 0 / 15 totaltotal 74.0% 114 / 154 CC 16 SCAR 14.3
CC
16
Cov
84%
create
11.7
_group
5.0
update
3.1
CRAP 4.2
« blib/lib/Bootylicious/TagCloud.pm ↑ Summary blib/lib/Bootylicious/DocumentContentLoader.pm »
1 package Bootylicious::Document;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use base 'Mojo::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Bootylicious::DocumentStatLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Bootylicious::DocumentMetadataLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Bootylicious::DocumentContentLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 require Carp;
13  
14 12 __PACKAGE__->attr('path');
15  
16 __PACKAGE__->attr(
17 stat_loader => sub {
18 54 ▶ Bootylicious::DocumentStatLoader->new(path => shift->path);
Subroutine __ANON__: called CC=1 SCAR=0.0
19 }
20 12 );
21  
22 __PACKAGE__->attr(
23 metadata_loader => sub {
24 20 ▶ Bootylicious::DocumentMetadataLoader->new(path => shift->path);
Subroutine __ANON__: called CC=1 SCAR=0.0
25 }
26 12 );
27  
28 __PACKAGE__->attr(
29 inner_loader => sub {
30 9 ▶ Bootylicious::DocumentContentLoader->new(path => shift->path);
Subroutine __ANON__: called CC=1 SCAR=0.0
31 }
32 12 );
33  
34 sub load {
35 77 ▶ my $self = shift;
Subroutine load: called CC=2 SCAR=6.9
Pod undocumented
36 77 my $path = shift;
37  
38 77 ▶ return unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 1 76 77
39  
40 76 $self->path($path);
41  
42 76 return $self;
43 }
44  
45 21 ▶sub name { shift->stat(name => @_) }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
46 1 ▶sub format { shift->stat(format => @_) }
Subroutine format: called CC=1 SCAR=0.0
Pod undocumented
47 0 ▶sub filename { shift->stat(filename => @_) }
Subroutine filename: not called CC=1 SCAR=6.9
Pod undocumented
48 157 ▶sub created { shift->stat(created => @_) }
Subroutine created: called CC=1 SCAR=0.0
Pod undocumented
49 9 ▶sub modified { shift->stat(modified => @_) }
Subroutine modified: called CC=1 SCAR=0.0
Pod undocumented
50  
51 9 ▶sub author { shift->metadata(author => @_) }
Subroutine author: called CC=1 SCAR=0.0
Pod undocumented
52  
53 15 ▶sub content { shift->inner(content => @_) }
Subroutine content: called CC=1 SCAR=0.0
Pod undocumented
54  
55 188 ▶sub stat { shift->_group(stat => @_) }
Subroutine stat: called CC=1 SCAR=0.0
Pod undocumented
56 51 ▶sub metadata { shift->_group(metadata => @_) }
Subroutine metadata: called CC=1 SCAR=0.0
Pod undocumented
57 25 ▶sub inner { shift->_group(inner => @_) }
Subroutine inner: called CC=1 SCAR=0.0
Pod undocumented
58  
59 sub _group {
60 264 ▶ my $self = shift;
Subroutine _group: called CC=5 SCAR=16.1
61 264 my $group = shift;
62 264 my $method = shift;
63  
64 264 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 22 242 264
65 22 $self->{$group}->{$method} = $_[0];
66 22 return $self;
67 }
68  
69 return $method ? $self->{$group}->{$method} : $self->{$group}
70 242 ▶ if exists $self->{$group};
Branch: 2 branches
BranchTrueFalseTotal
if exists $self->{$group} 159 83 242
$method ? : 143 16 159
71  
72 83 my $group_loader = "${group}_loader";
73 83 $self->{$group} = $self->$group_loader->load;
74  
75 81 ▶ return $method ? $self->{$group}->{$method} : $self->{$group};
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 81 0 81
76 }
77  
78 sub is_modified {
79 0 ▶ my $self = shift;
Subroutine is_modified: not called CC=1 SCAR=6.9
Pod undocumented
80  
81 0 return $self->created != $self->modified;
82 }
83  
84 sub create {
85 6 ▶ my $self = shift;
Subroutine create: called CC=9 SCAR=24.6
Pod undocumented
86 6 my $path = shift;
87 6 my $hash = shift;
88  
89 6 ▶ if ($hash && ref $hash eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash and ref $hash eq "HASH") 0 6 6
Condition33%1/3
$hash and ref $hash eq "HASH"
!ll&&!rl&&r
600
MC/DC0%0/2
$hash and ref $hash eq "HASH"
$hash ref $hash eq "HASH"
Truth table33%1/3
A and B
A= $hashB= ref $hash eq "HASH"
ABresult
0X0
100
111
90 0 foreach my $key (keys %$hash) {
91 0 $self->$key($hash->{$key});
92 }
93  
94 0 $path .= '/'.
95 Bootylicious::Timestamp->new(epoch => time)->timestamp . '-'
96 . $self->name . '.'
97 . $self->format;
98 }
99  
100 6 ▶ open my $file, '>:encoding(UTF-8)', $path or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $file, ">:encoding(UTF-8)", $path or return 0 6 6
101  
102 6 $self->path($path);
103  
104 6 my $metadata = '';
105 6 foreach my $key (sort keys %{$self->metadata}) {
106 10 my $value = $self->metadata->{$key};
107 10 ▶ next unless $value && $value ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless $value and $value ne "" 0 10 10
Condition33%1/3
$value and $value ne ""
!ll&&!rl&&r
0010
MC/DC0%0/2
$value and $value ne ""
$value $value ne ""
Truth table33%1/3
A and B
A= $valueB= $value ne ""
ABresult
0X0
100
111
108 10 $metadata .= ucfirst $key . ': ' . $value;
109 10 $metadata .= "\n";
110 }
111  
112 6 print $file $metadata;
113 6 print $file "\n";
114 6 ▶ print $file $self->content || '';
Condition50%1/2
$self->content || ''
l!l
60
MC/DC0%0/1
$self->content || ''
$self->content
Truth table50%1/2
A
A= $self->content
Aresult
11
00
115  
116 6 return $self;
117 }
118  
119 sub update {
120 1 ▶ my $self = shift;
Subroutine update: called CC=3 SCAR=11.4
Pod undocumented
121 1 my $hash = shift;
122  
123 1 ▶ $hash ||= {};
Condition50%1/2
$hash ||= {}
l!l
01
MC/DC0%0/1
$hash ||= {}
$hash
Truth table50%1/2
A
A= $hash
Aresult
11
00
124 1 foreach my $key (keys %$hash) {
125 0 $self->$key($hash->{$key});
126 }
127  
128 1 return $self->create($self->path);
129 }
130  
131 sub delete {
132 1 ▶ my $self = shift;
Subroutine delete: called CC=1 SCAR=0.0
Pod undocumented
133  
134 1 unlink $self->path;
135 }
136  
137 12 1;
« blib/lib/Bootylicious/TagCloud.pm ↑ Summary blib/lib/Bootylicious/DocumentContentLoader.pm »