File Coverage

blib/lib/SRS/EPP/Command.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             # vim: filetype=perl:noexpandtab:ts=3:sw=3
2             #
3             # Copyright (C) 2009 NZ Registry Services
4             #
5             # This program is free software: you can redistribute it and/or modify
6             # it under the terms of the Artistic License 2.0 or later. You should
7             # have received a copy of the Artistic License the file COPYING.txt.
8             # If not, see <http://www.perlfoundation.org/artistic_license_2_0>
9              
10             package SRS::EPP::Command;
11              
12 3     3   34847 use Moose;
  0            
  0            
13             use MooseX::Method::Signatures;
14             use Moose::Util::TypeConstraints;
15              
16             extends 'SRS::EPP::Message';
17              
18             use XML::EPP;
19             has "+message" =>
20             isa => "XML::EPP",
21             ;
22              
23             use Module::Pluggable search_path => [__PACKAGE__];
24              
25             sub rebless_class {
26             my $object = shift;
27             our $map;
28             if ( !$map ) {
29             $map = {
30             map {
31             $_->can("match_class") ?
32             ( $_->match_class => $_ )
33             : ();
34             }# map { print "rebless_class checking plugin $_\n"; $_ }
35             grep m{${\(__PACKAGE__)}::[^:]*$},
36             __PACKAGE__->plugins,
37             };
38             }
39             $map->{ref $object};
40             }
41              
42             sub action_class {
43             my $action = shift;
44             our $action_classes;
45             if ( !$action_classes ) {
46             $action_classes = {
47             map {
48             $_->can("action") ?
49             ($_->action => $_)
50             : ();
51             }# map { print "action_class checking plugin $_\n"; $_ }
52             grep m{^${\(__PACKAGE__)}::[^:]*$},
53             __PACKAGE__->plugins,
54             };
55             }
56             $action_classes->{ $action };
57             }
58              
59             sub REBLESS {
60              
61             }
62              
63             sub BUILD {
64             my $self = shift;
65             if ( my $epp = $self->message ) {
66             my $class;
67             $class = rebless_class( $epp->message );
68             if ( !$class and $epp->message and
69             $epp->message->can("action") ) {
70             $class = action_class($epp->message->action);
71             }
72             if ( $class ) {
73             #FIXME: use ->meta->rebless_instance
74             bless $self, $class;
75             $self->REBLESS;
76             }
77             }
78             }
79              
80             method simple() { 0 }
81             method authenticated() { 1 }
82             method done() { 1 }
83              
84             BEGIN {
85             class_type "SRS::EPP::Session";
86             class_type "SRS::EPP::SRSResponse";
87             }
88              
89             has 'session' =>
90             is => "rw",
91             isa => "SRS::EPP::Session",
92             weak_ref => 1,
93             ;
94              
95             has 'server_id' =>
96             is => "rw",
97             isa => "XML::EPP::trIDStringType",
98             lazy => 1,
99             default => sub {
100             my $self = shift;
101             $self->session->new_server_id;
102             }
103             ;
104              
105             BEGIN {
106             class_type "SRS::EPP::Session";
107             }
108              
109             # process a simple message - the $session is for posting back events
110             method process( SRS::EPP::Session $session ) {
111             $self->session($session);
112              
113             # default handler is to return an unimplemented message
114             return $self->make_response(code => 2101);
115             }
116              
117             method notify( SRS::EPP::SRSResponse @rs ) {
118             my $result;
119             if ( my $server_id = eval {
120             $result = $rs[0]->message;
121             $result->fe_id.",".$result->unique_id
122             } ) {
123             $self->server_id($server_id);
124             }
125             }
126              
127             sub make_response {
128             my $self = shift;
129             my $type = "SRS::EPP::Response";
130             if ( @_ % 2 ) {
131             $type = shift;
132             $type = "SRS::EPP::Response::$type" if $type !~ /^SRS::/;
133             }
134             my %fields = @_;
135             $fields{client_id} ||= $self->client_id if $self->has_client_id;
136             $fields{server_id} ||= $self->server_id;
137             $type->new(
138             %fields,
139             );
140             }
141              
142             has "client_id" =>
143             is => "rw",
144             isa => "XML::EPP::trIDStringType",
145             predicate => "has_client_id",
146             ;
147              
148             after 'message_trigger' => sub {
149             my $self = shift;
150             my $message = $self->message;
151             if ( my $client_id = eval { $message->message->client_id } ) {
152             $self->client_id($client_id);
153             }
154             };
155              
156             use Module::Pluggable
157             require => 1,
158             search_path => [__PACKAGE__],
159             ;
160              
161             __PACKAGE__->plugins;
162              
163             no Moose;
164             __PACKAGE__->meta->make_immutable;
165              
166             1;
167              
168             __END__
169              
170             =head1 NAME
171              
172             SRS::EPP::Command - encapsulation of received EPP commands
173              
174             =head1 SYNOPSIS
175              
176             my $cmd = SRS::EPP::Command::SubClass->new
177             (
178             xmlschema => ...
179             xmlstring => ...
180             );
181              
182             my $response = $cmd->process;
183              
184             =head1 DESCRIPTION
185              
186             This module is a base class for EPP commands; these are messages sent
187             from the client to the server.
188              
189             =head1 ATTRIBUTES
190              
191             =over
192              
193             =item xmlschema
194              
195             The XML schema for this message, as a string. (XXX - this should be a
196             class data variable)
197              
198             =item xmlstring
199              
200             The data of the message.
201              
202             =back
203              
204             =head1 SEE ALSO
205              
206             L<SRS::EPP::Command::Login>, L<SRS::EPP::Message>,
207             L<SRS::EPP::Response>
208              
209             =cut
210              
211             # Local Variables:
212             # mode:cperl
213             # indent-tabs-mode: t
214             # tab-width: 8
215             # cperl-continued-statement-offset: 8
216             # cperl-brace-offset: 0
217             # cperl-close-paren-offset: 0
218             # cperl-continued-brace-offset: 0
219             # cperl-continued-statement-offset: 8
220             # cperl-extra-newline-before-brace: nil
221             # cperl-indent-level: 8
222             # cperl-indent-parens-as-block: t
223             # cperl-indent-wrt-brace: nil
224             # cperl-label-offset: -8
225             # cperl-merge-trailing-else: t
226             # End: