line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::CHI::Bag; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use Moo; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
605
|
use CHI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
5
|
2
|
|
|
2
|
|
768
|
use Catmandu::IdGenerator::UUID; |
|
2
|
|
|
|
|
228545
|
|
|
2
|
|
|
|
|
720
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'chi' => (is => 'ro' , lazy => 1 , builder => 1); |
10
|
|
|
|
|
|
|
has 'idgen' => (is => 'ro' , lazy => 1 , builder => 1); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _build_chi { |
13
|
2
|
|
|
2
|
|
54
|
my ($self) = @_; |
14
|
2
|
|
|
|
|
12
|
my $driver = $self->store->driver; |
15
|
2
|
|
|
|
|
8
|
my $opts = $self->store->opts; |
16
|
2
|
|
|
|
|
9
|
my $name = __PACKAGE__ . '::' . $self->name; |
17
|
2
|
|
|
|
|
17
|
CHI->new(namespace => $name , driver => $driver, %$opts); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_idgen { |
21
|
0
|
|
|
0
|
|
0
|
Catmandu::IdGenerator::UUID->new; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub generator { |
25
|
7
|
|
|
7
|
0
|
8402
|
my $self = shift; |
26
|
7
|
|
|
|
|
127
|
my $keys = [ $self->chi->get_keys ]; |
27
|
|
|
|
|
|
|
sub { |
28
|
13
|
|
|
13
|
|
755
|
my $id = shift @$keys; |
29
|
|
|
|
|
|
|
|
30
|
13
|
100
|
|
|
|
33
|
return undef unless $id; |
31
|
|
|
|
|
|
|
|
32
|
7
|
|
|
|
|
118
|
$self->get($id); |
33
|
7
|
|
|
|
|
119
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get { |
37
|
|
|
|
|
|
|
my ($self,$id) = @_; |
38
|
|
|
|
|
|
|
$self->chi->get($id); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add { |
42
|
|
|
|
|
|
|
my ($self,$data) = @_; |
43
|
|
|
|
|
|
|
$data->{_id} //= $self->idgen->generate; |
44
|
|
|
|
|
|
|
my $id = $data->{_id}; |
45
|
|
|
|
|
|
|
$self->chi->set($id,$data); |
46
|
|
|
|
|
|
|
return $data; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub delete { |
50
|
|
|
|
|
|
|
my ($self,$id) = @_; |
51
|
|
|
|
|
|
|
$self->chi->remove($id); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub delete_all { |
55
|
|
|
|
|
|
|
my ($self) = @_; |
56
|
|
|
|
|
|
|
$self->chi->clear(); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub gen_id { |
60
|
0
|
|
|
0
|
0
|
|
Data::UUID->new->create_str(); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |