blib/lib/Yukki/Role/Savable.pm

filter: Statementstmt 91.4% 32 / 35 Branchbran 33.3% 2 / 6 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 73.7% 45 / 61 CC 7 SCAR 14.5
CC
7
Cov
74%
dump_yaml
8.7
load_yaml
3.3
BEGIN
1.0
CRAP 4.3
« blib/lib/Yukki/Web/Plugin/Role/Formatter.pm ↑ Summary blib/lib/Yukki/Web/View/Role/Navigation.pm »
1 package Yukki::Role::Savable;
2 19 $Yukki::Role::Savable::VERSION = '0.991_007'; # TRIAL
3 19 $Yukki::Role::Savable::VERSION = '0.991007';
4 19 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use YAML qw( Dump Load );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Provides a mechanism for YAML-izing objects
13  
14  
15 19 requires 'savable_attributes';
16  
17  
18 4 ▶sub dump_yaml {
Subroutine dump_yaml: called CC=5 SCAR=21.6
Pod documented
19 4 my $self = shift;
20  
21 4 my %output;
22 4 for my $attr ($self->savable_attributes) {
23 20 my $v = $self->$attr;
24 20 ▶ if (blessed $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($v)) 0 20 20
25 0 ▶ if ($v->can('does') && $v->does('Yukki::Role::Savable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->can('does') and $v->does('Yukki::Role::Savable')) { } 0 0 0
Condition0%0/3
$v->can("does") and $v->does("Yukki::Role::Savable")
!ll&&!rl&&r
000
MC/DC0%0/2
$v->can("does") and $v->does("Yukki::Role::Savable")
$v->can("does") $v->does("Yukki::Role::Savable")
Truth table0%0/3
A and B
A= $v->can("does")B= $v->does("Yukki::Role::Savable")
ABresult
0X0
100
111
26 0 $v = $v->dump_yaml;
27 }
28 else {
29 0 $v = "$v";
30 }
31 }
32 20 $output{ $attr } = $v;
33 }
34  
35 4 return Dump(\%output);
36 }
37  
38  
39 1 ▶sub load_yaml {
Subroutine load_yaml: called CC=3 SCAR=12.0
Pod documented
40 1 my ($class, $yaml) = @_;
41  
42 1 ▶ croak "No data given to from which to load $class"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $yaml and $yaml =~ /\S/u 0 1 1
Condition33%1/3
defined $yaml and $yaml =~ /\S/u
!ll&&!rl&&r
001
MC/DC0%0/2
defined $yaml and $yaml =~ /\S/u
defined $yaml $yaml =~ /\S/u
Truth table33%1/3
A and B
A= defined $yamlB= $yaml =~ /\S/u
ABresult
0X0
100
111
43 unless defined $yaml && $yaml =~ /\S/;
44  
45 1 my $input = Load($yaml);
46 1 $class->new($input);
47 }
48  
49 19 1;
50  
51 __END__
« blib/lib/Yukki/Web/Plugin/Role/Formatter.pm ↑ Summary blib/lib/Yukki/Web/View/Role/Navigation.pm »