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
« Catmandu/Fix/disassoc.pm ↑ Summary Catmandu/Fix/log.pm »
1 package Catmandu::Store::Hash::Bag;
2  
3 16 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 16 our $VERSION = '1.2025';
6  
7 16 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Catmandu::Hits;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 16 with 'Catmandu::Bag';
13 16 with 'Catmandu::Droppable';
14  
15 16 has _hash =>
16 (is => 'rw', lazy => 1, init_arg => undef, builder => '_build_hash');
17 16 has _head => (is => 'rw', init_arg => undef, clearer => '_clear_head');
18 16 has _tail => (is => 'rw', init_arg => undef, clearer => '_clear_tail');
19  
20 27 ▶sub _build_hash {
Subroutine _build_hash: called CC=2 SCAR=7.2
21 27 my $self = $_[0];
22 27 ▶ $self->store->_hashes->{$self->name} ||= {};
Condition50%1/2
$self->store->_hashes->{$self->name} ||= {}
l!l
027
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 26 ▶sub generator {
Subroutine generator: called CC=1 SCAR=0.0
Pod undocumented
26 26 my $self = $_[0];
27 50 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
28 50 state $node = $self->_head;
29 50 state $data;
30 50 ▶ $node || return;
Branch: 1 branch
BranchTrueFalseTotal
$node or return 33 17 50
31 33 $data = $node->[1];
32 33 $node = $node->[2];
33 33 $data;
34 26 };
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
6115
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 75 ▶sub add {
Subroutine add: called CC=3 SCAR=11.0
Pod undocumented
44 75 my ($self, $data) = @_;
45 75 my $id = $data->{$self->id_key};
46 75 my $node = $self->_hash->{$id};
47 75 ▶ if ($node) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node) { } 10 65 75
elsif (my $tail = $self->_tail) { } 36 29 65
48 10 $node->[1] = clone($data);
49 }
50 elsif (my $tail = $self->_tail) {
51 36 $tail->[2] = $node = [$tail, clone($data), undef];
52 36 $self->_hash->{$id} = $node;
53 36 $self->_tail($node);
54 }
55 else {
56 29 $node = [undef, clone($data), undef];
57 29 $self->_hash->{$id} = $node;
58 29 $self->_head($node);
59 29 $self->_tail($node);
60 }
61 75 $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 83 ▶sub delete_all {
Subroutine delete_all: called CC=1 SCAR=0.0
Pod undocumented
83 83 my $self = $_[0];
84 83 $self->_clear_head;
85 68 $self->_clear_tail;
86 7 $self->_hash($self->store->_hashes->{$self->name} = {});
87 }
88  
89 3 ▶sub drop {
Subroutine drop: called CC=1 SCAR=0.0
Pod undocumented
90 3 $_[0]->delete_all;
91 }
92  
93 16 1;
94  
95 __END__
« Catmandu/Fix/disassoc.pm ↑ Summary Catmandu/Fix/log.pm »