Tools/YAMLCache.pm

filter: Statementstmt 100% 35 / 35 Branchbran 75.0% 3 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 4 totaltotal 91.0% 51 / 56 CC 5 SCAR 6.9
CC
5
Cov
98%
_find_container
4.0
__ANON__
2.0
BEGIN
1.0
CRAP 2.0
« Tools/CLI/Download.pm ↑ Summary Tools/Output/TT.pm »
1 #!/usr/bin/perl
2  
3 package Mail::Summary::Tools::YAMLCache;
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use YAML::Syck ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 has data => (
9 isa => "HashRef",
10 is => "rw",
11 lazy => 1,
12 3 ▶ default => sub { $_[0]->_load_data || {} },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->_load_data or {} 2 1 3
13 1 );
14  
15 1 has file => (
16 isa => "Path::Class::File",
17 is => "ro",
18 required => 1,
19 );
20  
21 6 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
22 6 my ( $self, $long_key ) = @_;
23 6 my ( $container, $key ) = $self->_find_container( $long_key );
24 6 $container->{$key};
25 }
26  
27 2 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod undocumented
28 2 my ( $self, $long_key, $value ) = @_;
29 2 my ( $container, $key ) = $self->_find_container( $long_key );
30  
31 2 $container->{$key} = $value;
32 }
33  
34 1 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod undocumented
35 1 my ( $self, $long_key ) = @_;
36 1 my ( $container, $key ) = $self->_find_container( $long_key );
37 1 delete $container->{$key};
38 }
39  
40 9 ▶sub _find_container {
Subroutine _find_container: called CC=4 SCAR=13.9
41 9 my ( $self, $long_key ) = @_;
42 9 my @key = split ':', $long_key;
43 9 my $key = pop @key;
44  
45 9 ▶ $key = pop(@key) . ":$key" if $key[-1] =~ /^(?:https?|ftp)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $key[-1] =~ /^(?:https?|ftp)$/ 0 9 9
46  
47 9 my $container = $self->data;
48  
49 9 foreach my $subkey ( @key ) {
50 9 ▶ $container = $container->{$subkey} ||= {};
Condition100%2/2
$container->{$subkey} ||= {}
l!l
81
MC/DC100%1/1
$container->{$subkey} ||= {}
$container->{$subkey}
Truth table100%2/2
A
A= $container->{$subkey}
Aresult
11
00
51 }
52  
53 9 return ($container, $key);
54 }
55  
56 3 ▶sub _load_data {
Subroutine _load_data: called CC=1 SCAR=0.0
57 3 my $self = shift;
58 3 local $@;
59 3 eval { YAML::Syck::LoadFile( $self->file->stringify ) };
60 }
61  
62 3 ▶sub _save_data {
Subroutine _save_data: called CC=1 SCAR=0.0
63 3 my ( $self, $data ) = @_;
64 3 YAML::Syck::DumpFile( $self->file->stringify, $data );
65 }
66  
67 3 ▶sub DEMOLISH {
Subroutine DEMOLISH: called CC=1 SCAR=0.0
Pod undocumented
68 3 my $self = shift;
69 3 $self->_save_data($self->data);
70 }
71  
72 1 __PACKAGE__;
73  
74 __END__
« Tools/CLI/Download.pm ↑ Summary Tools/Output/TT.pm »