blib/lib/Bot/Cobalt/Core/ContextMeta.pm

filter: Statementstmt 41.8% 18 / 43 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 38.4% 5 / 13 Podpod 100% 7 / 7 totaltotal 28.8% 30 / 104 CC 16 SCAR 28.1
CC
16
Cov
24%
add
42.0
del
20.0
fetch
20.0
CRAP 16.7
« blib/lib/Bot/Cobalt/Plugin/Games/RockPaperScissors.pm ↑ Summary bin/cobalt2 »
1 package Bot::Cobalt::Core::ContextMeta;
2 1 $Bot::Cobalt::Core::ContextMeta::VERSION = '0.021001';
3 ## Base class for context-specific dynamic hashes
4 ## (ignores, auth, .. )
5  
6 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Bot::Cobalt::Common ':types';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 has _list => (
18 is => 'rw',
19 isa => HashRef,
20 0 ▶ builder => sub { +{} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 1 );
22  
23  
24 sub add {
25 0 ▶ my ($self, $context, $key, $meta) = @_;
Subroutine add: not called CC=6 SCAR=37.4
Pod documented
26 0 ▶ confess "add() needs at least a context and key"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context and defined $key 0 0 0
Condition0%0/3
defined $context and defined $key
!ll&&!rl&&r
000
MC/DC0%0/2
defined $context and defined $key
defined $context defined $key
Truth table0%0/3
A and B
A= defined $contextB= defined $key
ABresult
0X0
100
111
27 unless defined $context and defined $key;
28  
29 0 my $ref = +{ AddedAt => time };
30  
31 ## Allow AddedAt to be adjusted:
32 0 ▶ if (ref $meta && reftype $meta eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta and builtin::reftype($meta) eq "HASH") 0 0 0
Condition0%0/3
ref $meta and builtin::reftype($meta) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $meta and builtin::reftype($meta) eq "HASH"
ref $meta builtin::reftype($meta) eq "HASH"
Truth table0%0/3
A and B
A= ref $metaB= builtin::reftype($meta) eq "HASH"
ABresult
0X0
100
111
33 0 $ref->{$_} = $meta->{$_} for keys %$meta;
34 }
35
36 0 $self->_list->{$context}->{$key} = $ref;
37  
38 0 $key
39 }
40  
41 sub clear {
42 0 ▶ my ($self, $context) = @_;
Subroutine clear: not called CC=2 SCAR=17.9
Pod documented
43  
44 0 ▶ $self->_list(+{}) unless defined $context;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context 0 0 0
45  
46 0 delete $self->_list->{$context}
47 }
48  
49 sub del {
50 0 ▶ my ($self, $context, $key) = @_;
Subroutine del: not called CC=4 SCAR=30.0
Pod documented
51  
52 0 ▶ confess "del() needs a context and item"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context and defined $key 0 0 0
Condition0%0/3
defined $context and defined $key
!ll&&!rl&&r
000
MC/DC0%0/2
defined $context and defined $key
defined $context defined $key
Truth table0%0/3
A and B
A= defined $contextB= defined $key
ABresult
0X0
100
111
53 unless defined $context and defined $key;
54
55 0 ▶ my $list = $self->_list->{$context} // return;
Condition0%0/2
$self->_list->{$context} // (return)
l!l
00
MC/DC0%0/1
$self->_list->{$context} // (return)
$self->_list->{$context}
Truth table0%0/2
A
A= $self->_list->{$context}
Aresult
11
00
56  
57 0 delete $list->{$key}
58 }
59  
60 sub fetch {
61 0 ▶ my ($self, $context, $key) = @_;
Subroutine fetch: not called CC=4 SCAR=30.0
Pod documented
62
63 0 ▶ confess "fetch() needs a context and key"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context and defined $key 0 0 0
Condition0%0/3
defined $context and defined $key
!ll&&!rl&&r
000
MC/DC0%0/2
defined $context and defined $key
defined $context defined $key
Truth table0%0/3
A and B
A= defined $contextB= defined $key
ABresult
0X0
100
111
64 unless defined $context and defined $key;
65  
66 0 ▶ return unless exists $self->_list->{$context};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->_list->{$context} 0 0 0
67  
68 0 $self->_list->{$context}->{$key}
69 }
70  
71 sub list {
72 0 ▶ my $self = shift;
Subroutine list: not called CC=2 SCAR=17.9
Pod documented
73 0 ▶ wantarray ? $self->list_as_array(@_) : $self->list_as_ref(@_)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
74 }
75  
76 ## Less ambiguous list methods.
77  
78 0 ▶sub list_as_array { keys %{ shift->list_as_ref(@_) || +{} } }
Subroutine list_as_array: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->list_as_ref(@_) or {} 0 0 0
79  
80 sub list_as_ref {
81 0 ▶ my ($self, $context) = @_;
Subroutine list_as_ref: not called CC=2 SCAR=17.9
Pod documented
82 0 ▶ defined $context ? $self->_list->{$context} : $self->_list ;
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
83 }
84  
85 1 1;
86 __END__
« blib/lib/Bot/Cobalt/Plugin/Games/RockPaperScissors.pm ↑ Summary bin/cobalt2 »