line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
16
|
|
|
16
|
|
538038
|
|
|
16
|
|
|
|
|
40
|
|
|
16
|
|
|
|
|
124
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
16
|
|
|
16
|
|
118
|
use Catmandu::Util qw(:is); |
|
16
|
|
|
|
|
32
|
|
|
16
|
|
|
|
|
106
|
|
8
|
16
|
|
|
16
|
|
5473
|
use Catmandu::Store::Hash::Bag; |
|
16
|
|
|
|
|
44
|
|
|
16
|
|
|
|
|
4142
|
|
9
|
16
|
|
|
16
|
|
6481
|
use namespace::clean; |
|
16
|
|
|
|
|
50
|
|
|
16
|
|
|
|
|
508
|
|
10
|
16
|
|
|
16
|
|
106
|
|
|
16
|
|
|
|
|
31
|
|
|
16
|
|
|
|
|
71
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Store'; |
12
|
|
|
|
|
|
|
with 'Catmandu::Droppable'; |
13
|
|
|
|
|
|
|
with 'Catmandu::Transactional'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _hashes => |
16
|
|
|
|
|
|
|
(is => 'ro', lazy => 1, init_arg => undef, default => sub {+{}}); |
17
|
|
|
|
|
|
|
has init_data => (is => 'ro'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my ($self) = @_; |
20
|
|
|
|
|
|
|
if (my $data = $self->init_data) { |
21
|
30
|
|
|
30
|
0
|
230
|
$self->bag->add($_) for @$data; |
22
|
30
|
100
|
|
|
|
222
|
} |
23
|
6
|
|
|
|
|
25
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
$_->drop for values %{$self->bags}; |
27
|
|
|
|
|
|
|
return; |
28
|
0
|
|
|
0
|
0
|
0
|
} |
29
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
30
|
0
|
|
|
|
|
0
|
my ($self, $coderef) = @_; |
31
|
|
|
|
|
|
|
&{$coderef} if is_code_ref($coderef); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
2
|
0
|
4339
|
1; |
35
|
2
|
50
|
|
|
|
9
|
|
|
2
|
|
|
|
|
4
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Catmandu::Store::Hash - An in-memory store |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Catmandu; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $store = Catmandu->store('Hash'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $obj1 = $store->bag->add({ name => 'Patrick' }); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
printf "obj1 stored as %s\n" , $obj1->{_id}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Force an id in the store |
54
|
|
|
|
|
|
|
my $obj2 = $store->bag->add({ _id => 'test123' , name => 'Nicolas' }); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $obj3 = $store->bag->get('test123'); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$store->bag->delete('test123'); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$store->bag->delete_all; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# All bags are iterators |
63
|
|
|
|
|
|
|
$store->bag->each(sub { ... }); |
64
|
|
|
|
|
|
|
$store->bag->take(10)->each(sub { ... }); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DESCRIPTION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
A Catmandu::Store::Hash is an in-memory L<Catmandu::Store> backed by a hash |
69
|
|
|
|
|
|
|
for fast retrieval combined with a doubly linked list for fast traversal. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 METHODS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 new([init_data => [...] ]) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Create a new Catmandu::Store::Hash. Optionally provide as init_data an array |
76
|
|
|
|
|
|
|
ref of data: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $store = Catmandu->store('Hash', init_data => [ |
79
|
|
|
|
|
|
|
{ _id => 1, data => foo } , |
80
|
|
|
|
|
|
|
{ _id => 2, data => bar } |
81
|
|
|
|
|
|
|
]); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# or in a catmandu.yml configuration file: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
--- |
86
|
|
|
|
|
|
|
store: |
87
|
|
|
|
|
|
|
hash: |
88
|
|
|
|
|
|
|
package: Hash |
89
|
|
|
|
|
|
|
options: |
90
|
|
|
|
|
|
|
init_data: |
91
|
|
|
|
|
|
|
- _id: 1 |
92
|
|
|
|
|
|
|
data: foo |
93
|
|
|
|
|
|
|
- _id: 2 |
94
|
|
|
|
|
|
|
data: bar |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This Catmandu::Store implements: |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=over 3 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item L<Catmandu::Store> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item L<Catmandu::Transactional> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Each Catmandu::Bag in this Catmandu::Store implements: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over 3 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=back |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |