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