line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::Multi::Bag; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
106096
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
14
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
14
|
use Moo; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
8
|
2
|
|
|
2
|
|
779
|
use Hash::Merge::Simple qw(merge); |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
120
|
|
9
|
2
|
|
|
2
|
|
13
|
use namespace::clean; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
12
|
|
|
|
|
|
|
with 'Catmandu::Droppable'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub generator { |
15
|
4
|
|
|
4
|
0
|
12
|
my ($self) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Loop of all stores and find the first one that implements the bag |
18
|
|
|
|
|
|
|
# and can create a generator |
19
|
4
|
|
|
|
|
6
|
my $gen; |
20
|
4
|
|
|
|
|
9
|
for my $store (@{$self->store->stores}) { |
|
4
|
|
|
|
|
14
|
|
21
|
4
|
|
|
|
|
15
|
my $bag = $store->bag($self->name); |
22
|
4
|
50
|
|
|
|
19
|
$gen = $bag ? $bag->generator : undef; |
23
|
4
|
50
|
|
|
|
12
|
last if defined($gen); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
4
|
50
|
|
|
|
11
|
return undef unless $gen; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub { |
29
|
6
|
|
|
6
|
|
13
|
my $item = $gen->(); |
30
|
6
|
100
|
|
|
|
18
|
return undef unless $item; |
31
|
3
|
|
|
|
|
15
|
return $item; |
32
|
4
|
|
|
|
|
15
|
}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub get { |
36
|
|
|
|
|
|
|
my ($self, $id) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Loop over all the bags and merge the results of the records found |
39
|
|
|
|
|
|
|
# Required in case of Store/FileStore combinations where each part |
40
|
|
|
|
|
|
|
# can contain different metadata |
41
|
|
|
|
|
|
|
my $found = 0; |
42
|
|
|
|
|
|
|
my $result = {}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
for my $store (@{$self->store->stores}) { |
45
|
|
|
|
|
|
|
my $bag = $store->bag($self->name); |
46
|
|
|
|
|
|
|
my $item = $bag ? $bag->get($id) : undef; |
47
|
|
|
|
|
|
|
if ($item) { |
48
|
|
|
|
|
|
|
$found = 1; |
49
|
|
|
|
|
|
|
$result = merge $result , $item; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return $found ? $result : undef; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub add { |
57
|
|
|
|
|
|
|
my ($self, $data) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# By default try to add the data to all the stores |
60
|
|
|
|
|
|
|
for my $store (@{$self->store->stores}) { |
61
|
|
|
|
|
|
|
my $bag = $store->bag($self->name); |
62
|
|
|
|
|
|
|
$bag->add($data) if $bag; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub delete { |
69
|
|
|
|
|
|
|
my ($self, $id) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# By default try to delete the data from all the stores |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
for my $store (@{$self->store->stores}) { |
74
|
|
|
|
|
|
|
my $bag = $store->bag($self->name); |
75
|
|
|
|
|
|
|
$bag->delete($id) if $bag; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub delete_all { |
82
|
|
|
|
|
|
|
my ($self) = @_; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# By default try to drop the data from all the stores |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
for my $store (@{$self->store->stores}) { |
87
|
|
|
|
|
|
|
my $bag = $store->bag($self->name); |
88
|
|
|
|
|
|
|
$bag->delete_all if $bag; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub drop { |
95
|
1
|
|
|
1
|
0
|
3
|
my ($self) = @_; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# By default try to delete the data from all the stores |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
2
|
for my $store (@{$self->store->stores}) { |
|
1
|
|
|
|
|
5
|
|
100
|
2
|
|
|
|
|
10
|
my $bag = $store->bag($self->name); |
101
|
2
|
50
|
33
|
|
|
14
|
$bag->drop if $bag && $bag->does('Catmandu::Droppable'); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
3
|
1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub commit { |
108
|
|
|
|
|
|
|
my ($self) = @_; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# By default try to commit the data to all the stores |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
for my $store (@{$self->store->stores}) { |
113
|
|
|
|
|
|
|
my $bag = $store->bag($self->name); |
114
|
|
|
|
|
|
|
$bag->commit if $bag; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=pod |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Catmandu::Store::Multi::Bag - Bag implementation for the Multi store |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |