| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Store::File::MediaHaven::Bag; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
19
|
use Catmandu::Sane; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
23
|
|
|
6
|
3
|
|
|
3
|
|
600
|
use Moo; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
23
|
|
|
7
|
3
|
|
|
3
|
|
985
|
use Carp; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
174
|
|
|
8
|
3
|
|
|
3
|
|
1103
|
use Date::Parse; |
|
|
3
|
|
|
|
|
15234
|
|
|
|
3
|
|
|
|
|
328
|
|
|
9
|
3
|
|
|
3
|
|
25
|
use POSIX qw(ceil); |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
25
|
|
|
10
|
3
|
|
|
3
|
|
204
|
use namespace::clean; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
|
13
|
|
|
|
|
|
|
with 'Catmandu::FileBag'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub generator { |
|
16
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $mh = $self->store->mh; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $res = $mh->record($self->name); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub { |
|
23
|
0
|
|
|
0
|
|
|
state $done = 0; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
return undef if $done; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$done = 1; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return $self->_get($res,$res->{originalFileName}); |
|
30
|
0
|
|
|
|
|
|
}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _get { |
|
34
|
0
|
|
|
0
|
|
|
my ($self,$result,$key) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $mh = $self->store->mh; |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
return undef unless $result; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
return undef unless $result->{originalFileName} eq $key; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $md5; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
for my $prop (@{$result->{mdProperties}}) { |
|
|
0
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($prop->{attribute} eq 'md5_viaa') { |
|
46
|
0
|
|
|
|
|
|
$md5 = $prop->{value}; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return +{ |
|
51
|
|
|
|
|
|
|
_id => $key, |
|
52
|
|
|
|
|
|
|
size => -1, |
|
53
|
|
|
|
|
|
|
md5 => $md5 ? $md5 : 'none', |
|
54
|
|
|
|
|
|
|
created => str2time($result->{archiveDate}), |
|
55
|
|
|
|
|
|
|
modified => str2time($result->{lastModifiedDate}), |
|
56
|
|
|
|
|
|
|
content_type => 'application/zip', |
|
57
|
|
|
|
|
|
|
_stream => sub { |
|
58
|
0
|
|
|
0
|
|
|
my $out = $_[0]; |
|
59
|
0
|
|
|
|
|
|
my $bytes = 0; |
|
60
|
|
|
|
|
|
|
$mh->export($self->name, sub { |
|
61
|
0
|
|
|
|
|
|
my $data = shift; |
|
62
|
|
|
|
|
|
|
# Support the Dancer send_file "write" callback |
|
63
|
0
|
0
|
|
|
|
|
if ($out->can('syswrite')) { |
|
64
|
0
|
|
0
|
|
|
|
$bytes += $out->syswrite($data) || die "failed to write : $!"; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
else { |
|
67
|
0
|
|
0
|
|
|
|
$bytes += $out->write($data) || die "failed to write : $!";; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
|
|
|
|
|
}); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$out->close(); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$bytes; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
0
|
0
|
|
|
|
|
}; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub exists { |
|
79
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $mh = $self->store->mh; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $res = $mh->record($self->name); |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$res->{originalFileName} eq $id; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get { |
|
89
|
|
|
|
|
|
|
my ($self, $id) = @_; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $mh = $self->store->mh; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $res = $mh->record($self->name); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return $self->_get($res,$id); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub add { |
|
99
|
|
|
|
|
|
|
my ($self, $data) = @_; |
|
100
|
|
|
|
|
|
|
croak "Add is not supported in the MediaHaven FileStore"; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub delete { |
|
104
|
|
|
|
|
|
|
my ($self, $id) = @_; |
|
105
|
|
|
|
|
|
|
croak "Delete is not supported in the MediaHaven FileStore"; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub delete_all { |
|
109
|
|
|
|
|
|
|
my ($self) = @_; |
|
110
|
|
|
|
|
|
|
croak "Delete is not supported in the MediaHaven FileStore"; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub commit { |
|
114
|
|
|
|
|
|
|
return 1; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=pod |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 NAME |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Catmandu::Store::File::MediaHaven::Bag - Index of all "files" in a Catmandu::Store::File::MediaHaven "folder" |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
use Catmandu; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $store = Catmandu->store('File::MediaHaven' , |
|
132
|
|
|
|
|
|
|
url => '...' , |
|
133
|
|
|
|
|
|
|
username => '...' , |
|
134
|
|
|
|
|
|
|
password => '...' , |
|
135
|
|
|
|
|
|
|
); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $index = $store->index; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# List all containers |
|
140
|
|
|
|
|
|
|
$index->each(sub { |
|
141
|
|
|
|
|
|
|
my $container = shift; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
print "%s\n" , $container->{_id}; |
|
144
|
|
|
|
|
|
|
}); |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# Get a folder |
|
147
|
|
|
|
|
|
|
my $folder = $index->get(1234); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Get the files in an folder |
|
150
|
|
|
|
|
|
|
my $files = $index->files(1234); |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$files->each(sub { |
|
153
|
|
|
|
|
|
|
my $file = shift; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my $name = $file->_id; |
|
156
|
|
|
|
|
|
|
my $size = $file->size; |
|
157
|
|
|
|
|
|
|
my $content_type = $file->content_type; |
|
158
|
|
|
|
|
|
|
my $created = $file->created; |
|
159
|
|
|
|
|
|
|
my $modified = $file->modified; |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$file->stream(IO::File->new(">/tmp/$name"), file); |
|
162
|
|
|
|
|
|
|
}); |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# Retrieve a file |
|
165
|
|
|
|
|
|
|
my $file = $files->get("data.dat"); |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Stream a file to an IO::Handle |
|
168
|
|
|
|
|
|
|
$files->stream(IO::File->new(">data.dat"),$file); |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This Catmandu::Bag implements: |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 3 |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item L<Catmandu::FileBag> |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |