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: Contact.pm,v 1.3 2011/12/03 11:44:52 gavin Exp $ 6package Net::EPP::Frame::Command::Update::Contact; 7use base qw(Net::EPP::Frame::Command::Update); 8use Net::EPP::Frame::ObjectSpec; 9use strict; 10 11=pod 12 13=head1 NAME 14 15Net::EPP::Frame::Command::Update::Contact - an instance of L<Net::EPP::Frame::Command::Update> 16for contact objects. 17 18=head1 SYNOPSIS 19 20 use Net::EPP::Frame::Command::Update::Contact; 21 use strict; 22 23 my $info = Net::EPP::Frame::Command::Update::Contact->new; 24 $info->setContact('REG-12345'); 25 26 print $info->toString(1); 27 28This results in an XML document like this: 29 30 <?xml version="1.0" encoding="UTF-8"?> 31 <epp xmlns="urn:ietf:params:xml:ns:epp-1.0" 32 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 33 xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 34 epp-1.0.xsd"> 35 <command> 36 <info>REG-12345 37 <contact:update 38 xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" 39 xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 40 contact-1.0.xsd"> 41 <contact:id>example-1.tldE<lt>/contact:id> 42 </contact:update> 43 </info> 44 <clTRID>0cf1b8f7e14547d26f03b7641660c641d9e79f45</clTRIDE<gt> 45 </command> 46 </epp> 47 48=head1 OBJECT HIERARCHY 49 50 L<XML::LibXML::Node> 51 +----L<XML::LibXML::Document> 52 +----L<Net::EPP::Frame> 53 +----L<Net::EPP::Frame::Command> 54 +----L<Net::EPP::Frame::Command::Update> 55 +----L<Net::EPP::Frame::Command::Update::Contact> 56 57=cut 58 59sub new { 60 my $package = shift; 61 my $self = bless($package->SUPER::new('update'), $package); 62 63 my $contact = $self->addObject(Net::EPP::Frame::ObjectSpec->spec('contact')); 64 65 foreach my $grp (qw(add rem chg)) { 66 my $el = $self->createElement(sprintf('contact:%s', $grp)); 67 $self->getNode('update')->getChildNodes->shift->appendChild($el); 68 } 69 70 return $self; 71} 72 73=pod 74 75=head1 METHODS 76 77 $frame->setContact($id); 78 79This specifies the contact object to be updated. 80 81=cut 82 83sub setContact { 84 my ($self, $id) = @_; 85 86 my $el = $self->createElement('contact:id'); 87 $el->appendText($id); 88 89 my $n = $self->getNode('update')->getChildNodes->shift; 90 $n->insertBefore( $el, $n->firstChild ); 91 92 return 1; 93} 94 95=pod 96 97 $frame->addStatus($type, $info); 98 99Add a status of $type with the optional extra $info. 100 101=cut 102 103sub addStatus { 104 my ($self, $type, $info) = @_; 105 my $status = $self->createElement('contact:status'); 106 $status->setAttribute('s', $type); 107 $status->setAttribute('lang', 'en'); 108 if ($info) { 109 $status->appendText($info); 110 } 111 $self->getElementsByLocalName('contact:add')->shift->appendChild($status); 112 return 1; 113} 114 115=pod 116 117 $frame->remStatus($type); 118 119Remove a status of $type. 120 121=cut 122 123sub remStatus { 124 my ($self, $type) = @_; 125 my $status = $self->createElement('contact:status'); 126 $status->setAttribute('s', $type); 127 $self->getElementsByLocalName('contact:rem')->shift->appendChild($status); 128 return 1; 129} 130 131sub chgPostalInfo { 132 my ($self, $type, $name, $org, $addr) = @_; 133 134 my $el = $self->createElement('contact:postalInfo'); 135 $el->setAttribute('type', $type); 136 137 my $nel = $self->createElement('contact:name'); 138 $nel->appendText($name); 139 140 my $oel = $self->createElement('contact:org'); 141 $oel->appendText($org); 142 143 my $ael = $self->createElement('contact:addr'); 144 145 if (ref($addr->{street}) eq 'ARRAY') { 146 foreach my $street (@{$addr->{street}}) { 147 my $sel = $self->createElement('contact:street'); 148 $sel->appendText($street); 149 $ael->appendChild($sel); 150 } 151 } 152 153 foreach my $name (qw(city sp pc cc)) { 154 my $vel = $self->createElement('contact:'.$name); 155 $vel->appendText($addr->{$name}); 156 $ael->appendChild($vel); 157 } 158 159 $el->appendChild($nel); 160 $el->appendChild($oel) if $org; 161 $el->appendChild($ael); 162 163 $self->getElementsByLocalName('contact:chg')->shift->appendChild($el); 164 165 return $el; 166} 167 168 169=pod 170 171 $frame->chgAuthinfo($auth); 172 173Change the authinfo. 174 175=cut 176 177sub chgAuthInfo { 178 my ($self,$authInfo) = @_; 179 180 my $el = $self->createElement('contact:authInfo'); 181 my $pw = $self->createElement('contact:pw'); 182 $pw->appendText($authInfo); 183 $el->appendChild($pw); 184 185 $self->getElementsByLocalName('contact:chg')->shift->appendChild($el); 186 return 1; 187} 188 189 190=pod 191 192=head1 AUTHOR 193 194CentralNic Ltd (http://www.centralnic.com/). 195 196=head1 COPYRIGHT 197 198This module is (c) 2016 CentralNic Ltd. This module is free software; you can 199redistribute it and/or modify it under the same terms as Perl itself. 200 201=head1 SEE ALSO 202 203=over 204 205=item * L<Net::EPP::Frame> 206 207=back 208 209=cut 210 2111; 212