DRI/Protocol/EPP/Extensions/UnitedTLD/Charge.pm

filter: Statementstmt 16.9% 19 / 112 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 30.0% 6 / 20 Podpod 0.0% 0 / 12 totaltotal 11.4% 25 / 219 CC 42 SCAR 49.5
CC
42
Cov
10%
add_set
380.0
_parse_set
72.0
check_parse
72.0
CRAP 141.5
« DRI/Protocol/EPP/Extensions/CZ/NSSET.pm ↑ Summary DRI/Registry.pm »
1 ## Domain Registry Interface, Charge Extension Mapping for EPP
2 ##
3 ## Copyright (c) 2015,2018 Patrick Mevzek <netdri@dotandco.com>. 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::UnitedTLD::Charge;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Net::DRI::Protocol::EPP::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 ####################################################################################################
26  
27 sub register_commands
28 {
29 0 ▶ my ($class,$version)=@_;
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
30  
31 0 state $rops = { 'domain' => { check => [ undef, \&check_parse ],
32 check_multi => [ undef, \&check_parse ],
33 create => [ \&add_agreement, \&create_parse ],
34 info => [ undef, \&info_parse ],
35 renew => [ \&add_agreement, \&renew_parse ],
36 transfer_request => [ \&add_agreement, \&transfer_parse ],
37 update => [ \&update_build, \&update_parse ],
38 }
39 };
40  
41 0 return $rops;
42 }
43  
44 sub setup
45 {
46 0 ▶ my ($class,$po,$version)=@_;
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
47 0 state $ns = { 'charge' => 'http://www.unitedtld.com/epp/charge-1.0' };
48 0 $po->ns($ns);
49 0 return;
50 }
51  
52 0 ▶sub implements { return 'http://rightside.co/fileadmin/downloads/policies/Rightside_Price_Categories.pdf'; }
Subroutine implements: not called CC=1 SCAR=6.9
Pod undocumented
53  
54 ####################################################################################################
55  
56 sub _parse_set
57 {
58 0 ▶ my ($node)=@_;
Subroutine _parse_set: not called CC=8 SCAR=42.8
59  
60 0 my %s;
61 0 foreach my $el (Net::DRI::Util::xml_list_children($node))
62 {
63 0 my ($name,$node)=@$el;
64 0 ▶ if ($name eq 'category')
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'category') { } 0 0 0
elsif ($name eq 'type') { } 0 0 0
elsif ($name eq 'amount') { } 0 0 0
65 {
66 0 my $v=$node->textContent();
67 0 ▶ $s{category}=$node->hasAttribute('name') ? { name => $node->getAttribute('name'), value => $v } : $v;
Branch: 1 branch
BranchTrueFalseTotal
$node->hasAttribute('name') ? : 0 0 0
68 } elsif ($name eq 'type')
69 {
70 0 my $v=$node->textContent();
71 0 ▶ $s{type}=$node->hasAttribute('name') ? { name => $node->getAttribute('name'), value => $v } : $v;
Branch: 1 branch
BranchTrueFalseTotal
$node->hasAttribute('name') ? : 0 0 0
72 } elsif ($name eq 'amount')
73 {
74 0 my $key=$node->getAttribute('command');
75 0 ▶ $key.='.'.$node->getAttribute('name') if $node->hasAttribute('name');
Branch: 1 branch
BranchTrueFalseTotal
if $node->hasAttribute("name") 0 0 0
76 0 $s{$key}=0+$node->textContent();
77 }
78 }
79 0 return \%s;
80 }
81  
82 sub check_parse
83 {
84 0 ▶ my ($po,$otype,$oaction,$oname,$rinfo)=@_;
Subroutine check_parse: not called CC=8 SCAR=42.8
Pod undocumented
85 0 my $mes=$po->message();
86 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
87  
88 0 my $data=$mes->get_extension('charge','chkData');
89 0 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
90  
91 0 foreach my $cd (grep { $_->[0] eq 'cd' } Net::DRI::Util::xml_list_children($data))
92 {
93 0 my ($domain,@p);
94 0 foreach my $el (Net::DRI::Util::xml_list_children($cd->[1]))
95 {
96 0 my ($name,$node)=@$el;
97 0 ▶ if ($name eq 'name')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'name') { } 0 0 0
elsif ($name eq 'set') { } 0 0 0
98 {
99 0 $domain=$node->textContent();
100 } elsif ($name eq 'set')
101 {
102 0 push @p,_parse_set($node);
103 }
104 }
105 0 ▶ $rinfo->{$otype}->{$domain}->{price}=@p > 1 ? \@p : $p[0];
Branch: 1 branch
BranchTrueFalseTotal
@p > 1 ? : 0 0 0
106 }
107  
108 0 return;
109 }
110  
111 sub add_agreement
112 {
113 0 ▶ my ($epp,$domain,$rp)=@_;
Subroutine add_agreement: not called CC=4 SCAR=30.0
Pod undocumented
114 0 my $mes=$epp->message();
115  
116 0 ▶ return unless Net::DRI::Util::has_key($rp,'price');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "price") 0 0 0
117  
118 0 my @d;
119 0 ▶ foreach my $charge (ref $rp->{price} eq 'ARRAY' ? @{$rp->{price}} : ($rp->{price}))
Branch: 1 branch
BranchTrueFalseTotal
ref $rp->{'price'} eq 'ARRAY' ? : 0 0 0
120 {
121 0 push @d,['charge:set',add_set($charge)];
122 }
123  
124 0 my $eid=$mes->command_extension_register('charge','agreement');
125 0 $mes->command_extension($eid,\@d);
126 0 return;
127 }
128  
129 sub add_set
130 {
131 0 ▶ my ($charge)=@_;
Subroutine add_set: not called CC=19 SCAR=59.4
Pod undocumented
132 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('price element must be ref hash') unless ref $charge eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $charge eq "HASH" 0 0 0
133  
134 0 my @d;
135  
136 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('missing category element in price structure') unless Net::DRI::Util::has_key($charge,'category');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($charge, "category") 0 0 0
137 0 ▶ if (ref $charge->{category} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $charge->{'category'} eq 'HASH') { } 0 0 0
138 {
139 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('category missing value') unless Net::DRI::Util::has_key($charge->{category},'value');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($charge->{"category"}, "value") 0 0 0
140 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('category value must be an XML token') unless Net::DRI::Util::xml_is_token($charge->{category}->{value});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($charge->{"category"}{"value"}) 0 0 0
141 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('category missing name') unless Net::DRI::Util::has_key($charge->{category},'name');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($charge->{"category"}, "name") 0 0 0
142 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('category name must be an XML token') unless Net::DRI::Util::xml_is_token($charge->{category}->{name});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($charge->{"category"}{"name"}) 0 0 0
143 0 push @d,['charge:category',{ name => $charge->{category}->{name} },$charge->{category}->{value}];
144 } else
145 {
146 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('category must be an XML token') unless Net::DRI::Util::xml_is_token($charge->{category});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($charge->{"category"}) 0 0 0
147 0 push @d,['charge:category',$charge->{category}];
148 }
149  
150 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('missing type element in price structure') unless Net::DRI::Util::has_key($charge,'type');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($charge, "type") 0 0 0
151 0 ▶ if ($charge->{type} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if ($charge->{'type'} eq 'HASH') { } 0 0 0
152 {
153 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('type missing value') unless Net::DRI::Util::has_key($charge->{type},'value');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($charge->{"type"}, "value") 0 0 0
154 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('type value must be an XML token') unless Net::DRI::Util::xml_is_token($charge->{type}->{value});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($charge->{"type"}{"value"}) 0 0 0
155 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('type missing name') unless Net::DRI::Util::has_key($charge->{type},'name');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($charge->{"type"}, "name") 0 0 0
156 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('type name must be an XML token') unless Net::DRI::Util::xml_is_token($charge->{type}->{name});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($charge->{"type"}{"name"}) 0 0 0
157 0 push @d,['charge:type',{ name => $charge->{type}->{name} },$charge->{type}->{value}];
158 } else
159 {
160 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('type value must be "price", "fee" or "custom"') unless $charge->{type}=~m/^(?:price|fee|custom)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $charge->{"type"} =~ /^(?:price|fee|custom)$/ 0 0 0
161 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('type name must be set if type value is "custom"') if $charge->{type} eq 'custom';
Branch: 1 branch
BranchTrueFalseTotal
if $charge->{"type"} eq "custom" 0 0 0
162 0 push @d,['charge:type',$charge->{type}];
163 }
164  
165 0 foreach my $key (sort { $a cmp $b } grep { ! /^(?:category|type)$/ } keys %$charge)
166 {
167 0 my ($command,$name)=split(/\./,$key);
168 0 ▶ push @d,['charge:amount',{ command => $command, defined $name ? (name => $name) : ()},0+$charge->{$key}];
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 0 0 0
169 }
170  
171 0 return @d;
172 }
173  
174 sub _parse
175 {
176 0 ▶ my ($po,$otype,$oaction,$oname,$rinfo,$topname)=@_;
Subroutine _parse: not called CC=4 SCAR=30.0
177 0 my $mes=$po->message();
178 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
179  
180 0 my $data=$mes->get_extension('charge',$topname);
181 0 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
182  
183 0 my @p=map { _parse_set($_) } Net::DRI::Util::xml_list_children($data,'set');
184 0 ▶ $rinfo->{$otype}->{$oname}->{price}=@p > 1 ? \@p : $p[0];
Branch: 1 branch
BranchTrueFalseTotal
@p > 1 ? : 0 0 0
185 0 return;
186 }
187  
188 0 ▶sub create_parse { return _parse(@_,'creData'); } ## no critic (Subroutines::RequireArgUnpacking)
Subroutine create_parse: not called CC=1 SCAR=6.9
Pod undocumented
189 0 ▶sub info_parse { return _parse(@_,'infData'); } ## no critic (Subroutines::RequireArgUnpacking)
Subroutine info_parse: not called CC=1 SCAR=6.9
Pod undocumented
190 0 ▶sub renew_parse { return _parse(@_,'renData'); } ## no critic (Subroutines::RequireArgUnpacking)
Subroutine renew_parse: not called CC=1 SCAR=6.9
Pod undocumented
191 0 ▶sub transfer_parse { return _parse(@_,'trnData'); } ## no critic (Subroutines::RequireArgUnpacking)
Subroutine transfer_parse: not called CC=1 SCAR=6.9
Pod undocumented
192 0 ▶sub update_parse { return _parse(@_,'upData'); } ## no critic (Subroutines::RequireArgUnpacking)
Subroutine update_parse: not called CC=1 SCAR=6.9
Pod undocumented
193  
194 sub update_build
195 {
196 0 ▶ my ($epp,$domain,$todo,$rp)=@_;
Subroutine update_build: not called CC=4 SCAR=30.0
Pod undocumented
197  
198 0 my $rgp=$todo->set('rgp');
199 0 ▶ return unless Net::DRI::Util::has_key($rgp,'op') && $rgp->{op} eq 'request';
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rgp, "op") and $rgp->{"op"} eq "request" 0 0 0
Condition0%0/3
Net::DRI::Util::has_key($rgp, "op") and $rgp->{"op"} eq "request"
!ll&&!rl&&r
000
MC/DC0%0/2
Net::DRI::Util::has_key($rgp, "op") and $rgp->{"op"} eq "request"
Net::DRI::Util::has_key($rgp, "op") $rgp->{"op"} eq "request"
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($rgp, "op")B= $rgp->{"op"} eq "request"
ABresult
0X0
100
111
200 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('price structure is mandatory for a domain:update RGP request') unless Net::DRI::Util::has_key($rp,'price');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "price") 0 0 0
201 0 return add_agreement($epp,$domain,$rp);
202 }
203  
204  
205 ####################################################################################################
206 1 1;
207  
208 __END__
209  
210 =pod
211  
212 =head1 NAME
213  
214 Net::DRI::Protocol::EPP::Extensions::UnitedTLD::Charge - EPP Charge Extension mapping (http://rightside.co/fileadmin/downloads/policies/Rightside_Price_Categories.pdf) for Net::DRI
215  
216 =head1 DESCRIPTION
217  
218 Please see the README file for details.
219  
220 =head1 SUPPORT
221  
222 For now, support questions should be sent to:
223  
224 E<lt>netdri@dotandco.comE<gt>
225  
226 Please also see the SUPPORT file in the distribution.
227  
228 =head1 SEE ALSO
229  
230 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
231  
232 =head1 AUTHOR
233  
234 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
235  
236 =head1 COPYRIGHT
237  
238 Copyright (c) 2015,2018 Patrick Mevzek <netdri@dotandco.com>.
239 All rights reserved.
240  
241 This program is free software; you can redistribute it and/or modify
242 it under the terms of the GNU General Public License as published by
243 the Free Software Foundation; either version 2 of the License, or
244 (at your option) any later version.
245  
246 See the LICENSE file that comes with this distribution for more details.
247  
248 =cut
« DRI/Protocol/EPP/Extensions/CZ/NSSET.pm ↑ Summary DRI/Registry.pm »