line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::File::Multi; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
27279
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
24
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.14'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
821
|
use Catmandu::Util qw(:is); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
796
|
|
8
|
3
|
|
|
3
|
|
30
|
use Hash::Util::FieldHash qw(fieldhash); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
167
|
|
9
|
3
|
|
|
3
|
|
1336
|
use Catmandu::Store::Multi::Bag; |
|
3
|
|
|
|
|
21534
|
|
|
3
|
|
|
|
|
94
|
|
10
|
3
|
|
|
3
|
|
23
|
use Moo; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
12
|
|
11
|
3
|
|
|
3
|
|
1252
|
use namespace::clean; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
13
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Catmandu::FileStore'; |
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
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
for my $store (@{$self->stores}) { |
|
0
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
$store->drop if $store->does('Catmandu::Droppable'); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Catmandu::Store::File::Multi - A store that adds files to multiple stores |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# On the Command line |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Configure the File::Multi store with a catmandu.yml file |
58
|
|
|
|
|
|
|
$ cat catmandu.yml |
59
|
|
|
|
|
|
|
--- |
60
|
|
|
|
|
|
|
store: |
61
|
|
|
|
|
|
|
files1: |
62
|
|
|
|
|
|
|
package: File::Simple |
63
|
|
|
|
|
|
|
options: |
64
|
|
|
|
|
|
|
root: /data1/files |
65
|
|
|
|
|
|
|
files1: |
66
|
|
|
|
|
|
|
package: File::Simple |
67
|
|
|
|
|
|
|
options: |
68
|
|
|
|
|
|
|
root: /data1/files_copy |
69
|
|
|
|
|
|
|
multi: |
70
|
|
|
|
|
|
|
package: File::Multi |
71
|
|
|
|
|
|
|
options: |
72
|
|
|
|
|
|
|
stores: |
73
|
|
|
|
|
|
|
- files1 |
74
|
|
|
|
|
|
|
- files2 |
75
|
|
|
|
|
|
|
... |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# List all the folder in the multi store as YAML |
78
|
|
|
|
|
|
|
$ catmandu export multi to YAML |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Add a file to the multi store with ID 7890 and stored name data.dat |
81
|
|
|
|
|
|
|
$ catmandu stream /tmp/data.dat to multi --bag 7890 --id data.dat |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Download a file from the multi store |
84
|
|
|
|
|
|
|
$ catmandu stream multi --bag 7890 --id data.dat |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# In Perl |
87
|
|
|
|
|
|
|
use Catmandu; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $store = Catmandu->store('File::Multi' , stores [ |
90
|
|
|
|
|
|
|
Catmandu->store('Simple', root => '/data1/files') , |
91
|
|
|
|
|
|
|
Catmandu->store('Simple', root => '/data1/files_copy') , |
92
|
|
|
|
|
|
|
]); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $index = $store->index; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$store->index->each(sub { |
97
|
|
|
|
|
|
|
my $item = shift; |
98
|
|
|
|
|
|
|
printf "%s\n" , $item->{_id}; |
99
|
|
|
|
|
|
|
}); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Add a folder to the multi store |
102
|
|
|
|
|
|
|
my $item = $store->add({ _id => '1234'); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Retrieve the folder bag |
105
|
|
|
|
|
|
|
my $files = $store->files(1234); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Listing of all files |
108
|
|
|
|
|
|
|
$files->each(sub { |
109
|
|
|
|
|
|
|
my $file = shift; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $name = $file->_id; |
112
|
|
|
|
|
|
|
my $size = $file->size; |
113
|
|
|
|
|
|
|
my $content_type = $file->content_type; |
114
|
|
|
|
|
|
|
my $created = $file->created; |
115
|
|
|
|
|
|
|
my $modified = $file->modified; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$file->stream(IO::File->new(">/tmp/$name"), file); |
118
|
|
|
|
|
|
|
}); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Add a new file |
121
|
|
|
|
|
|
|
$files->upload(IO::File->new("</tmp/data.dat"),"data.dat"); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Retrieve a file |
124
|
|
|
|
|
|
|
my $file = $files->get('data.dat'); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Stream the file to an IO::Handle |
127
|
|
|
|
|
|
|
$container->stream(IO::File->new(">/tmp/data.dat"),$file); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# This will delete the folder and files |
130
|
|
|
|
|
|
|
$index->delete('1234'); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 DESCRIPTION |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The L<Catmandu::Store::File::Multi> is a combination of many L<Catmandu::FileStore>-s |
135
|
|
|
|
|
|
|
as one access point. The Multi store inherits all the methods |
136
|
|
|
|
|
|
|
from L<Catmandu::FileStore>. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
By default, the Multi store tries to update records in all configured backend |
139
|
|
|
|
|
|
|
stores. Importing, exporting, delete and drop will be executed against |
140
|
|
|
|
|
|
|
all backend stores when possible. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 METHODS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 new(stores => [...]) |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Create a new Catmandu::Store::File::Multi. The C<stores> configuration parameter contains an array of references to |
147
|
|
|
|
|
|
|
L<Catmandu::FileStore>-s based on their name in a configuration file or instances. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This Catmandu::FileStore implements: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over 3 |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item L<Catmandu::FileStore> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
The index Catmandu::Bag in this Catmandu::Store implements: |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=over 3 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item L<Catmandu::FileBag::Index> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The file Catmandu::Bag in this Catmandu::Store implements: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over 3 |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item L<Catmandu::FileBag> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 SEE ALSO |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L<Catmandu::Store::File::Multi::Index>, |
188
|
|
|
|
|
|
|
L<Catmandu::Store::File::Multi::Bag>, |
189
|
|
|
|
|
|
|
L<Catmandu::Store::Multi> , |
190
|
|
|
|
|
|
|
L<Catmandu::Plugin::SideCar> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |