line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Catmandu::FedoraCommons::Response - Perl model for generic Fedora Commons REST API responses |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Catmandu::FedoraCommons; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $fedora = Catmandu::FedoraCommons->new('http://localhost:8080/fedora','fedoraAdmin','fedoraAdmin'); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $result = $fedora->findObjects(terms=>'*'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
die $resut->error unless $result->is_ok; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $obj = $result->parse_content; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$result->is_ok; |
18
|
|
|
|
|
|
|
$result->error; |
19
|
|
|
|
|
|
|
$result->raw; |
20
|
|
|
|
|
|
|
$result->content_type; |
21
|
|
|
|
|
|
|
$result->length; |
22
|
|
|
|
|
|
|
$result->date; |
23
|
|
|
|
|
|
|
$result->parse_content(); |
24
|
|
|
|
|
|
|
$result->parse_content($my_model); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
A Catmandu::FedoraCommons::Response gets returned for every Catmandu::FedoraCommons method. This response |
29
|
|
|
|
|
|
|
contains the raw HTTP content of a Fedora Commons request and can also be used to parse XML responses into |
30
|
|
|
|
|
|
|
Perl objects using the parse_content function. For more information on the Perl objects see the information |
31
|
|
|
|
|
|
|
in the Catmandu::FedoraCommons::Model packages. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
package Catmandu::FedoraCommons::Response; |
37
|
|
|
|
|
|
|
|
38
|
10
|
|
|
10
|
|
58221
|
use Catmandu::FedoraCommons::Model::findObjects; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::getObjectHistory; |
40
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::getObjectProfile; |
41
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::listDatastreams; |
42
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::listMethods; |
43
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::findObjects; |
44
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::datastreamProfile; |
45
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::pidList; |
46
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::validate; |
47
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::getRelationships; |
48
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::export; |
49
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::datastreamHistory; |
50
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::purgeDatastream; |
51
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::addRelationship; |
52
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::ingest; |
53
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::modifyObject; |
54
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::purgeObject; |
55
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::upload; |
56
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::purgeRelationship; |
57
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::getDatastreamDissemination; |
58
|
|
|
|
|
|
|
use Catmandu::FedoraCommons::Model::describeRepository; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub factory { |
61
|
|
|
|
|
|
|
my ($class, $method , $response) = @_; |
62
|
|
|
|
|
|
|
bless { method => $method , response => $response } , $class; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 is_ok() |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns true when the result Fedora Commons response contains no errors. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
sub is_ok { |
71
|
|
|
|
|
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$self->{response}->code =~ /^(200|201|202)$/; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 error() |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Returns the error message of the Fedora Commons response if available. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
sub error { |
82
|
|
|
|
|
|
|
my ($self) = @_; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$self->{response}->message; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 parse_content($model) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns a Perl representation of the Fedora Commons response. Optionally a model object can be provided that |
90
|
|
|
|
|
|
|
implements a $obj->parse($bytes) method and returns a Perl object. If no model is provided then default |
91
|
|
|
|
|
|
|
models from the Catmandu::FedoraCommons::Model namespace are used. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Example: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
package MyParser; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub new { |
98
|
|
|
|
|
|
|
my $class = shift; |
99
|
|
|
|
|
|
|
return bless {} , $class; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub parse { |
103
|
|
|
|
|
|
|
my ($self,$bytes) = @_; |
104
|
|
|
|
|
|
|
... |
105
|
|
|
|
|
|
|
return $perl |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
package main; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $fedora = Catmandu::FedoraCommons->new('http://localhost:8080/fedora','fedoraAdmin','fedoraAdmin'); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $result = $fedora->findObjects(terms=>'*'); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $perl = $result->parse_content(MyParser->new); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
sub parse_content { |
118
|
|
|
|
|
|
|
my ($self,$model) = @_; |
119
|
|
|
|
|
|
|
my $method = $self->{method}; |
120
|
|
|
|
|
|
|
my $xml = $self->raw; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
if ($method eq 'addRelationship') { |
123
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::addRelationship->parse($xml); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
elsif ($method eq 'ingest') { |
126
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::ingest->parse($xml); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
elsif ($method eq 'modifyObject') { |
129
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::modifyObject->parse($xml); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
elsif ($method eq 'purgeObject') { |
132
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::purgeObject->parse($xml); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
elsif ($method eq 'purgeRelationship') { |
135
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::purgeRelationship->parse($xml); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif ($method eq 'upload') { |
138
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::upload->parse($xml); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif ($method eq 'purgeDatastream') { |
141
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::purgeDatastream->parse($xml); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
elsif ($method eq 'getDatastreamDissemination') { |
144
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::getDatastreamDissemination->parse($xml); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
elsif ($method eq 'getDissemination') { |
147
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::getDatastreamDissemination->parse($xml); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
unless ($self->content_type =~ /(text|application)\/(xml|rdf\+xml)/) { |
151
|
|
|
|
|
|
|
Carp::carp "You probably want to use the raw() method"; |
152
|
|
|
|
|
|
|
return undef; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
if (defined $model) { |
156
|
|
|
|
|
|
|
return $model->parse($xml); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
elsif ($method eq 'findObjects') { |
159
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::findObjects->parse($xml); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
elsif ($method eq 'getObjectHistory') { |
162
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::getObjectHistory->parse($xml); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
elsif ($method eq 'getObjectProfile') { |
165
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::getObjectProfile->parse($xml); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
elsif ($method eq 'listDatastreams') { |
168
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::listDatastreams->parse($xml); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
elsif ($method eq 'listMethods') { |
171
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::listMethods->parse($xml); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
elsif ($method eq 'resumeFindObjects') { |
174
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::findObjects->parse($xml); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
elsif ($method eq 'addDatastream') { |
177
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::datastreamProfile->parse($xml); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
elsif ($method eq 'getDatastream') { |
180
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::datastreamProfile->parse($xml); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
elsif ($method eq 'getDatastreamHistory') { |
183
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::datastreamHistory->parse($xml); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
elsif ($method eq 'getNextPID') { |
186
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::pidList->parse($xml); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
elsif ($method eq 'modifyDatastream') { |
189
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::datastreamProfile->parse($xml); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
elsif ($method eq 'setDatastreamState') { |
192
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::datastreamProfile->parse($xml); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
elsif ($method eq 'setDatastreamVersionable') { |
195
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::datastreamProfile->parse($xml); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
elsif ($method eq 'validate') { |
198
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::validate->parse($xml); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
elsif ($method eq 'getRelationships') { |
201
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::getRelationships->parse($xml); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
elsif ($method eq 'export') { |
204
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::export->parse($xml); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
elsif ($method eq 'getObjectXML') { |
207
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::export->parse($xml); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
elsif ($method eq 'describeRepository') { |
210
|
|
|
|
|
|
|
return Catmandu::FedoraCommons::Model::describeRepository->parse($xml); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
else { |
213
|
|
|
|
|
|
|
Carp::croak "no model found for $method"; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 raw() |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Returns the raw Fedora Commons response as a string. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
sub raw { |
223
|
|
|
|
|
|
|
my ($self) = @_; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$self->{response}->content; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 content_type() |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Returns the Content-Type of the Fedora Commons response. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |
233
|
|
|
|
|
|
|
sub content_type { |
234
|
|
|
|
|
|
|
my ($self) = @_; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
$self->{response}->header('Content-Type'); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 length() |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Returns the byte length of the Fedora Commons response. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
244
|
|
|
|
|
|
|
sub length { |
245
|
|
|
|
|
|
|
my ($self) = @_; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
$self->{response}->header('Content-Length'); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 date() |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Returns the date of the Fedora Commons response. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=cut |
255
|
|
|
|
|
|
|
sub date { |
256
|
|
|
|
|
|
|
my ($self) = @_; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$self->{response}->header('Date'); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 AUTHORS |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=over 4 |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item * Patrick Hochstenbach, C<< <patrick.hochstenbach at ugent.be> >> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=back |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 SEE ALSO |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
L<Catmandu::Model::findObjects>, |
272
|
|
|
|
|
|
|
L<Catmandu::Model::getObjectHistory>, |
273
|
|
|
|
|
|
|
L<Catmandu::Model::getObjectPrifule>, |
274
|
|
|
|
|
|
|
L<Catmandu::Model::listDatastreams>, |
275
|
|
|
|
|
|
|
L<Catmandu::Model::listMethods> |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=cut |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
1; |