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

filter: Statementstmt 95.4% 42 / 44 Branchbran 56.2% 9 / 16 Conditioncond 31.2% 5 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 92.8% 13 / 14 Podpod 100% 7 / 7 totaltotal 71.0% 76 / 107 CC 16 SCAR 13.8
CC
16
Cov
74%
add
7.6
list_as_array
6.0
del
4.8
CRAP 4.0
« blib/lib/Bot/Cobalt/Lang.pm ↑ Summary blib/lib/Bot/Cobalt/Conf/File/Plugins.pm »
1 package Bot::Cobalt::Core::ContextMeta;
2 2 $Bot::Cobalt::Core::ContextMeta::VERSION = '0.021003';
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 2 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 has _list => (
18 is => 'rw',
19 isa => HashRef,
20 1 ▶ builder => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _build__list: called CC=1 SCAR=0.0
21 2 );
22  
23  
24 3 ▶sub add {
Subroutine add: called CC=6 SCAR=20.3
Pod documented
25 3 my ($self, $context, $key, $meta) = @_;
26 3 ▶ confess "add() needs at least a context and key"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context and defined $key 0 3 3
Condition33%1/3
defined $context and defined $key
!ll&&!rl&&r
003
MC/DC0%0/2
defined $context and defined $key
defined $context defined $key
Truth table33%1/3
A and B
A= defined $contextB= defined $key
ABresult
0X0
100
111
27 unless defined $context and defined $key;
28  
29 3 my $ref = +{ AddedAt => time };
30  
31 ## Allow AddedAt to be adjusted:
32 3 ▶ if (ref $meta && reftype $meta eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta and builtin::reftype($meta) eq "HASH") 3 0 3
Condition33%1/3
ref $meta and builtin::reftype($meta) eq "HASH"
!ll&&!rl&&r
003
MC/DC0%0/2
ref $meta and builtin::reftype($meta) eq "HASH"
ref $meta builtin::reftype($meta) eq "HASH"
Truth table33%1/3
A and B
A= ref $metaB= builtin::reftype($meta) eq "HASH"
ABresult
0X0
100
111
33 3 $ref->{$_} = $meta->{$_} for keys %$meta;
34 }
35
36 3 $self->_list->{$context}->{$key} = $ref;
37  
38 3 $key
39 }
40  
41 1 ▶sub clear {
Subroutine clear: called CC=2 SCAR=7.1
Pod documented
42 1 my ($self, $context) = @_;
43  
44 1 ▶ $self->_list(+{}) unless defined $context;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context 0 1 1
45  
46 1 delete $self->_list->{$context}
47 }
48  
49 1 ▶sub del {
Subroutine del: called CC=4 SCAR=15.6
Pod documented
50 1 my ($self, $context, $key) = @_;
51  
52 1 ▶ confess "del() needs a context and item"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context and defined $key 0 1 1
Condition33%1/3
defined $context and defined $key
!ll&&!rl&&r
001
MC/DC0%0/2
defined $context and defined $key
defined $context defined $key
Truth table33%1/3
A and B
A= defined $contextB= defined $key
ABresult
0X0
100
111
53 unless defined $context and defined $key;
54
55 1 ▶ my $list = $self->_list->{$context} // return;
Condition50%1/2
$self->_list->{$context} // (return)
l!l
10
MC/DC0%0/1
$self->_list->{$context} // (return)
$self->_list->{$context}
Truth table50%1/2
A
A= $self->_list->{$context}
Aresult
11
00
56  
57 1 delete $list->{$key}
58 }
59  
60 4 ▶sub fetch {
Subroutine fetch: called CC=4 SCAR=15.6
Pod documented
61 4 my ($self, $context, $key) = @_;
62
63 4 ▶ confess "fetch() needs a context and key"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context and defined $key 0 4 4
Condition33%1/3
defined $context and defined $key
!ll&&!rl&&r
004
MC/DC0%0/2
defined $context and defined $key
defined $context defined $key
Truth table33%1/3
A and B
A= defined $contextB= defined $key
ABresult
0X0
100
111
64 unless defined $context and defined $key;
65  
66 4 ▶ return unless exists $self->_list->{$context};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->_list->{$context} 0 4 4
67  
68 4 $self->_list->{$context}->{$key}
69 }
70  
71 3 ▶sub list {
Subroutine list: called CC=2 SCAR=7.2
Pod documented
72 3 my $self = shift;
73 3 ▶ wantarray ? $self->list_as_array(@_) : $self->list_as_ref(@_)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
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
Condition0%0/2
(shift())->list_as_ref(@_) || {}
l!l
00
MC/DC0%0/1
(shift())->list_as_ref(@_) || {}
(shift())->list_as_ref(@_)
Truth table0%0/2
A
A= (shift())->list_as_ref(@_)
Aresult
11
00
79  
80 3 ▶sub list_as_ref {
Subroutine list_as_ref: called CC=2 SCAR=6.9
Pod documented
81 3 my ($self, $context) = @_;
82 3 ▶ defined $context ? $self->_list->{$context} : $self->_list ;
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 2 1 3
83 }
84  
85 2 1;
86 __END__
« blib/lib/Bot/Cobalt/Lang.pm ↑ Summary blib/lib/Bot/Cobalt/Conf/File/Plugins.pm »