File Coverage

blib/lib/Net/EPP/Frame/Command.pm
Criterion Covered Total %
statement 36 65 55.3
branch 0 4 0.0
condition n/a
subroutine 12 22 54.5
pod 2 8 25.0
total 50 99 50.5


line stmt bran cond sub pod time code
1             # Copyright (c) 2016 CentralNic Ltd. All rights reserved. This program is
2             # free software; you can redistribute it and/or modify it under the same
3             # terms as Perl itself.
4             #
5             # $Id: Command.pm,v 1.4 2011/12/03 11:44:51 gavin Exp $
6             package Net::EPP::Frame::Command;
7 1     1   696 use Net::EPP::Frame::Command::Check;
  1         3  
  1         39  
8 1     1   664 use Net::EPP::Frame::Command::Create;
  1         5  
  1         44  
9 1     1   666 use Net::EPP::Frame::Command::Delete;
  1         4  
  1         46  
10 1     1   591 use Net::EPP::Frame::Command::Info;
  1         4  
  1         55  
11 1     1   632 use Net::EPP::Frame::Command::Login;
  1         3  
  1         69  
12 1     1   651 use Net::EPP::Frame::Command::Logout;
  1         23  
  1         65  
13 1     1   601 use Net::EPP::Frame::Command::Poll;
  1         4  
  1         81  
14 1     1   618 use Net::EPP::Frame::Command::Renew;
  1         4  
  1         68  
15 1     1   589 use Net::EPP::Frame::Command::Transfer;
  1         4  
  1         97  
16 1     1   603 use Net::EPP::Frame::Command::Update;
  1         6  
  1         95  
17 1     1   8 use base qw(Net::EPP::Frame);
  1         3  
  1         383  
18 1     1   9 use strict;
  1         3  
  1         866  
19              
20             =pod
21              
22             =head1 NAME
23              
24             Net::EPP::Frame::Command - an instance of L for client commands
25              
26             =head1 DESCRIPTION
27              
28             This module is a base class for the Net::EPP::Frame::* subclasses, you should
29             never need to access it directly.
30              
31             =head1 OBJECT HIERARCHY
32              
33             L
34             +----L
35             +----L
36             +----L
37              
38             =cut
39              
40             sub new {
41 0     0 1   my $package = shift;
42 0           my $self = $package->SUPER::new('command');
43 0           return bless($self, $package);
44             }
45              
46             sub addObject() {
47 0     0 0   my ($self, $object, $ns, $schema) = @_;
48              
49 0           my $obj = $self->createElement($self->getCommandType);
50 0           $obj->setNamespace($ns, $object);
51 0           $self->getNode($self->getCommandType)->addChild($obj);
52              
53 0           return $obj;
54             }
55              
56             sub _addExtraElements {
57 0     0     my $self = shift;
58              
59 0 0         $self->command->addChild($self->createElement($self->getCommandType)) if ($self->getCommandType ne '');
60 0           $self->command->addChild($self->createElement('clTRID'));
61              
62 0           $self->_addCommandElements;
63 0           return 1;
64             }
65              
66       0     sub _addCommandElements {
67             }
68              
69             =pod
70              
71             =head1 METHODS
72              
73             my $object = $frame->addObject(@spec);
74              
75             This method creates and returns a new element corresponding to the data in
76             C<@spec>, and appends it to the "command" element (as returned by the
77             C method below).
78              
79             The L module can be used to quickly retrieve EPP
80             object specifications.
81              
82             my $type = $frame->getCommandType;
83              
84             This method returns a scalar containing the command type (eg L<'create'>).
85              
86             my $type = $frame->getCommandNode;
87              
88             This method returns the L object corresponding to the
89             command in question, eg the CcreateE> element (for a
90             L object). It is within this element that
91             EPP objects are placed.
92              
93             my $node = $frame->command;
94              
95             This method returns the L object corresponding to the
96             CcommandE> element.
97              
98             my $node = $frame->clTRID;
99              
100             This method returns the L object corresponding to the
101             CclTRIDE> element.
102              
103             =cut
104              
105             sub getCommandType {
106 0     0 0   my $self = shift;
107 0           my $type = ref($self);
108 0           my $me = __PACKAGE__;
109 0           $type =~ s/^$me\:+//;
110 0           $type =~ s/\:{2}.+//;
111 0           return lc($type);
112             }
113              
114             sub getCommandNode {
115 0     0 0   my $self = shift;
116 0           return $self->getNode($self->getCommandType);
117             }
118              
119 0     0 1   sub command { $_[0]->getNode('command') }
120 0     0 0   sub clTRID { $_[0]->getNode('clTRID') }
121              
122             =pod
123              
124             my $extension = $frame->extension;
125              
126             This method returns the L object corresponding to the
127             CextensionE> element. If one does not exist, it will be created and
128             inserted at the correct position.
129              
130             =cut
131              
132             sub extension {
133 0     0 0   my $self = shift;
134              
135 0           my $extension = $self->getNode('extension');
136              
137 0 0         $extension = $self->getCommandNode->parentNode->insertAfter($self->createElement('extension'), $self->getCommandNode) if (!$extension);
138              
139 0           return $extension;
140             }
141              
142             =pod
143              
144             my $element = $frame->createExtensionElementFor($xmlns);
145              
146             This methods creates a new element in the CextensionE> element for the
147             EPP extension specified by C<$xmlns> which can be obtained from
148             L. The element's tag name will correspond to the
149             command name (C, C etc).
150              
151             Example usage:
152              
153             my $frame = Net::EPP::Frame::Command::Info::Domain->new;
154              
155             my $element = $frame->createExtensionElementFor(
156             Net::EPP::Frame::ObjectSpec->xmlns('foobar')
157             );
158              
159             // prints
160             print $element->toString();
161              
162             =cut
163              
164             sub createExtensionElementFor {
165 0     0 0   my ($self, $xmlns) = @_;
166              
167 0           return $self->extension->appendChild($self->createElementNS($xmlns, $self->getCommandType));
168             }
169              
170             1;