| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package METS::Files; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
87528
|
use strict; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
64
|
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
78
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
988
|
use Class::Utils qw(set_params); |
|
|
2
|
|
|
|
|
63237
|
|
|
|
2
|
|
|
|
|
44
|
|
|
7
|
2
|
|
|
2
|
|
347
|
use Error::Pure qw(err); |
|
|
2
|
|
|
|
|
11
|
|
|
|
2
|
|
|
|
|
99
|
|
|
8
|
2
|
|
|
2
|
|
1142
|
use METS::Parse::Simple; |
|
|
2
|
|
|
|
|
21465
|
|
|
|
2
|
|
|
|
|
76
|
|
|
9
|
2
|
|
|
2
|
|
20
|
use Readonly; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
991
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Readonly::Scalar our $EMPTY_STR => q{}; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constructor. |
|
16
|
|
|
|
|
|
|
sub new { |
|
17
|
0
|
|
|
0
|
1
|
|
my ($class, @params) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Create object. |
|
20
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# METS Data. |
|
23
|
0
|
|
|
|
|
|
$self->{'mets_data'} = undef; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Process parameters. |
|
26
|
0
|
|
|
|
|
|
set_params($self, @params); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Check METS data. |
|
29
|
0
|
0
|
|
|
|
|
if (! defined $self->{'mets_data'}) { |
|
30
|
0
|
|
|
|
|
|
err "Parameter 'mets_data' is required."; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
0
|
|
|
|
|
|
$self->{'_mets'} = METS::Parse::Simple->new->parse($self->{'mets_data'}); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Compute prefix. |
|
35
|
0
|
|
|
|
|
|
$self->{'_prefix'} = $EMPTY_STR; |
|
36
|
0
|
0
|
|
|
|
|
if (exists $self->{'_mets'}->{'xmlns:mets'}) { |
|
37
|
0
|
|
|
|
|
|
$self->{'_prefix'} = 'mets:'; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Get img files. |
|
44
|
|
|
|
|
|
|
sub get_use_files { |
|
45
|
0
|
|
|
0
|
1
|
|
my ($self, $use) = @_; |
|
46
|
0
|
|
|
|
|
|
my @files; |
|
47
|
0
|
0
|
0
|
|
|
|
if (exists $self->{'_mets'}->{$self->{'_prefix'}.'fileSec'} |
|
48
|
|
|
|
|
|
|
&& exists $self->{'_mets'}->{$self->{'_prefix'}.'fileSec'} |
|
49
|
|
|
|
|
|
|
->{$self->{'_prefix'}.'fileGrp'}) { |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
foreach my $mets_file_grp_hr (@{$self->{'_mets'} |
|
52
|
|
|
|
|
|
|
->{$self->{'_prefix'}.'fileSec'} |
|
53
|
0
|
|
|
|
|
|
->{$self->{'_prefix'}.'fileGrp'}}) { |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ($mets_file_grp_hr->{'USE'} eq $use) { |
|
56
|
0
|
|
|
|
|
|
foreach my $file_hr (@{$mets_file_grp_hr |
|
57
|
0
|
|
|
|
|
|
->{$self->{'_prefix'}.'file'}}) { |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
push @files, $file_hr |
|
60
|
|
|
|
|
|
|
->{$self->{'_prefix'}.'FLocat'} |
|
61
|
0
|
|
|
|
|
|
->{'xlink:href'}; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
0
|
|
|
|
|
|
return @files; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_use_types { |
|
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Get file types. |
|
73
|
0
|
|
|
|
|
|
my @file_types; |
|
74
|
0
|
0
|
0
|
|
|
|
if (exists $self->{'_mets'}->{$self->{'_prefix'}.'fileSec'} |
|
75
|
|
|
|
|
|
|
&& exists $self->{'_mets'}->{$self->{'_prefix'}.'fileSec'} |
|
76
|
|
|
|
|
|
|
->{$self->{'_prefix'}.'fileGrp'}) { |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
foreach my $mets_file_grp_hr (@{$self->{'_mets'} |
|
79
|
|
|
|
|
|
|
->{$self->{'_prefix'}.'fileSec'} |
|
80
|
0
|
|
|
|
|
|
->{$self->{'_prefix'}.'fileGrp'}}) { |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
push @file_types, $mets_file_grp_hr->{'USE'}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return @file_types; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding utf8 |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
METS::Files - Class for METS files manipulation. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use METS::Files; |
|
104
|
|
|
|
|
|
|
my $obj = METS::Files->new( |
|
105
|
|
|
|
|
|
|
'mets_data' => $mets_data, |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
my @files = $obj->get_use_files($use); |
|
108
|
|
|
|
|
|
|
my @types = $obj->get_use_types; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 METHODS |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over 8 |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item C<new()> |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Constructor. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 8 |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * C<mets_data> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
METS data. |
|
123
|
|
|
|
|
|
|
Parameter is required. |
|
124
|
|
|
|
|
|
|
Default value is undef. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item C<get_use_files($use)> |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Get "USE" files. |
|
131
|
|
|
|
|
|
|
Returns array with files. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item C<get_use_types()> |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Get "USE" types. |
|
136
|
|
|
|
|
|
|
Returns array with types. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 ERRORS |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
new(): |
|
143
|
|
|
|
|
|
|
Parameter 'mets_data' is required. |
|
144
|
|
|
|
|
|
|
From Class::Utils::set_params(): |
|
145
|
|
|
|
|
|
|
Unknown parameter '%s'. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
use strict; |
|
150
|
|
|
|
|
|
|
use warnings; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
use Data::Printer; |
|
153
|
|
|
|
|
|
|
use METS::Files; |
|
154
|
|
|
|
|
|
|
use Perl6::Slurp qw(slurp); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# Arguments. |
|
157
|
|
|
|
|
|
|
if (@ARGV < 1) { |
|
158
|
|
|
|
|
|
|
print STDERR "Usage: $0 mets_file\n"; |
|
159
|
|
|
|
|
|
|
exit 1; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
my $mets_file = $ARGV[0]; |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Get mets data. |
|
164
|
|
|
|
|
|
|
my $mets_data = slurp($mets_file); |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# Object. |
|
167
|
|
|
|
|
|
|
my $obj = METS::Files->new( |
|
168
|
|
|
|
|
|
|
'mets_data' => $mets_data, |
|
169
|
|
|
|
|
|
|
); |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Get files. |
|
172
|
|
|
|
|
|
|
my $files_hr; |
|
173
|
|
|
|
|
|
|
foreach my $use ($obj->get_use_types) { |
|
174
|
|
|
|
|
|
|
$files_hr->{$use} = [$obj->get_use_files($use)]; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# Dump to output. |
|
178
|
|
|
|
|
|
|
p $files_hr; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Output without arguments like: |
|
181
|
|
|
|
|
|
|
# Usage: __SCRIPT__ mets_file |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
use strict; |
|
186
|
|
|
|
|
|
|
use warnings; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
use Data::Printer; |
|
189
|
|
|
|
|
|
|
use METS::Files; |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Example METS data. |
|
192
|
|
|
|
|
|
|
my $mets_data = <<'END'; |
|
193
|
|
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
194
|
|
|
|
|
|
|
<mets xmlns:xlink="http://www.w3.org/TR/xlink"> |
|
195
|
|
|
|
|
|
|
<fileSec> |
|
196
|
|
|
|
|
|
|
<fileGrp ID="IMGGRP" USE="Images"> |
|
197
|
|
|
|
|
|
|
<file ID="IMG00001" CREATED="2006-06-20T12:00:00" ADMID="IMGPARAM00001" MIMETYPE="image/tiff" SEQ="1" SIZE="5184000" GROUPID="1"> |
|
198
|
|
|
|
|
|
|
<FLocat LOCTYPE="URL" xlink:href="file://./003855/003855r.tif" /> |
|
199
|
|
|
|
|
|
|
</file> |
|
200
|
|
|
|
|
|
|
<file ID="IMG00002" CREATED="2006-06-20T12:00:00" ADMID="IMGPARAM00002" MIMETYPE="image/tiff" SEQ="2" SIZE="5200228" GROUPID="2"> |
|
201
|
|
|
|
|
|
|
<FLocat LOCTYPE="URL" xlink:href="file://./003855/003855v.tif" /> |
|
202
|
|
|
|
|
|
|
</file> |
|
203
|
|
|
|
|
|
|
</fileGrp> |
|
204
|
|
|
|
|
|
|
<fileGrp ID="PDFGRP" USE="PDF"> |
|
205
|
|
|
|
|
|
|
<file ID="PDF00001" CREATED="2006-06-20T12:00:00" ADMID="IMGPARAM00001" MIMETYPE="text/pdf" SEQ="1" SIZE="251967" GROUPID="1"> |
|
206
|
|
|
|
|
|
|
<FLocat LOCTYPE="URL" xlink:href="file://./003855/003855r.pdf" /> |
|
207
|
|
|
|
|
|
|
</file> |
|
208
|
|
|
|
|
|
|
<file ID="PDF00002" CREATED="2006-06-20T12:00:00" ADMID="IMGPARAM00002" MIMETYPE="text/pdf" SEQ="2" SIZE="172847" GROUPID="2"> |
|
209
|
|
|
|
|
|
|
<FLocat LOCTYPE="URL" xlink:href="file://./003855/003855v.pdf" /> |
|
210
|
|
|
|
|
|
|
</file> |
|
211
|
|
|
|
|
|
|
</fileGrp> |
|
212
|
|
|
|
|
|
|
</fileSec> |
|
213
|
|
|
|
|
|
|
</mets> |
|
214
|
|
|
|
|
|
|
END |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# Object. |
|
217
|
|
|
|
|
|
|
my $obj = METS::Files->new( |
|
218
|
|
|
|
|
|
|
'mets_data' => $mets_data, |
|
219
|
|
|
|
|
|
|
); |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# Get files. |
|
222
|
|
|
|
|
|
|
my $files_hr; |
|
223
|
|
|
|
|
|
|
foreach my $use ($obj->get_use_types) { |
|
224
|
|
|
|
|
|
|
$files_hr->{$use} = [$obj->get_use_files($use)]; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Dump to output. |
|
228
|
|
|
|
|
|
|
p $files_hr; |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# Output: |
|
231
|
|
|
|
|
|
|
# \ { |
|
232
|
|
|
|
|
|
|
# Images [ |
|
233
|
|
|
|
|
|
|
# [0] "file://./003855/003855r.tif", |
|
234
|
|
|
|
|
|
|
# [1] "file://./003855/003855v.tif" |
|
235
|
|
|
|
|
|
|
# ], |
|
236
|
|
|
|
|
|
|
# PDF [ |
|
237
|
|
|
|
|
|
|
# [0] "file://./003855/003855r.pdf", |
|
238
|
|
|
|
|
|
|
# [1] "file://./003855/003855v.pdf" |
|
239
|
|
|
|
|
|
|
# ] |
|
240
|
|
|
|
|
|
|
# } |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
L<Class::Utils>, |
|
246
|
|
|
|
|
|
|
L<Error::Pure>, |
|
247
|
|
|
|
|
|
|
L<METS::Parse::Simple>, |
|
248
|
|
|
|
|
|
|
L<Readonly>. |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 REPOSITORY |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/METS-Files> |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 AUTHOR |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
L<http://skim.cz> |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
© Michal Josef Špaček 2015-2020 |
|
263
|
|
|
|
|
|
|
BSD 2-Clause License |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 VERSION |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
0.01 |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |