blib/lib/MooseX/Storage/IO/CHI.pm

filter: Statementstmt 95.6% 66 / 69 Branchbran 50.0% 5 / 10 Conditioncond 46.1% 6 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 91.6% 11 / 12 Podpod n/a totaltotal 78.5% 88 / 112 CC 11 SCAR 13.2
CC
11
Cov
84%
load
6.8
store
5.4
build_cache
2.0
CRAP 3.7
↑ Summary
1 package MooseX::Storage::IO::CHI;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.05';
6  
7 1 ▶use CHI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 parameter key_attr => (
12 isa => 'Str',
13 required => 1,
14 );
15  
16 1 parameter key_prefix => (
17 isa => 'Str',
18 default => '',
19 );
20  
21 1 parameter expires_in => (
22 isa => 'Maybe[Str]',
23 default => undef,
24 );
25  
26 1 parameter cache_attr => (
27 isa => 'Str',
28 default => 'cache',
29 );
30  
31 parameter cache_args => (
32 isa => 'HashRef',
33 0 ▶ default => sub{{}},
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 1 );
35  
36 1 parameter cache_args_method => (
37 isa => 'Str',
38 default => 'cache_args',
39 );
40  
41 1 parameter cache_builder_method => (
42 isa => 'Str',
43 default => 'build_cache',
44 );
45  
46 1 ▶role {
Subroutine __ANON__: called CC=1 SCAR=0.1
47 1 my $p = shift;
48  
49 1 requires 'pack';
50 1 requires 'unpack';
51  
52 1 my $cache_attr = $p->cache_attr;
53 1 my $cache_builder_method = $p->cache_builder_method;
54 1 my $cache_args_method = $p->cache_args_method;
55  
56 2 ▶ method $cache_builder_method => sub {
Subroutine build_cache: called CC=2 SCAR=7.0
57 2 ▶ my $class = ref $_[0] || $_[0];
Condition66%2/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
58 2 my $cache_args = $class->$cache_args_method();
59 2 return CHI->new(%$cache_args);
60 1 };
61  
62 2 ▶ method $cache_args_method => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
63 2 return $p->cache_args
64 1 };
65  
66 has $cache_attr => (
67 is => 'ro',
68 isa => 'CHI::Driver',
69 lazy => 1,
70 traits => [ 'DoNotSerialize' ],
71 1 ▶ default => sub { shift->$cache_builder_method },
Subroutine __ANON__: called CC=1 SCAR=0.0
72 1 );
73  
74 1 ▶ method store => sub {
Subroutine store: called CC=5 SCAR=16.9
75 1 my ( $self, %args ) = @_;
76 1 ▶ my $cache = delete $args{cache} || $self->$cache_attr;
Condition33%1/3
delete $args{'cache'} || $self->$cache_attr
l!l&&r!l&&!r
010
MC/DC0%0/2
delete $args{'cache'} || $self->$cache_attr
delete $args{'cache'} $self->$cache_attr
Truth table33%1/3
A || B
A= delete $args{'cache'}B= $self->$cache_attr
ABresult
1X1
011
000
77 1 my $key_attr = $p->key_attr;
78 1 my $key_value = $self->$key_attr;
79 1 ▶ die "Cannot have null value for key_attr $key_attr"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key_value 0 1 1
80 unless defined $key_value;
81 1 my $cachekey = $p->key_prefix . $key_value;
82 1 my $data;
83 1 ▶ if ($self->can('freeze')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can('freeze')) { } 0 1 1
84 0 $data = $self->freeze;
85 } else {
86 1 $data = $self->pack;
87 }
88  
89 1 my $set_args;
90 1 ▶ if (defined $p->expires_in) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p->expires_in) 1 0 1
91 1 $set_args->{expires_in} = $p->expires_in;
92 }
93 1 $cache->set($cachekey, $data, $set_args);
94 1 };
95  
96 1 ▶ method load => sub {
Subroutine load: called CC=6 SCAR=19.2
97 1 my ( $class, $key_value, %args ) = @_;
98 1 ▶ my $cache = delete $args{cache} || $class->$cache_builder_method;
Condition33%1/3
delete $args{'cache'} || $class->$cache_builder_method
l!l&&r!l&&!r
010
MC/DC0%0/2
delete $args{'cache'} || $class->$cache_builder_method
delete $args{'cache'} $class->$cache_builder_method
Truth table33%1/3
A || B
A= delete $args{'cache'}B= $class->$cache_builder_method
ABresult
1X1
011
000
99 1 ▶ my $inject = delete $args{inject} || {};
Condition50%1/2
delete $args{'inject'} || {}
l!l
01
MC/DC0%0/1
delete $args{'inject'} || {}
delete $args{'inject'}
Truth table50%1/2
A
A= delete $args{'inject'}
Aresult
11
00
100  
101 1 my $key_attr = $p->key_attr;
102 1 ▶ $key_value // die "undefined value for key attr $key_attr";
Condition50%1/2
$key_value // die("undefined value for key attr $key_attr")
l!l
10
MC/DC0%0/1
$key_value // die("undefined value for key attr $key_attr")
$key_value
Truth table50%1/2
A
A= $key_value
Aresult
11
00
103  
104 1 my $cachekey = $p->key_prefix . $key_value;
105  
106 1 my $data = $cache->get($cachekey);
107 1 ▶ return undef unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 1 1
108  
109 1 $inject->{$cache_attr} = $cache;
110  
111 1 my $obj;
112 1 ▶ if ($class->can('thaw')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('thaw')) { } 0 1 1
113 0 $obj = $class->thaw($data, inject => $inject, %args);
114 } else {
115 1 $obj = $class->unpack($data, inject => $inject, %args);
116 }
117  
118 1 return $obj;
119 1 };
120 1 };
121  
122 1 1;
123 __END__
↑ Summary