| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$hash and ref $hash eq "HASH"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$value and $value ne ""
MC/DC0%0/2
$value and $value ne ""
$value
$value ne ""
Truth table33%1/3
A and B
A= $valueB= $value ne ""
| |||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$self->content || ''
$self->content
Truth table50%1/2
A
A= $self->content
| |||||||||||||||||||||||||||||
| 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 ||= {}
MC/DC0%0/1
$hash ||= {}
$hash
Truth table50%1/2
A
A= $hash
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||