line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::File::MediaHaven::Index; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
17
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
22
|
|
6
|
3
|
|
|
3
|
|
652
|
use Moo; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
23
|
|
7
|
3
|
|
|
3
|
|
1004
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
213
|
|
8
|
3
|
|
|
3
|
|
920
|
use POSIX qw(ceil); |
|
3
|
|
|
|
|
14015
|
|
|
3
|
|
|
|
|
26
|
|
9
|
3
|
|
|
3
|
|
4451
|
use Catmandu::Store::File::MediaHaven::Searcher; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
111
|
|
10
|
3
|
|
|
3
|
|
22
|
use namespace::clean; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
24
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
13
|
|
|
|
|
|
|
with 'Catmandu::Searchable'; |
14
|
|
|
|
|
|
|
with 'Catmandu::FileBag::Index'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub generator { |
17
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $searcher = Catmandu::Store::File::MediaHaven::Searcher->new( |
20
|
|
|
|
|
|
|
bag => $self , |
21
|
|
|
|
|
|
|
limit => undef , |
22
|
|
|
|
|
|
|
start => 0 , |
23
|
|
|
|
|
|
|
sort => undef , |
24
|
|
|
|
|
|
|
query => undef , |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $searcher->generator; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub exists { |
31
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
croak "Need a key" unless defined $id; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $res = $self->store->mh->record($id); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
defined($res); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub add { |
41
|
|
|
|
|
|
|
my ($self, $data) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
croak "Add is not supported in the MediaHaven FileStore"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get { |
47
|
|
|
|
|
|
|
my ($self, $id) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $res = $self->store->mh->record($id); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
if ($res) { |
52
|
|
|
|
|
|
|
return +{_id => $id}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
|
|
|
|
|
|
return undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub delete { |
60
|
|
|
|
|
|
|
my ($self, $id) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
croak "Delete is not supported in the MediaHaven FileStore"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub delete_all { |
66
|
|
|
|
|
|
|
my ($self) = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
croak "Delete is not supported in the MediaHaven FileStore"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub delete_by_query { |
72
|
|
|
|
|
|
|
my ($self, %args) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
croak "Delete is not supported in the MediaHaven FileStore"; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub search { |
78
|
|
|
|
|
|
|
my ($self, %args) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
croak "Search is not supported in the MediaHaven FileStore"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub searcher { |
84
|
|
|
|
|
|
|
my ($self, %args) = @_; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Catmandu::Store::File::MediaHaven::Searcher->new(%args, bag => $self); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub count { |
90
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $mh = $self->store->mh; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $res = $mh->search(undef); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$res->{totalNrOfResults}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub commit { |
100
|
|
|
|
|
|
|
return 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=pod |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 NAME |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Catmandu::Store::File::MediaHaven::Index - Index of all "Folders" in a MediaHaven database |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SYNOPSIS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
use Catmandu; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $store = Catmandu->store('File::MediaHaven' , |
118
|
|
|
|
|
|
|
url => '...' , |
119
|
|
|
|
|
|
|
username => '...' , |
120
|
|
|
|
|
|
|
password => '...' , |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $index = $store->index; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# List all containers |
126
|
|
|
|
|
|
|
$index->each(sub { |
127
|
|
|
|
|
|
|
my $container = shift; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
print "%s\n" , $container->{_id}; |
130
|
|
|
|
|
|
|
}); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Get a folder |
133
|
|
|
|
|
|
|
my $folder = $index->get(1234); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Get the files in an folder |
136
|
|
|
|
|
|
|
my $files = $index->files(1234); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$files->each(sub { |
139
|
|
|
|
|
|
|
my $file = shift; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my $name = $file->_id; |
142
|
|
|
|
|
|
|
my $size = $file->size; |
143
|
|
|
|
|
|
|
my $content_type = $file->content_type; |
144
|
|
|
|
|
|
|
my $created = $file->created; |
145
|
|
|
|
|
|
|
my $modified = $file->modified; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$file->stream(IO::File->new(">/tmp/$name"), file); |
148
|
|
|
|
|
|
|
}); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# Retrieve a file |
151
|
|
|
|
|
|
|
my $file = $files->get("data.dat"); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Stream a file to an IO::Handle |
154
|
|
|
|
|
|
|
$files->stream(IO::File->new(">data.dat"),$file); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This Catmandu::Bag implements: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=over 3 |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item L<Catmandu::FileBag::Index> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |