line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::Hash::Bag; |
2
|
|
|
|
|
|
|
|
3
|
16
|
|
|
16
|
|
116
|
use Catmandu::Sane; |
|
16
|
|
|
|
|
39
|
|
|
16
|
|
|
|
|
107
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
16
|
|
|
16
|
|
123
|
use Moo; |
|
16
|
|
|
|
|
45
|
|
|
16
|
|
|
|
|
89
|
|
8
|
16
|
|
|
16
|
|
12666
|
use Catmandu::Hits; |
|
16
|
|
|
|
|
86
|
|
|
16
|
|
|
|
|
682
|
|
9
|
16
|
|
|
16
|
|
136
|
use Clone qw(clone); |
|
16
|
|
|
|
|
39
|
|
|
16
|
|
|
|
|
895
|
|
10
|
16
|
|
|
16
|
|
101
|
use namespace::clean; |
|
16
|
|
|
|
|
46
|
|
|
16
|
|
|
|
|
93
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
13
|
|
|
|
|
|
|
with 'Catmandu::Droppable'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _hash => |
16
|
|
|
|
|
|
|
(is => 'rw', lazy => 1, init_arg => undef, builder => '_build_hash'); |
17
|
|
|
|
|
|
|
has _head => (is => 'rw', init_arg => undef, clearer => '_clear_head'); |
18
|
|
|
|
|
|
|
has _tail => (is => 'rw', init_arg => undef, clearer => '_clear_tail'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_hash { |
21
|
27
|
|
|
27
|
|
280
|
my $self = $_[0]; |
22
|
27
|
|
50
|
|
|
473
|
$self->store->_hashes->{$self->name} ||= {}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub generator { |
26
|
26
|
|
|
26
|
0
|
63
|
my $self = $_[0]; |
27
|
|
|
|
|
|
|
sub { |
28
|
50
|
|
|
50
|
|
123
|
state $node = $self->_head; |
29
|
50
|
|
|
|
|
73
|
state $data; |
30
|
50
|
100
|
|
|
|
146
|
$node || return; |
31
|
33
|
|
|
|
|
75
|
$data = $node->[1]; |
32
|
33
|
|
|
|
|
59
|
$node = $node->[2]; |
33
|
33
|
|
|
|
|
146
|
$data; |
34
|
26
|
|
|
|
|
162
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get { |
38
|
|
|
|
|
|
|
my ($self, $id) = @_; |
39
|
|
|
|
|
|
|
my $node = $self->_hash->{$id} || return; |
40
|
|
|
|
|
|
|
clone($node->[1]); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub add { |
44
|
|
|
|
|
|
|
my ($self, $data) = @_; |
45
|
|
|
|
|
|
|
my $id = $data->{$self->id_key}; |
46
|
|
|
|
|
|
|
my $node = $self->_hash->{$id}; |
47
|
|
|
|
|
|
|
if ($node) { |
48
|
|
|
|
|
|
|
$node->[1] = clone($data); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif (my $tail = $self->_tail) { |
51
|
|
|
|
|
|
|
$tail->[2] = $node = [$tail, clone($data), undef]; |
52
|
|
|
|
|
|
|
$self->_hash->{$id} = $node; |
53
|
|
|
|
|
|
|
$self->_tail($node); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
|
|
|
|
|
|
$node = [undef, clone($data), undef]; |
57
|
|
|
|
|
|
|
$self->_hash->{$id} = $node; |
58
|
|
|
|
|
|
|
$self->_head($node); |
59
|
|
|
|
|
|
|
$self->_tail($node); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
$data; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub delete { |
65
|
|
|
|
|
|
|
my ($self, $id) = @_; |
66
|
|
|
|
|
|
|
my $node = $self->_hash->{$id} || return; |
67
|
|
|
|
|
|
|
if ($node->[0]) { |
68
|
|
|
|
|
|
|
$node->[0][2] = $node->[2]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
|
|
|
|
|
|
$self->_head($node->[2]); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
if ($node->[2]) { |
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
|
|
|
|
|
|
|
my $self = $_[0]; |
84
|
|
|
|
|
|
|
$self->_clear_head; |
85
|
|
|
|
|
|
|
$self->_clear_tail; |
86
|
|
|
|
|
|
|
$self->_hash($self->store->_hashes->{$self->name} = {}); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub drop { |
90
|
3
|
|
|
3
|
0
|
194
|
$_[0]->delete_all; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
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 |