line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::File::Memory; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '1.16'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
419217
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
395205
|
|
|
3
|
|
|
|
|
21
|
|
6
|
3
|
|
|
3
|
|
808
|
use Moo; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
17
|
|
7
|
3
|
|
|
3
|
|
1152
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
231
|
|
8
|
3
|
|
|
3
|
|
1609
|
use Catmandu::Store::File::Memory::Index; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
135
|
|
9
|
3
|
|
|
3
|
|
1466
|
use Catmandu::Store::File::Memory::Bag; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
108
|
|
10
|
3
|
|
|
3
|
|
21
|
use namespace::clean; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
12
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::FileStore'; |
13
|
|
|
|
|
|
|
with 'Catmandu::Droppable'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _files => (is => 'ro', lazy => 1, default => sub {+{}}); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub drop { |
18
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
$self->index->delete_all; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
1; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
__END__ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=pod |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Catmandu::Store::File::Memory - A Catmandu::FileStore to keep files in memory |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# From Perl |
36
|
|
|
|
|
|
|
use Catmandu; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $store = Catmandu->store('File::Mempory'); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $index = $store->index; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# List all folders |
43
|
|
|
|
|
|
|
$index->each(sub { |
44
|
|
|
|
|
|
|
my $container = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
print "%s\n" , $container->{_id}; |
47
|
|
|
|
|
|
|
}); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Add a new folder |
50
|
|
|
|
|
|
|
$index->add({ _id => '1234' }); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Get the folder |
53
|
|
|
|
|
|
|
my $files = $index->files('1234'); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Add a file to the folder |
56
|
|
|
|
|
|
|
$files->upload(IO::File->new('<foobar.txt'), 'foobar.txt'); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Retrieve a file |
59
|
|
|
|
|
|
|
my $file = $files->get('foobar.txt'); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Stream the contents of a file |
62
|
|
|
|
|
|
|
$files->stream(IO::File->new('>foobar.txt'), $file); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Delete a file |
65
|
|
|
|
|
|
|
$files->delete('foobar.txt'); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Delete a container |
68
|
|
|
|
|
|
|
$index->delete('1234'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This Catmandu::FileStore implements: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over 3 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item L<Catmandu::FileStore> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=back |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The index Catmandu::Bag in this Catmandu::Store implements: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 3 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item L<Catmandu::FileBag::Index> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=back |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
The file Catmandu::Bag in this Catmandu::Store implements: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over 3 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item L<Catmandu::FileBag> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SEE ALSO |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L<Catmandu::Store::File::Memory::Index>, |
109
|
|
|
|
|
|
|
L<Catmandu::Store::File::Memory::Bag>, |
110
|
|
|
|
|
|
|
L<Catmandu::Plugin::SideCar>, |
111
|
|
|
|
|
|
|
L<Catmandu::FileStore> |