line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::AlephX::Response; |
2
|
24
|
|
|
24
|
|
110626
|
use Catmandu::Sane; |
|
24
|
|
|
|
|
157325
|
|
|
24
|
|
|
|
|
124
|
|
3
|
24
|
|
|
24
|
|
3406
|
use Moo::Role; |
|
24
|
|
|
|
|
43
|
|
|
24
|
|
|
|
|
139
|
|
4
|
24
|
|
|
24
|
|
7481
|
use Catmandu::Util qw(:is :check); |
|
24
|
|
|
|
|
52
|
|
|
24
|
|
|
|
|
8461
|
|
5
|
24
|
|
|
24
|
|
10022
|
use Catmandu::AlephX::XPath::Helper qw(:all); |
|
24
|
|
|
|
|
66
|
|
|
24
|
|
|
|
|
2599
|
|
6
|
24
|
|
|
24
|
|
206
|
use Exporter qw(import); |
|
24
|
|
|
|
|
41
|
|
|
24
|
|
|
|
|
7692
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK=qw(get_children xpath); |
8
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all=>[@EXPORT_OK]); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "1.071"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Catmandu::AlephX::Response - base class for xml-responses from the AlephX-server |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
All responses from the AlephX-server share the same functionality and keys: |
19
|
|
|
|
|
|
|
- expressed in XML |
20
|
|
|
|
|
|
|
- name of the parent element is equal to the parameter 'op', except when |
21
|
|
|
|
|
|
|
the value in 'op' is not recognized. Then it is set to 'login'. |
22
|
|
|
|
|
|
|
- when an internal error occurred, the error is reported in the key 'error' |
23
|
|
|
|
|
|
|
- session-id is reported in the key 'session-id' |
24
|
|
|
|
|
|
|
- al the other subkeys are be treated as 'data' |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
All public methods from Catmandu::AlephX return an object of a subclass of Catmandu::AlepX::Response. |
27
|
|
|
|
|
|
|
In case of connection errors, or xml parsing problems, exceptions are thrown. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 methods |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 op |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
type of 'op'. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 error |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
internal error that was reported in the xml response. |
38
|
|
|
|
|
|
|
These errors only apply to values in your parameters. |
39
|
|
|
|
|
|
|
Other errors, like connection errors or problems while parsing the xml response are thrown as exceptions. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 session_id |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
session-id of the current request |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 is_success |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This method only checks if there was an internal error in the AlephX-response. |
48
|
|
|
|
|
|
|
So it simply tests if the key 'error' was undefined. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
As said before, other errors are thrown as exceptions |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
requires qw(op parse); |
55
|
|
|
|
|
|
|
has errors => ( |
56
|
|
|
|
|
|
|
is => 'rw', |
57
|
|
|
|
|
|
|
isa => sub { check_array_ref($_[0]); }, |
58
|
|
|
|
|
|
|
lazy => 1, |
59
|
|
|
|
|
|
|
default => sub { []; } |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
#deprecated, use $self->errors |
62
|
|
|
|
|
|
|
sub error { |
63
|
0
|
|
|
0
|
1
|
|
warn "method 'error' is deprecated, and only return one error. Please use method 'errors' which gives you an array reference of all errors."; |
64
|
0
|
|
|
|
|
|
$_[0]->errors()->[-1]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
has session_id => (is => 'rw'); |
67
|
|
|
|
|
|
|
sub is_success { |
68
|
0
|
|
|
0
|
1
|
|
return !scalar(@{$_[0]->errors()}); |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
has content_ref => ( |
71
|
|
|
|
|
|
|
is => 'rw' |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
sub parse_errors { |
74
|
0
|
|
|
0
|
0
|
|
my($self,$xpath)=@_; |
75
|
0
|
|
|
|
|
|
my $op = $self->op(); |
76
|
0
|
|
|
|
|
|
[map { $_->to_literal; } $xpath->find("/$op/error|/login/error|/$op/error-text-1|/$op/error-text-2")->get_nodelist()]; |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |