line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::File::Multi::Index; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2178
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
26
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.14'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
822
|
use Moo; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
20
|
|
8
|
3
|
|
|
3
|
|
1119
|
use namespace::clean; |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
34
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'Catmandu::Store::Multi::Bag'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::FileBag::Index'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
1; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__END__ |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=pod |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Catmandu::Store::File::Multi::Index - Index of all "Folders" in a Catmandu::Store::File::Multi |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Catmandu; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $store = Catmandu->store('File::Multi' , stores [ |
29
|
|
|
|
|
|
|
Catmandu->store('File::Simple', root => '/data1/files') , |
30
|
|
|
|
|
|
|
Catmandu->store('File::Simple', root => '/data1/files_copy') , |
31
|
|
|
|
|
|
|
]); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $index = $store->index; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# List all containers |
36
|
|
|
|
|
|
|
$index->each(sub { |
37
|
|
|
|
|
|
|
my $container = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
print "%s\n" , $container->{_id}; |
40
|
|
|
|
|
|
|
}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Add a new folder |
43
|
|
|
|
|
|
|
$index->add({_id => '1234'}); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Delete a folder |
46
|
|
|
|
|
|
|
$index->delete(1234); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Get a folder |
49
|
|
|
|
|
|
|
my $folder = $index->get(1234); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Get the files in an folder |
52
|
|
|
|
|
|
|
my $files = $index->files(1234); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$files->each(sub { |
55
|
|
|
|
|
|
|
my $file = shift; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $name = $file->_id; |
58
|
|
|
|
|
|
|
my $size = $file->size; |
59
|
|
|
|
|
|
|
my $content_type = $file->content_type; |
60
|
|
|
|
|
|
|
my $created = $file->created; |
61
|
|
|
|
|
|
|
my $modified = $file->modified; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$file->stream(IO::File->new(">/tmp/$name"), file); |
64
|
|
|
|
|
|
|
}); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Add a file |
67
|
|
|
|
|
|
|
$files->upload(IO::File->new("<data.dat"),"data.dat"); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Retrieve a file |
70
|
|
|
|
|
|
|
my $file = $files->get("data.dat"); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Stream a file to an IO::Handle |
73
|
|
|
|
|
|
|
$files->stream(IO::File->new(">data.dat"),$file); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Delete a file |
76
|
|
|
|
|
|
|
$files->delete("data.dat"); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Delete a folders |
79
|
|
|
|
|
|
|
$index->delete("1234"); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This Catmandu::Bag implements: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 3 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item L<Catmandu::FileBag::Index> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |