line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::MechanicalTurk::Response; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
97
|
use strict; |
|
18
|
|
|
|
|
37
|
|
|
18
|
|
|
|
|
670
|
|
4
|
18
|
|
|
18
|
|
86
|
use warnings; |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
535
|
|
5
|
18
|
|
|
18
|
|
92
|
use Net::Amazon::MechanicalTurk::BaseObject; |
|
18
|
|
|
|
|
31
|
|
|
18
|
|
|
|
|
378
|
|
6
|
18
|
|
|
18
|
|
10427
|
use Net::Amazon::MechanicalTurk::XMLParser; |
|
18
|
|
|
|
|
48
|
|
|
18
|
|
|
|
|
16672
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw{ Net::Amazon::MechanicalTurk::BaseObject }; |
11
|
|
|
|
|
|
|
our %CLIENT_ERRORS = ( |
12
|
|
|
|
|
|
|
"TransportError" => "There was an error communicating with MechanicalTurk.", |
13
|
|
|
|
|
|
|
"ResponseFormatError" => "Could not find response in XML received from MechanicalTurk.", |
14
|
|
|
|
|
|
|
"MalformedXML" => "Invald XML received from MechanicalTurk.", |
15
|
|
|
|
|
|
|
"UnknownError" => "An unknown error was received from MechanicalTurk." |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Net::Amazon::MechanicalTurk::Response->attributes(qw{ |
19
|
|
|
|
|
|
|
errorMessage |
20
|
|
|
|
|
|
|
errorCode |
21
|
|
|
|
|
|
|
fullResult |
22
|
|
|
|
|
|
|
result |
23
|
|
|
|
|
|
|
type |
24
|
|
|
|
|
|
|
}); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init { |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
$self->setAttributes(@_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub xml { |
32
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
my $attrName = "Net::Amazon::MechanicalTurk::Response::xml"; |
34
|
0
|
0
|
|
|
|
|
if ($#_ >= 0) { |
35
|
0
|
|
|
|
|
|
my $xml = shift; |
36
|
0
|
|
|
|
|
|
$self->{$attrName} = $xml; |
37
|
0
|
|
|
|
|
|
$self->parseResult(); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
return $self->{$attrName}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub clientError { |
43
|
0
|
|
|
0
|
0
|
|
my ($self, $type, $message) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if (!exists $CLIENT_ERRORS{$type}) { |
46
|
0
|
|
|
|
|
|
die "Unknown error type $type."; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if (defined($message)) { |
50
|
0
|
|
|
|
|
|
$message = $CLIENT_ERRORS{$type} . " " . $message; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
0
|
|
|
|
|
|
$message = $CLIENT_ERRORS{$type}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->errorCode("Client.${type}"); |
57
|
0
|
|
|
|
|
|
$self->errorMessage($message); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (!$self->type) { |
60
|
0
|
|
|
|
|
|
$self->type('ClientError'); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub parseResult { |
67
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->debugMessage("Parsing XML response."); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->fullResult(undef); |
72
|
0
|
|
|
|
|
|
$self->result(undef); |
73
|
0
|
|
|
|
|
|
$self->errorCode(undef); |
74
|
0
|
|
|
|
|
|
$self->errorMessage(undef); |
75
|
0
|
|
|
|
|
|
$self->type(undef); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Parse the XML |
78
|
0
|
|
|
|
|
|
my ($fullResult, $rootElement); |
79
|
0
|
|
|
|
|
|
eval { |
80
|
0
|
|
|
|
|
|
($fullResult, $rootElement) = Net::Amazon::MechanicalTurk::XMLParser->new->parse($self->xml); |
81
|
0
|
|
|
|
|
|
$self->debugMessage("Parsed XML."); |
82
|
|
|
|
|
|
|
}; |
83
|
0
|
0
|
|
|
|
|
if ($@) { |
84
|
0
|
|
|
|
|
|
$self->debugMessage("Error: $@"); |
85
|
0
|
|
|
|
|
|
$self->clientError('MalformedXML'); |
86
|
0
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->type($rootElement); |
90
|
0
|
|
|
|
|
|
$self->fullResult($fullResult); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $error; |
93
|
|
|
|
|
|
|
$self->fullResult->visit(sub { |
94
|
0
|
|
|
0
|
|
|
my ($key, $value, $nodes) = @_; |
95
|
0
|
0
|
0
|
|
|
|
if (!defined($error) and defined($key) and $key eq "Error") { |
|
|
|
0
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$error = $value->get(1); |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
}); |
99
|
0
|
0
|
|
|
|
|
if (defined($error)) { |
100
|
0
|
|
|
|
|
|
$self->errorCode($error->getFirst("Code")); |
101
|
0
|
|
|
|
|
|
$self->errorMessage($error->getFirst("Message")); |
102
|
0
|
0
|
|
|
|
|
if (!$self->errorCode) { |
|
|
0
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->clientError('UnknownError'); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif (!$self->errorMessage) { |
106
|
0
|
|
|
|
|
|
$self->errorMessage(); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
0
|
|
|
|
|
|
my $result; |
111
|
0
|
|
|
|
|
|
while (my ($key,$value) = each %{$self->fullResult}) { |
|
0
|
|
|
|
|
|
|
112
|
0
|
0
|
0
|
|
|
|
if (!defined($result) and $key ne "OperationRequest") { |
113
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($value, "ARRAY")) { |
114
|
0
|
0
|
|
|
|
|
if ($#{$value} == 0) { |
|
0
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$result = $value->[0]; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
0
|
|
|
|
|
|
$result = $value; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if (!defined($result)) { |
125
|
0
|
|
|
|
|
|
$self->clientError("ResponseFormatError"); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->result($result); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub toString { |
133
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
134
|
0
|
|
|
|
|
|
my $str = sprintf "<<%s>>", ref($self); |
135
|
0
|
|
|
|
|
|
$str .= "\n Type: " . $self->type; |
136
|
0
|
0
|
|
|
|
|
if ($self->errorCode) { |
137
|
0
|
|
|
|
|
|
$str .= "\n Error Code: " . $self->errorCode; |
138
|
0
|
|
|
|
|
|
$str .= "\n Error Message: " . $self->errorMessage; |
139
|
|
|
|
|
|
|
} |
140
|
0
|
0
|
|
|
|
|
if (defined($self->fullResult)) { |
141
|
0
|
|
|
|
|
|
$str .= "\n Result: \n"; |
142
|
0
|
|
|
|
|
|
foreach my $line (split /\n/, $self->fullResult->toString) { |
143
|
0
|
|
|
|
|
|
$str .= " $line\n"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
0
|
|
|
|
|
|
return $str; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
return 1; |