line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::Multi; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
741
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Catmandu::Util qw(:is); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
274
|
|
8
|
1
|
|
|
1
|
|
10
|
use Hash::Util::FieldHash qw(fieldhash); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
9
|
1
|
|
|
1
|
|
416
|
use Catmandu::Store::Multi::Bag; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
30
|
|
10
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
11
|
1
|
|
|
1
|
|
411
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Catmandu::Store'; |
14
|
|
|
|
|
|
|
with 'Catmandu::Droppable'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has stores => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
default => sub {[]}, |
20
|
|
|
|
|
|
|
coerce => sub { |
21
|
|
|
|
|
|
|
my $stores = $_[0]; |
22
|
|
|
|
|
|
|
return [ |
23
|
|
|
|
|
|
|
map { |
24
|
|
|
|
|
|
|
if (is_string($_)) { |
25
|
|
|
|
|
|
|
Catmandu->store($_); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
|
|
|
|
|
|
$_; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} @$stores |
31
|
|
|
|
|
|
|
]; |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub drop { |
36
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
37
|
0
|
|
|
|
|
|
for my $store (@{$self->stores}) { |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$store->drop; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=pod |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Catmandu::Store::Multi - A store that adds data to multiple stores |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 SYNOPSIS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# On the Command line |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Configure the Multi store with a catmandu.yml file |
57
|
|
|
|
|
|
|
$ cat catmandu.yml |
58
|
|
|
|
|
|
|
--- |
59
|
|
|
|
|
|
|
store: |
60
|
|
|
|
|
|
|
metadata1: |
61
|
|
|
|
|
|
|
package: DBI |
62
|
|
|
|
|
|
|
options: |
63
|
|
|
|
|
|
|
data_source: "DBI:mysql:database=catmandu" |
64
|
|
|
|
|
|
|
metadata2: |
65
|
|
|
|
|
|
|
package: ElasticSearch |
66
|
|
|
|
|
|
|
options: |
67
|
|
|
|
|
|
|
client: '1_0::Direct' |
68
|
|
|
|
|
|
|
index_name: catmandu |
69
|
|
|
|
|
|
|
multi: |
70
|
|
|
|
|
|
|
package: Multi |
71
|
|
|
|
|
|
|
options: |
72
|
|
|
|
|
|
|
stores: |
73
|
|
|
|
|
|
|
- metadata1 |
74
|
|
|
|
|
|
|
- metadata2 |
75
|
|
|
|
|
|
|
... |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Add a YAML record to the multi store |
78
|
|
|
|
|
|
|
$ catmandu import YAML to multi < data.yml |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Extract all the records from the multi store as YAML |
81
|
|
|
|
|
|
|
$ catmandu export multi to YAML > data.yml |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# In Perl |
84
|
|
|
|
|
|
|
use Catmandu; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $store = Catmandu->store('Multi' , stores [ |
87
|
|
|
|
|
|
|
Catmandu->store('DBI', data_source => 'DBI:mysql:database=catmandu') , |
88
|
|
|
|
|
|
|
Catmandu->store('ElasticSearch', client => '1_0::Direct', index_name => 'catmandu') , |
89
|
|
|
|
|
|
|
]); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$store->bag->each(sub { |
92
|
|
|
|
|
|
|
my $item = shift; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
printf "%s\n" , $item->{_id}; |
95
|
|
|
|
|
|
|
}); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$store->bag->add({ _id => 1234 , foo => 'bar' , test => [qw(1 2 3 4)]}); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $item = $store->bag->get('1234'); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$store->bag->delete('1234'); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The L<Catmandu::Store::Multi> is a combination of many L<Catmandu::Store>-s |
106
|
|
|
|
|
|
|
as one access point. The Multi store inherits all the methods |
107
|
|
|
|
|
|
|
from L<Catmandu::Store>. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
By default, the Multi store tries to update records in all configured backend |
110
|
|
|
|
|
|
|
stores. Importing, exporting, delete and drop will be executed against |
111
|
|
|
|
|
|
|
all backend stores when possible. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 new(stores => [...]) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Create a new Catmandu::Store::Multi.The C<store> configuration parameter |
118
|
|
|
|
|
|
|
contains an array of references to L<Catmandu::Store>-s based on their name in |
119
|
|
|
|
|
|
|
a configuration file or instances. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This Catmandu::Store implements: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over 3 |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item L<Catmandu::Store> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Each Catmandu::Bag in this Catmandu::Store implements: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 3 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=back |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |