File Coverage

blib/lib/XML/SRS/Result.pm
Criterion Covered Total %
statement 5 7 71.4
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 8 10 80.0


line stmt bran cond sub pod time code
1              
2             # this is called 'Response' in the XML, but we call it 'Result' to not clash
3             # with 'Response', which is actually 'NZSRSResponse'
4             package XML::SRS::Result;
5             BEGIN {
6 1     1   1741 $XML::SRS::Result::VERSION = '0.09';
7             }
8              
9 1     1   6 use Carp;
  1         2  
  1         73  
10 1     1   479 use Moose;
  0            
  0            
11             use PRANG::Graph;
12             use XML::SRS::Types;
13             use Moose::Util::TypeConstraints;
14              
15             has_attr 'action' =>
16             is => "ro",
17             isa => "XML::SRS::ActionEtc",
18             required => 1,
19             xml_name => "Action",
20             ;
21              
22             has_attr 'fe_id' =>
23             is => "ro",
24             isa => "XML::SRS::Number",
25             required => 1,
26             xml_name => "FeId",
27             ;
28              
29             has_attr 'unique_id' =>
30             is => "ro",
31             isa => "XML::SRS::Number",
32             required => 1,
33             xml_name => "FeSeq",
34             ;
35              
36             # for identifying a result within a unique transaction
37             has 'part' =>
38             is => "rw",
39             isa => "Int",
40             ;
41              
42             sub result_id {
43             my $self = shift;
44             $self->fe_id.",".$self->unique_id
45             .($self->part ? ("[".$self->part."]") : "");
46             }
47              
48             has_attr 'by_id' =>
49             is => "ro",
50             isa => "XML::SRS::RegistrarId",
51             required => 1,
52             xml_name => "OrigRegistrarId",
53             ;
54              
55             has_attr 'for_id' =>
56             is => "ro",
57             isa => "XML::SRS::RegistrarId",
58             xml_required => 0,
59             xml_name => "RecipientRegistrarId",
60             ;
61              
62             has_attr 'client_id' =>
63             is => "ro",
64             isa => "XML::SRS::UID",
65             xml_required => 0,
66             xml_name => "TransId",
67             ;
68              
69             has_attr 'rows' =>
70             is => "ro",
71             isa => "XML::SRS::Number",
72             xml_required => 0,
73             xml_name => "Rows",
74             ;
75              
76             has_attr 'has_more_rows' =>
77             is => "ro",
78             isa => "XML::SRS::Boolean",
79             coerce => 1,
80             xml_required => 0,
81             xml_name => "MoreRowsAvailable",
82             ;
83              
84             has_attr 'count' =>
85             is => "ro",
86             isa => "XML::SRS::Number",
87             xml_required => 0,
88             xml_name => "Count",
89             ;
90              
91             subtype 'XML::SRS::timeStampType'
92             => as "XML::SRS::TimeStamp",
93             ;
94              
95             coerce "XML::SRS::timeStampType"
96             => from TimestampTZ
97             => via {
98             XML::SRS::TimeStamp->new(timestamptz => $_);
99             };
100              
101             has_element 'server_time' =>
102             is => "ro",
103             isa => "XML::SRS::timeStampType",
104             coerce => 1,
105             xml_nodeName => "FeTimeStamp",
106             required => 1,
107             ;
108              
109             use MooseX::Timestamp;
110             use MooseX::TimestampTZ;
111              
112              
113              
114             # this is for GetMessages responses, so let's call it messages
115             has_element 'messages' =>
116             is => "ro",
117             isa => "ArrayRef[XML::SRS::Result]",
118             xml_nodeName => "Response",
119             xml_min => 0,
120             ;
121              
122             has_element 'responses' =>
123             is => "ro",
124             isa => "ArrayRef[XML::SRS::ActionResponse]",
125             xml_required => 0,
126             lazy => 1,
127             default => sub {
128             my $self = shift;
129             ($self->has_response and defined $self->response)
130             ? [ $self->response ] : [];
131             },
132             ;
133              
134             has 'response' =>
135             is => "ro",
136             isa => "Maybe[XML::SRS::ActionResponse]",
137             predicate => "has_response",
138             lazy => 1,
139             default => sub {
140             my $self = shift;
141             my $rs_a = $self->responses;
142             if ( $rs_a and @$rs_a ) {
143             if ( @$rs_a > 1 ) {
144             confess "result has multiple responses";
145             }
146             else {
147             $rs_a->[0];
148             }
149             }
150             else {
151             undef;
152             }
153             },
154             ;
155              
156             with 'XML::SRS::Node';
157              
158             1;
159              
160             __END__
161              
162             =head1 NAME
163              
164             XML::SRS::Result - Represents the result of an individual SRS query or action
165              
166             =head1 SYNOPSIS
167              
168             my $response = XML::SRS->parse($xml);
169            
170             my $results = $response->results;
171            
172             # If the response was for a transaction involving domains, get the
173             # list of domain records returned in the response (as an array ref)
174             my $domains = $results->responses;
175              
176             =head1 DESCRIPTION
177              
178             This class represents the response to an individual transaction in an
179             SRS request. Each response may have its own list of 'responses'. For
180             example, a DomainDetailsQry might return multiple domains. These domains
181             can be obtained via the 'responses' attribute of this class (see below).
182              
183             The root XML element of this class is 'Response' XML element. However, as
184             this clashes with the top level 'Response' (i.e. 'NZSRSResponse' XML element),
185             it has been renamed 'Result'.
186              
187             =head1 ATTRIBUTES
188              
189             Each attribute of this class has an accessor/mutator of the same name as
190             the attribute. Additionally, they can be passed as parameters to the
191             constructor.
192              
193             =head2 responses
194              
195             An array ref of objects that compose the L<XML::SRS::ActionResponse> role.
196             This corresponds to the responses to the indvidual transactions of a request.
197             The objects returned here will be in a class dependent on the response type,
198             for example, a DomainDetailsQry will return 0 or more L<XML::SRS::Domain>
199             objects, while a HandleDetailsQry will return 0 or more L<XML::SRS::Handle>
200             objects. See the POD for each individual transaction for details on what type
201             of response to expect.
202              
203             =head2 response
204              
205             Returns the first response in the list, or undef if there are none. It's a
206             fairly common case to only expect one response, so this attribute is often
207             useful.
208              
209             =head2 messages
210              
211             The GetMessages transaction is somewhat different, in that it returns a list
212             of results (i.e. XML::SRS::Result objects), rather than responses. This
213             attribute contains those result objects.
214              
215             =head2 action
216              
217             The name of the 'action' this result relates to. For example 'Whois'
218             if this is the result of a 'Whois' request. Maps to the 'Action' XML
219             attribute.
220              
221             =head2 fe_id
222              
223             The front end service id of the request. Maps to the 'FeId' XML attribute.
224              
225             =head2 unique_id
226              
227             The front end sequence number of the request. Maps to the 'FeSeq' XML
228             attribute.
229              
230             =head2 by_id
231              
232             Maps to the 'OrigRegistrarId' XML attribute
233              
234             =head2 for_id
235              
236             Maps to the 'RecipientRegistrarId' XML attribute
237              
238             =head2 client_id
239              
240             Maps to the 'TransId' XML attribute
241              
242             =head2 rows
243              
244             Maps to the 'Rows' XML attribute
245              
246             =head2 has_more_rows
247              
248             Maps to the 'MoreRowsAvailable' XML attribute
249              
250             =head2 count
251              
252             Maps to the 'Count' XML attribute
253              
254             =head1 METHODS
255              
256             =head2 new(%params)
257              
258             Construct a new XML::SRS::Request object. %params specifies the initial
259             values of the attributes.
260              
261             =head1 COMPOSED OF
262              
263             L<XML::SRS::Node>