line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package SRS::EPP::Session::CmdQ; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$SRS::EPP::Session::CmdQ::VERSION = '0.22'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4501
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
8
|
1
|
|
|
1
|
|
7781
|
use MooseX::Params::Validate; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
495
|
use SRS::EPP::Command; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use SRS::EPP::Response; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'queue' => |
13
|
|
|
|
|
|
|
is => "ro", |
14
|
|
|
|
|
|
|
isa => "ArrayRef[SRS::EPP::Command]", |
15
|
|
|
|
|
|
|
default => sub { [] }, |
16
|
|
|
|
|
|
|
; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'responses' => |
19
|
|
|
|
|
|
|
is => "ro", |
20
|
|
|
|
|
|
|
isa => "ArrayRef[Maybe[SRS::EPP::Response]]", |
21
|
|
|
|
|
|
|
default => sub { [] }, |
22
|
|
|
|
|
|
|
; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'next' => |
25
|
|
|
|
|
|
|
is => "rw", |
26
|
|
|
|
|
|
|
isa => "Num", |
27
|
|
|
|
|
|
|
default => 0, |
28
|
|
|
|
|
|
|
traits => ['Number'], |
29
|
|
|
|
|
|
|
handles => { |
30
|
|
|
|
|
|
|
add_next => 'add', |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub next_command { |
35
|
|
|
|
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $q = $self->queue; |
38
|
|
|
|
|
|
|
my $next = $self->next; |
39
|
|
|
|
|
|
|
while ( $self->responses->[$next] ) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# no processing needed? skip |
42
|
|
|
|
|
|
|
$self->add_next(1); |
43
|
|
|
|
|
|
|
$next++; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
if ( my $item = $q->[$next] ) { |
46
|
|
|
|
|
|
|
$self->add_next(1); |
47
|
|
|
|
|
|
|
return $item; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
|
|
|
|
|
|
(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub commands_queued { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $q = $self->queue; |
58
|
|
|
|
|
|
|
return scalar(@$q); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub queue_command { |
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my ( $cmd ) = pos_validated_list( |
65
|
|
|
|
|
|
|
\@_, |
66
|
|
|
|
|
|
|
{ isa => 'SRS::EPP::Command' }, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
push @{ $self->queue }, $cmd; |
70
|
|
|
|
|
|
|
push @{ $self->responses }, undef; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# with a command object, place a response at the same place in the queue |
74
|
|
|
|
|
|
|
sub add_command_response { |
75
|
|
|
|
|
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my ( $response, $cmd ) = pos_validated_list( |
78
|
|
|
|
|
|
|
\@_, |
79
|
|
|
|
|
|
|
{ isa => 'SRS::EPP::Response' }, |
80
|
|
|
|
|
|
|
{ isa => 'SRS::EPP::Command', optional => 1 }, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $q = $self->queue; |
85
|
|
|
|
|
|
|
my $rs = $self->responses; |
86
|
|
|
|
|
|
|
my $ok; |
87
|
|
|
|
|
|
|
for ( my $i = 0; $i <= $#$q; $i++ ) { |
88
|
|
|
|
|
|
|
if ( |
89
|
|
|
|
|
|
|
($cmd and $q->[$i] == $cmd) |
90
|
|
|
|
|
|
|
or |
91
|
|
|
|
|
|
|
!defined $rs->[$i] |
92
|
|
|
|
|
|
|
) |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
$rs->[$i] = $response; |
95
|
|
|
|
|
|
|
$ok = 1; |
96
|
|
|
|
|
|
|
last; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
confess "Could not queue response, not found" if !$ok; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub response_ready { |
103
|
|
|
|
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
defined($self->responses->[0]); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub dequeue_response { |
109
|
|
|
|
|
|
|
my $self = shift; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if ( $self->response_ready ) { |
112
|
|
|
|
|
|
|
my $cmd = shift @{ $self->queue }; |
113
|
|
|
|
|
|
|
my $response = shift @{ $self->responses }; |
114
|
|
|
|
|
|
|
if ( $self->next ) { |
115
|
|
|
|
|
|
|
$self->add_next(-1); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
if (wantarray) { |
118
|
|
|
|
|
|
|
($response, $cmd); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
|
|
|
|
|
|
$response; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
|
|
|
|
|
|
(); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
SRS::EPP::Session::CmdQ - manage epp command/response queue |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $q = SRS::EPP::Session::CmdQ->new( ); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# put requests on queue |
142
|
|
|
|
|
|
|
$q->queue_command( $epp_command ); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# pull a command off the queue; mark it in progress |
145
|
|
|
|
|
|
|
my @rq = $q->next_command; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# put a response in |
148
|
|
|
|
|
|
|
$q->add_command_response( $epp_response, $epp_command? ); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# if a message has had all its requests answered, it can be dequeued |
151
|
|
|
|
|
|
|
($epp_response, $epp_command) = $q->dequeue_response(); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# also available in scalar context |
154
|
|
|
|
|
|
|
$epp_response = $q->dequeue_response(); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 DESCRIPTION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This class implements a simple FIFO queue, but with small |
159
|
|
|
|
|
|
|
customizations to operation to suit the use case of the SRS EPP |
160
|
|
|
|
|
|
|
Proxy's queue of EPP commands and responses. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SEE ALSO |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<SRS::EPP::Session> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR AND LICENCE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Development commissioned by NZ Registry Services, and carried out by |
169
|
|
|
|
|
|
|
Catalyst IT - L<http://www.catalyst.net.nz/> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Copyright 2009, 2010, NZ Registry Services. This module is licensed |
172
|
|
|
|
|
|
|
under the Artistic License v2.0, which permits relicensing under other |
173
|
|
|
|
|
|
|
Free Software licenses. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# Local Variables: |
179
|
|
|
|
|
|
|
# mode:cperl |
180
|
|
|
|
|
|
|
# indent-tabs-mode: t |
181
|
|
|
|
|
|
|
# cperl-continued-statement-offset: 8 |
182
|
|
|
|
|
|
|
# cperl-brace-offset: 0 |
183
|
|
|
|
|
|
|
# cperl-close-paren-offset: 0 |
184
|
|
|
|
|
|
|
# cperl-continued-brace-offset: 0 |
185
|
|
|
|
|
|
|
# cperl-continued-statement-offset: 8 |
186
|
|
|
|
|
|
|
# cperl-extra-newline-before-brace: nil |
187
|
|
|
|
|
|
|
# cperl-indent-level: 8 |
188
|
|
|
|
|
|
|
# cperl-indent-parens-as-block: t |
189
|
|
|
|
|
|
|
# cperl-indent-wrt-brace: nil |
190
|
|
|
|
|
|
|
# cperl-label-offset: -8 |
191
|
|
|
|
|
|
|
# cperl-merge-trailing-else: t |
192
|
|
|
|
|
|
|
# End: |