blib/lib/Catmandu/Store/Hash/Bag.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 80.0% 8 / 10 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 89.5% 77 / 86 CC 9 SCAR 9.3
CC
9
Cov
94%
delete
6.0
add
3.0
_build_hash
2.1
CRAP 2.5
« blib/lib/Catmandu/Fix/Condition/exists.pm ↑ Summary blib/lib/Catmandu/Store/Hash.pm »
1 package Catmandu::Store::Hash::Bag;
2  
3 13 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '1.0201_02';
6  
7 13 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Catmandu::Hits;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 with 'Catmandu::Bag';
13 13 with 'Catmandu::Droppable';
14  
15 13 has _hash =>
16 (is => 'rw', lazy => 1, init_arg => undef, builder => '_build_hash');
17 13 has _head => (is => 'rw', init_arg => undef, clearer => '_clear_head');
18 13 has _tail => (is => 'rw', init_arg => undef, clearer => '_clear_tail');
19  
20 sub _build_hash {
21 19 ▶ my $self = $_[0];
Subroutine _build_hash: called CC=2 SCAR=7.2
22 19 ▶ $self->store->_hashes->{$self->name} ||= {};
Condition50%1/2
$self->store->_hashes->{$self->name} ||= {}
l!l
019
MC/DC0%0/1
$self->store->_hashes->{$self->name} ||= {}
$self->store->_hashes->{$self->name}
Truth table50%1/2
A
A= $self->store->_hashes->{$self->name}
Aresult
11
00
23 }
24  
25 sub generator {
26 22 ▶ my $self = $_[0];
Subroutine generator: called CC=1 SCAR=0.0
Pod undocumented
27 sub {
28 46 ▶ state $node = $self->_head;
Subroutine __ANON__: called CC=2 SCAR=6.9
29 46 state $data;
30 46 ▶ $node || return;
Branch: 1 branch
BranchTrueFalseTotal
$node or return 16 30 46
31 30 $data = $node->[1];
32 30 $node = $node->[2];
33 30 $data;
34 22 };
35 }
36  
37 sub get {
38 3 my ($self, $id) = @_;
39 3 ▶ my $node = $self->_hash->{$id} || return;
Condition100%2/2
$self->_hash->{$id} || (return)
l!l
5110
MC/DC100%1/1
$self->_hash->{$id} || (return)
$self->_hash->{$id}
Truth table100%2/2
A
A= $self->_hash->{$id}
Aresult
11
00
40 3 clone($node->[1]);
41 }
42  
43 sub add {
44 56 ▶ my ($self, $data) = @_;
Subroutine add: called CC=3 SCAR=11.0
Pod undocumented
45 56 my $id = $data->{$self->id_key};
46 56 my $node = $self->_hash->{$id};
47 56 ▶ if ($node) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node) { } 8 48 56
elsif (my $tail = $self->_tail) { } 27 21 48
48 8 $node->[1] = clone($data);
49 }
50 elsif (my $tail = $self->_tail) {
51 27 $tail->[2] = $node = [$tail, clone($data), undef];
52 27 $self->_hash->{$id} = $node;
53 27 $self->_tail($node);
54 }
55 else {
56 21 $node = [undef, clone($data), undef];
57 21 $self->_hash->{$id} = $node;
58 21 $self->_head($node);
59 21 $self->_tail($node);
60 }
61 56 $data;
62 }
63  
64 sub delete {
65 0 my ($self, $id) = @_;
66 3 my $node = $self->_hash->{$id} || return;
67 ▶ if ($node->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->[0]) { } 0 3 3
68 $node->[0][2] = $node->[2];
69 }
70 else {
71 $self->_head($node->[2]);
72 }
73 ▶ if ($node->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->[2]) { } 3 0 3
74 $node->[2][0] = $node->[0];
75 }
76 else {
77 $self->_tail($node->[0]);
78 }
79 delete $self->_hash->{$id};
80 }
81  
82 sub delete_all {
83 67 ▶ my $self = $_[0];
Subroutine delete_all: called CC=1 SCAR=0.0
Pod undocumented
84 67 $self->_clear_head;
85 57 $self->_clear_tail;
86 6 $self->_hash($self->store->_hashes->{$self->name} = {});
87 }
88  
89 sub drop {
90 2 ▶ $_[0]->delete_all;
Subroutine drop: called CC=1 SCAR=0.0
Pod undocumented
91 }
92  
93 13 1;
94  
95 __END__
96  
97 =pod
98  
99 =head1 NAME
100  
101 Catmandu::Store::Hash::Bag - Bag implementation for the Hash store
102  
103 =cut
« blib/lib/Catmandu/Fix/Condition/exists.pm ↑ Summary blib/lib/Catmandu/Store/Hash.pm »