File Coverage

blib/lib/Net/DRI/Protocol/EPP/Extensions/LU/Contact.pm
Criterion Covered Total %
statement 9 72 12.5
branch 0 44 0.0
condition 0 27 0.0
subroutine 3 9 33.3
pod 0 6 0.0
total 12 158 7.5


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, .LU Contact EPP extension commands
2             ##
3             ## Copyright (c) 2007,2008,2013 Patrick Mevzek . All rights reserved.
4             ##
5             ## This file is part of Net::DRI
6             ##
7             ## Net::DRI is free software; you can redistribute it and/or modify
8             ## it under the terms of the GNU General Public License as published by
9             ## the Free Software Foundation; either version 2 of the License, or
10             ## (at your option) any later version.
11             ##
12             ## See the LICENSE file that comes with this distribution for more details.
13             ####################################################################################################
14              
15             package Net::DRI::Protocol::EPP::Extensions::LU::Contact;
16              
17 1     1   1497 use strict;
  1         1  
  1         28  
18 1     1   3 use warnings;
  1         2  
  1         21  
19              
20 1     1   4 use Net::DRI::Util;
  1         2  
  1         839  
21              
22             =pod
23              
24             =head1 NAME
25              
26             Net::DRI::Protocol::EPP::Extensions::LU::Contact - .LU EPP Contact extension commands for Net::DRI
27              
28             =head1 DESCRIPTION
29              
30             Please see the README file for details.
31              
32             =head1 SUPPORT
33              
34             For now, support questions should be sent to:
35              
36             Enetdri@dotandco.comE
37              
38             Please also see the SUPPORT file in the distribution.
39              
40             =head1 SEE ALSO
41              
42             Ehttp://www.dotandco.com/services/software/Net-DRI/E
43              
44             =head1 AUTHOR
45              
46             Patrick Mevzek, Enetdri@dotandco.comE
47              
48             =head1 COPYRIGHT
49              
50             Copyright (c) 2007,2008,2013 Patrick Mevzek .
51             All rights reserved.
52              
53             This program is free software; you can redistribute it and/or modify
54             it under the terms of the GNU General Public License as published by
55             the Free Software Foundation; either version 2 of the License, or
56             (at your option) any later version.
57              
58             See the LICENSE file that comes with this distribution for more details.
59              
60             =cut
61              
62             ####################################################################################################
63              
64             sub register_commands
65             {
66 0     0 0   my ($class,$version)=@_;
67 0           my %tmp=(
68             info => [ undef, \&info_parse ],
69             create => [ \&create, undef ],
70             update => [ \&update, undef ],
71             );
72              
73 0           return { 'contact' => \%tmp };
74             }
75              
76             sub build_command_extension
77             {
78 0     0 0   my ($mes,$epp,$tag)=@_;
79 0           return $mes->command_extension_register($tag,sprintf('xmlns:dnslu="%s" xsi:schemaLocation="%s %s"',$mes->nsattrs('dnslu')));
80             }
81              
82             ####################################################################################################
83              
84             sub info_parse
85             {
86 0     0 0   my ($po,$otype,$oaction,$oname,$rinfo)=@_;
87 0           my $mes=$po->message();
88 0 0         return unless $mes->is_success();
89              
90 0           my $infdata=$mes->get_extension('dnslu','ext');
91 0 0         return unless $infdata;
92 0           my $ns=$mes->ns('dnslu');
93 0           $infdata=$infdata->getChildrenByTagNameNS($ns,'resData');
94 0 0         return unless $infdata->size();
95 0           $infdata=$infdata->shift()->getChildrenByTagNameNS($ns,'infData');
96 0 0         return unless $infdata->size();
97 0           $infdata=$infdata->shift()->getChildrenByTagNameNS($ns,'contact');
98 0 0         return unless $infdata->size();
99 0           $infdata=$infdata->shift();
100            
101 0           my $co=$rinfo->{contact}->{$oname}->{self};
102              
103 0           my $t=$infdata->getChildrenByTagNameNS($ns,'type');
104 0 0         $co->type($t->shift->getFirstChild()->getData()) if $t->size();
105              
106 0           my $c=$infdata->getChildrenByTagNameNS($ns,'disclose');
107 0 0         if ($c->size())
108             {
109 0           $c=$c->shift()->getFirstChild();
110 0 0         $co->disclose({}) unless defined($co->disclose());
111 0           while($c)
112             {
113 0 0         next unless ($c->nodeType() == 1); ## only for element nodes
114 0   0       my $name=$c->localname() || $c->nodeName();
115 0 0         next unless $name;
116 0           $co->disclose()->{$name.'_loc'}=$c->getAttribute('flag');
117 0           } continue { $c=$c->getNextSibling(); }
118             }
119 0           return;
120             }
121              
122             sub build_disclose
123             {
124 0     0 0   my ($rd,$type)=@_;
125 0 0 0       return () unless (defined($rd) && (ref($rd) eq 'HASH') && %$rd);
      0        
126 0           my @d=();
127 0 0 0       push @d,['dnslu:name',{flag=>$rd->{name_loc}}] if (exists($rd->{name_loc}) && Net::DRI::Util::xml_is_boolean($rd->{name_loc}));
128 0 0 0       push @d,['dnslu:addr',{flag=>$rd->{addr_loc}}] if (exists($rd->{addr_loc}) && Net::DRI::Util::xml_is_boolean($rd->{addr_loc}));
129 0 0         if ($type eq 'contact')
130             {
131 0 0 0       push @d,['dnslu:org',{flag=>$rd->{org_loc}}] if (exists($rd->{org_loc}) && Net::DRI::Util::xml_is_boolean($rd->{org_loc}));
132 0 0 0       push @d,['dnslu:voice',{flag=>$rd->{voice}}] if (exists($rd->{voice}) && Net::DRI::Util::xml_is_boolean($rd->{voice}));
133 0 0 0       push @d,['dnslu:fax',{flag=>$rd->{fax}}] if (exists($rd->{fax}) && Net::DRI::Util::xml_is_boolean($rd->{fax}));
134 0 0 0       push @d,['dnslu:email',{flag=>$rd->{email}}] if (exists($rd->{email}) && Net::DRI::Util::xml_is_boolean($rd->{email}));
135             }
136 0           return \@d;
137             }
138              
139             sub create
140             {
141 0     0 0   my ($epp,$contact)=@_;
142 0           my $mes=$epp->message();
143              
144             ## validate() has been called, we are sure that type exists
145 0           my @n;
146 0           push @n,['dnslu:type',$contact->type()];
147 0           my $rd=build_disclose($contact->disclose(),$contact->type());
148 0 0         push @n,['dnslu:disclose',@$rd] if $rd;
149              
150 0           my $eid=build_command_extension($mes,$epp,'dnslu:ext');
151 0           $mes->command_extension($eid,['dnslu:create',['dnslu:contact',@n]]);
152 0           return;
153             }
154              
155             sub update
156             {
157 0     0 0   my ($epp,$domain,$todo)=@_;
158 0           my $mes=$epp->message();
159              
160 0           my @n;
161 0 0         push @n,['dnslu:add',['dnslu:disclose',@{build_disclose($todo->add('disclose'),'contact')}]] if $todo->add('disclose');
  0            
162 0 0         push @n,['dnslu:rem',['dnslu:disclose',@{build_disclose($todo->del('disclose'),'contact')}]] if $todo->del('disclose');
  0            
163 0 0         return unless @n;
164              
165 0           my $eid=build_command_extension($mes,$epp,'dnslu:ext');
166 0           $mes->command_extension($eid,['dnslu:update',['dnslu:contact',@n]]);
167 0           return;
168             }
169              
170             ####################################################################################################
171             1;