DRI/Protocol/EPP/Extensions/VeriSign/Suggestion.pm

filter: Statementstmt 9.7% 13 / 133 Branchbran 0.0% 0 / 86 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 6 totaltotal 6.4% 17 / 265 CC 59 SCAR 70.4
CC
59
Cov
5%
suggestion
1806.0
parse
110.0
parse_grid
42.0
CRAP 1136.6
« DRI/Data/Contact/DENIC.pm ↑ Summary DRI/Protocol/EPP/Extensions/PL/Message.pm »
1 ## Domain Registry Interface, VeriSign EPP Suggestion Extension
2 ##
3 ## Copyright (c) 2010,2012,2013,2016,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::VeriSign::Suggestion;
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  
20 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 ####################################################################################################
24  
25 sub register_commands
26 0 ▶{
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my ($class,$version)=@_;
28  
29 0 return { 'domain' => { 'suggestion' => [ \&suggestion, \&parse ],
30 } };
31 }
32  
33 sub setup
34 0 ▶{
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($class,$po,$version)=@_;
36 0 $po->ns({ 'suggestion' => 'http://www.verisign-grs.com/epp/suggestion-1.1' });
37 0 return;
38 }
39  
40 ####################################################################################################
41  
42 sub suggestion
43 0 ▶{
Subroutine suggestion: not called CC=42 SCAR=75.0
Pod undocumented
44 0 my ($epp,$domain,$rd)=@_;
45  
46 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('suggestion domain/key must be a string') unless Net::DRI::Util::xml_is_string($domain);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_string($domain) 0 0 0
47 0 my @d;
48 0 push @d,['suggestion:key',$domain];
49  
50 0 ▶ if (Net::DRI::Util::has_key($rd,'language'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "language")) 0 0 0
51 {
52 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('language value must be of XML language type') unless Net::DRI::Util::xml_is_language($rd->{language});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_language($rd->{"language"}) 0 0 0
53 0 push @d,['suggestion:language',$rd->{language}];
54 }
55  
56 0 my @f;
57 0 ▶ if (Net::DRI::Util::has_key($rd,'filter_id'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, 'filter_id')) { } 0 0 0
58 {
59 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('filter_id must be an integer') unless $rd->{filter_id}=~m/^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $rd->{"filter_id"} =~ /^\d+$/ 0 0 0
60 0 push @d,['suggestion:filterid',$rd->{filter_id}];
61 } else
62 {
63 0 my %f;
64 0 foreach my $k (qw/contentfilter customfilter usehyphens usenumbers useidns/)
65 {
66 0 ▶ $f{$k}=$rd->{$k} if Net::DRI::Util::has_key($rd,$k) && Net::DRI::Util::xml_is_boolean($rd->{$k});
Branch: 1 branch
BranchTrueFalseTotal
if Net::DRI::Util::has_key($rd, $k) and Net::DRI::Util::xml_is_boolean($rd->{$k}) 0 0 0
Condition0%0/3
Net::DRI::Util::has_key($rd, $k) and Net::DRI::Util::xml_is_boolean($rd->{$k})
!ll&&!rl&&r
000
MC/DC0%0/2
Net::DRI::Util::has_key($rd, $k) and Net::DRI::Util::xml_is_boolean($rd->{$k})
Net::DRI::Util::has_key($rd, $k) Net::DRI::Util::xml_is_boolean($rd->{$k})
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($rd, $k)B= Net::DRI::Util::xml_is_boolean($rd->{$k})
ABresult
0X0
100
111
67 }
68 0 ▶ if (Net::DRI::Util::has_key($rd,'view'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "view")) 0 0 0
69 {
70 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('view must be either table or grid') unless $rd->{view}=~m/^(?:table|grid)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $rd->{"view"} =~ /^(?:table|grid)$/ 0 0 0
71 0 $f{view}=$rd->{view};
72 }
73 0 ▶ if (Net::DRI::Util::has_key($rd,'forsale'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "forsale")) 0 0 0
74 {
75 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('forsale must be either off, low, medium or high') unless $rd->{forsale}=~m/^(?:off|low|medium|high)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $rd->{"forsale"} =~ /^(?:off|low|medium|high)$/ 0 0 0
76 0 $f{forsale}=$rd->{forsale};
77 }
78 0 ▶ if (Net::DRI::Util::has_key($rd,'maxlength'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "maxlength")) 0 0 0
79 {
80 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('maxlength must be a number between 1 and 63') unless Net::DRI::Util::verify_int($rd->{maxlength},1,63);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_int($rd->{"maxlength"}, 1, 63) 0 0 0
81 0 $f{maxlength}=$rd->{maxlength};
82 }
83 0 ▶ if (Net::DRI::Util::has_key($rd,'maxresults'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "maxresults")) 0 0 0
84 {
85 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('maxresults must be a number between 1 and 100') unless Net::DRI::Util::verify_int($rd->{maxresults},1,100);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_int($rd->{"maxresults"}, 1, 100) 0 0 0
86 0 $f{maxresults}=$rd->{maxresults};
87 }
88  
89 0 ▶ if (Net::DRI::Util::has_key($rd,'action') && ref $rd->{action} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "action") and ref $rd->{"action"} eq "HASH") 0 0 0
Condition0%0/3
Net::DRI::Util::has_key($rd, "action") and ref $rd->{"action"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
Net::DRI::Util::has_key($rd, "action") and ref $rd->{"action"} eq "HASH"
Net::DRI::Util::has_key($rd, "action") ref $rd->{"action"} eq "HASH"
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($rd, "action")B= ref $rd->{"action"} eq "HASH"
ABresult
0X0
100
111
90 {
91 0 foreach my $action (sort { $a cmp $b } keys %{$rd->{action}})
92 {
93 0 my $weight=$rd->{action}->{$action};
94 0 ▶ Net::DRI::Exception::usererr_invalid_parameters(sprintf('weight for action "%s" myst be either off, low, medium or high',$action)) unless defined $weight && $weight=~/^(?:off|low|medium|high)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $weight and $weight =~ /^(?:off|low|medium|high)$/ 0 0 0
Condition0%0/3
defined $weight and $weight =~ /^(?:off|low|medium|high)$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $weight and $weight =~ /^(?:off|low|medium|high)$/
defined $weight $weight =~ /^(?:off|low|medium|high)$/
Truth table0%0/3
A and B
A= defined $weightB= $weight =~ /^(?:off|low|medium|high)$/
ABresult
0X0
100
111
95 0 push @f,['suggestion:action',{name => $action, weight => $weight }];
96 }
97 }
98 0 ▶ if (Net::DRI::Util::has_key($rd,'tld'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "tld")) 0 0 0
99 {
100 0 ▶ foreach my $tld (ref $rd->{tld} eq 'ARRAY' ? @{$rd->{tld}} : ($rd->{tld}))
Branch: 1 branch
BranchTrueFalseTotal
ref $rd->{'tld'} eq 'ARRAY' ? : 0 0 0
101 {
102 0 ▶ Net::DRI::Exception::usererr_invalid_parameters(sprintf('TLD must be 1 to 255 characters and not: ',defined $tld ? $tld : '<undef>')) unless Net::DRI::Util::xml_is_token($tld,1,255);
Branch: 2 branches
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($tld, 1, 255) 0 0 0
defined $tld ? : 0 0 0
103 0 push @f,['suggestion:tld',$tld];
104 }
105 }
106 0 ▶ if (Net::DRI::Util::has_key($rd,'geo') && ref $rd->{geo} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "geo") and ref $rd->{"geo"} eq "HASH") 0 0 0
Condition0%0/3
Net::DRI::Util::has_key($rd, "geo") and ref $rd->{"geo"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
Net::DRI::Util::has_key($rd, "geo") and ref $rd->{"geo"} eq "HASH"
Net::DRI::Util::has_key($rd, "geo") ref $rd->{"geo"} eq "HASH"
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($rd, "geo")B= ref $rd->{"geo"} eq "HASH"
ABresult
0X0
100
111
107 {
108 0 ▶ if (exists $rd->{geo}->{lat} && exists $rd->{geo}->{lon})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $rd->{'geo'}{'lat'} and exists $rd->{'geo'}{'lon'}) { } 0 0 0
elsif (exists $rd->{'geo'}{'addr'}) { } 0 0 0
Condition0%0/3
exists $rd->{"geo"}{"lat"} and exists $rd->{"geo"}{"lon"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rd->{"geo"}{"lat"} and exists $rd->{"geo"}{"lon"}
exists $rd->{"geo"}{"lat"} exists $rd->{"geo"}{"lon"}
Truth table0%0/3
A and B
A= exists $rd->{"geo"}{"lat"}B= exists $rd->{"geo"}{"lon"}
ABresult
0X0
100
111
109 {
110 0 my $lat = $rd->{geo}->{lat};
111 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('geo latitude must be a decimal with at most 6 decimal digits, between -90 and +90') unless Net::DRI::Util::xml_is_decimal($lat, 6, undef, -90, 90);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_decimal($lat, 6, undef, -90, 90) 0 0 0
112 0 my $lon = $rd->{geo}->{lon};
113 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('geo longitude must be a decimal with at most 6 decimal digits, between -180 and +180') unless Net::DRI::Util::xml_is_decimal($lat, 6, undef, -180, 180);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_decimal($lat, 6, undef, -180, 180) 0 0 0
114 0 push @f,['suggestion:geo',['suggestion:coordinates', { lat => $lat, lon => $lon } ]];
115 } elsif (exists $rd->{geo}->{addr})
116 {
117 0 my $addr = $rd->{geo}->{addr};
118 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('geo addr must be an XML token with 3 to 45 characters') unless Net::DRI::Util::xml_is_token($addr, 3, 45);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($addr, 3, 45) 0 0 0
119 0 ▶ my $ip = exist $rd->{geo}->{ip} ? $rd->{geo}->{ip} : 'v4';
Branch: 1 branch
BranchTrueFalseTotal
$rd->exist->{'geo'}{'ip'} ? : 0 0 0
120 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('geo ip must be v4 or v6 string') unless $ip=~m/^v[46]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip =~ /^v[46]$/ 0 0 0
121 0 push @f,['suggestion:geo',['suggestion:addr',{ ip => $ip }, $addr]];
122 } else
123 {
124 0 Net::DRI::Exception::usererr_insufficient_parameters('geo data should have either lat+lon keys or addr/addr+ip keys');
125 }
126 }
127  
128 0 ▶ @f=(['suggestion:filter',\%f,@f]) if %f || @f;
Branch: 1 branch
BranchTrueFalseTotal
if %f or @f 0 0 0
Condition0%0/3
%f or @f
l!l&&r!l&&!r
000
MC/DC0%0/2
%f or @f
%f @f
Truth table0%0/3
A or B
A= %fB= @f
ABresult
1X1
011
000
129 }
130  
131 0 ▶ push @d,@f if @f;
Branch: 1 branch
BranchTrueFalseTotal
if @f 0 0 0
132 0 ▶ if (Net::DRI::Util::has_key($rd, 'sub_id'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "sub_id")) 0 0 0
133 {
134 0 my $subid=$rd->{sub_id};
135 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('if provided sub_id value must be an XML token') unless Net::DRI::Util::xml_is_token($subid);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($subid) 0 0 0
136 0 push @d,['suggestion:subID', $subid];
137 }
138  
139 0 my $mes=$epp->message();
140 0 $mes->command(['info','suggestion:info', $mes->nsattrs('suggestion')]);
141 0 $mes->command_body(\@d);
142 0 return;
143 }
144  
145 sub parse
146 0 ▶{
Subroutine parse: not called CC=10 SCAR=47.0
Pod undocumented
147 0 my ($po,$otype,$oaction,$oname,$rinfo)=@_;
148 0 my $mes=$po->message();
149 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
150  
151 0 my $infdata=$mes->get_response('suggestion','infData');
152 0 ▶ return unless defined $infdata;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $infdata 0 0 0
153  
154 0 my $key;
155 0 my $ns=$mes->ns('suggestion');
156 0 foreach my $el (Net::DRI::Util::xml_list_children($infdata))
157 {
158 0 my ($n,$c)=@$el;
159 0 ▶ if ($n eq 'key')
Branch: 4 branches
BranchTrueFalseTotal
if ($n eq 'key') { } 0 0 0
elsif ($n eq 'language') { } 0 0 0
elsif ($n eq 'token') { } 0 0 0
elsif ($n eq 'answer') { } 0 0 0
160 {
161 0 $key=$c->textContent();
162 0 $rinfo->{domain}->{$key}->{action}='suggest';
163 0 $rinfo->{domain}->{$key}->{suggestions}={};
164 } elsif ($n eq 'language')
165 {
166 0 $rinfo->{domain}->{$key}->{suggestions}->{language}='ENG';
167 } elsif ($n eq 'token')
168 {
169 0 $rinfo->{domain}->{$key}->{suggestions}->{tokens}->{$c->getAttribute('name')}=[ map { $_->textContent() } (Net::DRI::Util::xml_traverse($c,$ns,'related')) ];
170 } elsif ($n eq 'answer')
171 {
172 0 my $ans=Net::DRI::Util::xml_traverse($c,$ns,'table');
173 0 ▶ if (defined $ans)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ans) 0 0 0
174 {
175 0 $rinfo->{domain}->{$key}->{suggestions}->{result_type}='table';
176 0 $rinfo->{domain}->{$key}->{suggestions}->{answer}=parse_table($ans,$ns);
177 }
178 0 $ans=Net::DRI::Util::xml_traverse($c,$ns,'grid');
179 0 ▶ if (defined $ans)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ans) 0 0 0
180 {
181 0 $rinfo->{domain}->{$key}->{suggestions}->{result_type}='grid';
182 0 $rinfo->{domain}->{$key}->{suggestions}->{answer}=parse_grid($ans,$ns);
183 }
184 }
185 }
186 0 return;
187 }
188  
189 sub parse_table
190 0 ▶{
Subroutine parse_table: not called CC=4 SCAR=30.0
Pod undocumented
191 0 my ($node,$ns)=@_;
192 0 my %r;
193  
194 0 foreach my $row (Net::DRI::Util::xml_traverse($node,$ns,'row'))
195 {
196 0 my %d;
197 0 my $name=$row->getAttribute('name');
198 0 $d{score}=0+$row->getAttribute('score');
199 0 $d{status}=$row->getAttribute('status');
200 0 foreach my $key (qw/source morelikethis ppcvalue uName/)
201 {
202 0 my $v=$row->getAttribute($key);
203 0 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
204 0 $d{lc $key}=$v;
205 }
206 0 $r{$name}=\%d;
207 }
208 0 return \%r;
209 }
210  
211  
212 sub parse_grid
213 0 ▶{
Subroutine parse_grid: not called CC=6 SCAR=37.4
Pod undocumented
214 0 my ($node,$ns)=@_;
215 0 my %r;
216  
217 0 foreach my $row (Net::DRI::Util::xml_traverse($node,$ns,'record'))
218 {
219 0 my %d;
220 0 my $name=$row->getAttribute('name');
221 0 foreach my $key (qw/source morelikethis ppcvalue/)
222 {
223 0 my $v=$row->getAttribute($key);
224 0 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
225 0 $d{$key}=$v;
226 }
227 0 my %rr;
228 0 foreach my $cell (Net::DRI::Util::xml_traverse($row,$ns,'cell'))
229 {
230 0 my $tld=$cell->getAttribute('tld');
231 0 $rr{$tld}={ score => 0+$cell->getAttribute('score'), status => $cell->getAttribute('status'), %d };
232 0 ▶ $rr{$tld}->{utld}=$cell->getAttribute('uTld') if $cell->hasAttribute('uTld');
Branch: 1 branch
BranchTrueFalseTotal
if $cell->hasAttribute("uTld") 0 0 0
233 }
234 0 $r{$name}=\%rr;
235 }
236 0 return \%r;
237 }
238 #########################################################################################################
239 1 1;
240  
241 __END__
« DRI/Data/Contact/DENIC.pm ↑ Summary DRI/Protocol/EPP/Extensions/PL/Message.pm »