DRI/Registry.pm

filter: Statementstmt 25.9% 96 / 370 Branchbran 11.5% 23 / 200 Conditioncond 9.4% 13 / 138 MC/DCmcdc 2.5% 2 / 80 Subroutinesub 42.8% 24 / 56 Podpod 2.3% 1 / 43 totaltotal 17.9% 159 / 887 CC 155 SCAR 49.5
CC
155
Cov
19%
process
520.0
process_back
380.0
protocol_capable
182.0
CRAP 141.9
« DRI/Protocol/EPP/Extensions/UnitedTLD/Charge.pm ↑ Summary DRI/Protocol/EPP/Extensions/ChangePoll.pm »
1 ## Domain Registry Interface, Registry object
2 ##
3 ## Copyright (c) 2005-2011,2013-2015 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::Registry;
16  
17 85 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 85 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 85 ▶use base qw(Class::Accessor::Chained::Fast Net::DRI::BaseClass);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 85 __PACKAGE__->mk_ro_accessors(qw(name driver profile trid_factory logging)); ## READ-ONLY !!
22  
23 85 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 85 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 85 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 85 ▶use Net::DRI::Protocol::ResultStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 85 ▶use Net::DRI::Data::RegistryObject;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 85 our $AUTOLOAD;
31  
32 =pod
33  
34 =head1 NAME
35  
36 Net::DRI::Registry - Specific Registry Driver Instance inside Net::DRI
37  
38 =head1 DESCRIPTION
39  
40 Please see the README file for details.
41  
42 =head1 SUPPORT
43  
44 For now, support questions should be sent to:
45  
46 E<lt>netdri@dotandco.comE<gt>
47  
48 Please also see the SUPPORT file in the distribution.
49  
50 =head1 SEE ALSO
51  
52 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
53  
54 =head1 AUTHOR
55  
56 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
57  
58 =head1 COPYRIGHT
59  
60 Copyright (c) 2005-2011,2013-2015 Patrick Mevzek <netdri@dotandco.com>.
61 All rights reserved.
62  
63 This program is free software; you can redistribute it and/or modify
64 it under the terms of the GNU General Public License as published by
65 the Free Software Foundation; either version 2 of the License, or
66 (at your option) any later version.
67  
68 See the LICENSE file that comes with this distribution for more details.
69  
70 =cut
71  
72 ####################################################################################################
73  
74 sub new
75 {
76 78 ▶ my ($class,$name,$drd,$cache,$trid,$logging)=@_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
77  
78 78 my $self={name => $name,
79 driver => $drd,
80 cache => $cache,
81 profiles => {}, ## { profile name => { protocol => X
82 ## transport => X
83 ## status => Net::DRI::Protocol::ResultStatus
84 ## %extra
85 ## }
86 ## }
87 profile => undef, ## current profile
88 auto_target => {},
89 last_data => {},
90 last_process => {},
91 trid_factory => $trid,
92 logging => $logging,
93 };
94  
95 78 bless($self,$class);
96 78 return $self;
97 }
98  
99 sub available_profile
100 {
101 0 ▶ my $self=shift;
Subroutine available_profile: not called CC=2 SCAR=17.9
Pod undocumented
102 0 ▶ return (defined($self->{profile}))? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'profile'} ? : 0 0 0
103 }
104  
105 sub available_profiles
106 {
107 0 ▶ my ($self,$full)=@_;
Subroutine available_profiles: not called CC=3 SCAR=24.8
Pod undocumented
108 0 ▶ $full||=0;
Condition0%0/2
$full ||= 0
l!l
00
MC/DC0%0/1
$full ||= 0
$full
Truth table0%0/2
A
A= $full
Aresult
11
00
109 0 ▶ my @r=sort { $a cmp $b } ($full ? map { $_->{fullname} } values(%{$self->{profiles}}) : keys(%{$self->{profiles}}));
Branch: 1 branch
BranchTrueFalseTotal
$full ? : 0 0 0
110 0 return @r;
111 }
112  
113 sub exist_profile
114 {
115 78 ▶ my ($self,$name)=@_;
Subroutine exist_profile: called CC=2 SCAR=8.1
Pod undocumented
116 78 ▶ return (defined($name) && exists($self->{profiles}->{$name}));
Condition33%1/3
defined $name && exists $self->{'profiles'}{$name}
!ll&&!rl&&r
0780
MC/DC0%0/2
defined $name && exists $self->{'profiles'}{$name}
defined $name exists $self->{'profiles'}{$name}
Truth table33%1/3
A && B
A= defined $nameB= exists $self->{'profiles'}{$name}
ABresult
0X0
100
111
117 }
118  
119 4 ▶sub err_no_current_profile { Net::DRI::Exception->die(0,'DRI',3,'No current profile available'); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine err_no_current_profile: called CC=1 SCAR=0.0
Pod undocumented
120 0 ▶sub err_profile_name_does_not_exist { Net::DRI::Exception->die(0,'DRI',4,'Profile name '.$_[0].' does not exist'); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine err_profile_name_does_not_exist: not called CC=1 SCAR=6.9
Pod undocumented
121  
122 sub remote_object
123 {
124 0 ▶ my ($self,@args)=@_;
Subroutine remote_object: not called CC=1 SCAR=6.9
Pod undocumented
125 0 return Net::DRI::Data::RegistryObject->new($self,@args);
126 }
127  
128 sub _current
129 {
130 4 ▶ my ($self,$what,$tostore)=@_;
Subroutine _current: called CC=7 SCAR=36.3
131 4 ▶ err_no_current_profile() unless (defined($self->{profile}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"profile"} 4 0 4
132 0 ▶ err_profile_name_does_not_exist($self->{profile}) unless (exists($self->{profiles}->{$self->{profile}}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"profiles"}{$self->{"profile"}} 0 0 0
133 0 ▶ Net::DRI::Exception::err_assert('key should be transport, protocol or status, and not: '.$what) unless defined $what && exists $self->{profiles}->{$self->{profile}}->{$what};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what and exists $self->{"profiles"}{$self->{"profile"}}{$what} 0 0 0
Condition0%0/3
defined $what and exists $self->{"profiles"}{$self->{"profile"}}{$what}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $what and exists $self->{"profiles"}{$self->{"profile"}}{$what}
defined $what exists $self->{"profiles"}{$self->{"profile"}}{$what}
Truth table0%0/3
A and B
A= defined $whatB= exists $self->{"profiles"}{$self->{"profile"}}{$what}
ABresult
0X0
100
111
134  
135 0 ▶ if (($what eq 'status') && $tostore)
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "status" and $tostore) 0 0 0
Condition0%0/3
$what eq "status" and $tostore
!ll&&!rl&&r
000
MC/DC0%0/2
$what eq "status" and $tostore
$what eq "status" $tostore
Truth table0%0/3
A and B
A= $what eq "status"B= $tostore
ABresult
0X0
100
111
136 {
137 0 $self->{profiles}->{$self->{profile}}->{$what}=$tostore;
138 }
139  
140 0 return $self->{profiles}->{$self->{profile}}->{$what};
141 }
142  
143 0 ▶sub transport { return shift->_current('transport'); }
Subroutine transport: not called CC=1 SCAR=6.9
Pod undocumented
144 1 ▶sub protocol { return shift->_current('protocol'); }
Subroutine protocol: called CC=1 SCAR=0.0
Pod undocumented
145 0 ▶sub status { return shift->_current('status',@_); } ## no critic (Subroutines::RequireArgUnpacking)
Subroutine status: not called CC=1 SCAR=6.9
Pod undocumented
146 1 ▶sub protocol_transport { my $self=shift; return ($self->protocol(),$self->transport()); }
Subroutine protocol_transport: called CC=1 SCAR=0.0
Pod undocumented
147  
148 sub local_object
149 {
150 3 ▶ my ($self,$f,@args)=@_;
Subroutine local_object: called CC=3 SCAR=12.5
Pod undocumented
151 3 ▶ return unless $self && $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $f 0 3 3
Condition33%1/3
$self and $f
!ll&&!rl&&r
003
MC/DC0%0/2
$self and $f
$self $f
Truth table33%1/3
A and B
A= $selfB= $f
ABresult
0X0
100
111
152 3 return $self->_current('protocol')->create_local_object($f,@args);
153 }
154  
155 sub _result
156 {
157 0 ▶ my ($self,$f)=@_;
Subroutine _result: not called CC=7 SCAR=40.3
158 0 my $p=$self->profile();
159 0 ▶ err_no_current_profile() unless (defined($p));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 0 0
160 0 ▶ Net::DRI::Exception->die(0,'DRI',6,'No last status code available for current registry and profile') unless (exists($self->{profiles}->{$p}->{status}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"profiles"}{$p}{"status"} 0 0 0
161 0 my $rc=$self->{profiles}->{$p}->{status}; ## a Net::DRI::Protocol::ResultStatus object !
162 0 ▶ Net::DRI::Exception->die(1,'DRI',5,'Status key is not a Net::DRI::Protocol::ResultStatus object') unless Net::DRI::Util::is_class($rc,'Net::DRI::Protocol::ResultStatus');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::is_class($rc, "Net::DRI::Protocol::ResultStatus") 0 0 0
163 0 ▶ return $rc if ($f eq 'self');
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "self" 0 0 0
164 0 ▶ Net::DRI::Exception::method_not_implemented($f,'Net::DRI::Protocol::ResultStatus') unless ($f && $rc->can($f));
Branch: 1 branch
BranchTrueFalseTotal
unless $f and $rc->can($f) 0 0 0
Condition0%0/3
$f and $rc->can($f)
!ll&&!rl&&r
000
MC/DC0%0/2
$f and $rc->can($f)
$f $rc->can($f)
Truth table0%0/3
A and B
A= $fB= $rc->can($f)
ABresult
0X0
100
111
165 0 return $rc->$f();
166 }
167  
168 0 ▶sub result_is_success { return shift->_result('is_success'); }
Subroutine result_is_success: not called CC=1 SCAR=6.9
Pod undocumented
169 0 ▶sub is_success { return shift->_result('is_success'); } ## Alias
Subroutine is_success: not called CC=1 SCAR=6.9
Pod undocumented
170 0 ▶sub result_code { return shift->_result('code'); }
Subroutine result_code: not called CC=1 SCAR=6.9
Pod undocumented
171 0 ▶sub result_native_code { return shift->_result('native_code'); }
Subroutine result_native_code: not called CC=1 SCAR=6.9
Pod undocumented
172 0 ▶sub result_message { return shift->_result('message'); }
Subroutine result_message: not called CC=1 SCAR=6.9
Pod undocumented
173 0 ▶sub result_lang { return shift->_result('lang'); }
Subroutine result_lang: not called CC=1 SCAR=6.9
Pod undocumented
174 0 ▶sub result_status { return shift->_result('self'); }
Subroutine result_status: not called CC=1 SCAR=6.9
Pod undocumented
175 0 ▶sub result_extra_info { return shift->_result('info'); }
Subroutine result_extra_info: not called CC=1 SCAR=6.9
Pod undocumented
176  
177 0 ▶sub cache_expire { return shift->{cache}->delete_expired(); }
Subroutine cache_expire: not called CC=1 SCAR=6.9
Pod undocumented
178 0 ▶sub cache_clear { return shift->{cache}->delete(); }
Subroutine cache_clear: not called CC=1 SCAR=6.9
Pod undocumented
179  
180 sub set_info
181 {
182 0 ▶ my ($self,$type,$key,$data,$ttl)=@_;
Subroutine set_info: not called CC=2 SCAR=17.9
Pod undocumented
183 0 my $p=$self->profile();
184 0 ▶ err_no_current_profile() unless defined($p);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 0 0
185 0 my $regname=$self->name();
186  
187 0 my $c=$self->{cache}->set($regname.'.'.$p,$type,$key,$data,$ttl);
188 0 $self->{last_data}=$c; ## the hash exists, since we called clear_info somewhere before
189 0 $self->{last_data}->{result_from_cache}=0;
190  
191 0 return $c;
192 }
193  
194 ## Returns a $rc object or undef if nothing found in cache for the specific object ($type/$key) and action ($action)
195 sub try_restore_from_cache
196 {
197 0 ▶ my ($self,$type,$key,$action)=@_;
Subroutine try_restore_from_cache: not called CC=5 SCAR=34.0
Pod undocumented
198 0 ▶ if (! Net::DRI::Util::all_valid($type,$key,$action)) { Net::DRI::Exception::err_assert('try_restore_from_cache improperly called'); }
Branch: 1 branch
BranchTrueFalseTotal
unless (Net::DRI::Util::all_valid($type, $key, $action)) 0 0 0
199  
200 0 my $a=$self->get_info('action',$type,$key);
201 ## not in cache or in cache but for some other action
202 0 ▶ if (! defined $a || ($a ne $action)) { $self->log_output('debug','core',sprintf('Cache MISS (empty cache or other action) for type=%s key=%s',$type,$key)); return; }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $a or $a ne $action) 0 0 0
Condition0%0/3
not defined $a or $a ne $action
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $a or $a ne $action
not defined $a $a ne $action
Truth table0%0/3
not(A) or B
A= not defined $aB= $a ne $action
ABresult
1X1
011
000
203  
204 ## retrieve from cache, copy, and do some cleanup
205 0 $self->{last_data}=$self->get_info_all($type,$key);
206 ## since we passed the above test on get_info('action'), we know here we received something defined by get_info_all,
207 ## but we test explicitly again (get_info_all returns an empty ref hash on problem, not undef), to avoid race conditions and such
208 0 ▶ if (! keys(%{$self->{last_data}})) { $self->log_output('debug','core',sprintf('Cache MISS (no last_data content) for type=%s key=%s',$type,$key)); return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %{$$self{"last_data"};}) 0 0 0
209  
210 ## Clone the result_status object as it may be linked from others part, and we may tweak its link chain (for example in domain_check)
211 0 $self->{last_data}->{result_status}=$self->{last_data}->{result_status}->clone();
212  
213 ## get_info_all makes a copy, but only at first level ! so this high level change is ok (no pollution), but be warned for below !
214 0 $self->{last_data}->{result_from_cache}=1;
215  
216 ## Important note here:
217 ## we were previously kind of copying the session/exchange branch as obtained from $self->{last_data}->{result_status}->{local,global}_get_data_collection()
218 ## before doing change
219 ## however this is in fact unnecessary and complicated
220 ## complicated because in fact of the ambiguity above in local or global get_data_collection
221 ## unneccessary because wer are just setting result_from_cache to 1 here in session/exchange,
222 ## and 1) as soon as this flag is flipped, it will never revert back to 0
223 ## 2) in process_back() below we made a copy of session/exchange before putting it in ResultStatus, so changing it here, does not change previous result status given back to client
224 0 $self->{last_data}->{result_status}->local_get_data_collection()->{session}->{exchange}->{result_from_cache}=1;
225 0 $self->{cache}->set_result_from_cache($type,$key);
226 0 $self->{cache}->set_result_from_cache('session','exchange');
227 0 $self->{cache}->set_result_from_cache('message','info');
228  
229 0 $self->log_output('debug','core',sprintf('Cache HIT for type=%s key=%s',$type,$key));
230 0 return $self->{last_data}->{result_status};
231 }
232  
233 0 ▶sub clear_info { shift->{last_data}={}; } ## no critic (Subroutines::RequireFinalReturn)
Subroutine clear_info: not called CC=1 SCAR=6.9
Pod undocumented
234  
235 sub get_info
236 {
237 0 ▶ my ($self,$what,$type,$key)=@_;
Subroutine get_info: not called CC=6 SCAR=37.4
Pod undocumented
238 0 ▶ return unless defined $what && $what;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what and $what 0 0 0
Condition0%0/3
defined $what and $what
!ll&&!rl&&r
000
MC/DC0%0/2
defined $what and $what
defined $what $what
Truth table0%0/3
A and B
A= defined $whatB= $what
ABresult
0X0
100
111
239  
240 0 ▶ if (Net::DRI::Util::all_valid($type,$key)) ## search the cache, by default same registry & profile !
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::all_valid($type, $key)) { } 0 0 0
241 {
242 0 my $p=$self->profile();
243 0 ▶ err_no_current_profile() unless defined($p);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 0 0
244 0 my $regname=$self->name();
245 0 return $self->{cache}->get($type,$key,$what,$regname.'.'.$p);
246 } else
247 {
248 0 ▶ return unless exists $self->{last_data}->{$what};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"last_data"}{$what} 0 0 0
249 0 return $self->{last_data}->{$what};
250 }
251 }
252  
253 sub get_info_all
254 {
255 0 ▶ my ($self,$type,$key)=@_;
Subroutine get_info_all: not called CC=7 SCAR=40.3
Pod undocumented
256 0 my $rh;
257  
258 0 ▶ if (Net::DRI::Util::all_valid($type,$key))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::all_valid($type, $key)) { } 0 0 0
259 {
260 0 my $p=$self->profile();
261 0 ▶ err_no_current_profile() unless defined($p);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 0 0
262 0 my $regname=$self->name();
263 0 $rh=$self->{cache}->get($type,$key,undef,$regname.'.'.$p);
264 } else
265 {
266 0 $rh=$self->{last_data};
267 }
268  
269 0 ▶ return {} unless (defined($rh) && ref($rh) && keys(%$rh));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rh and ref $rh and keys %$rh 0 0 0
Condition0%0/6
defined $rh and ref $rh and keys %$rh
!ll&&!rl&&r
000
defined $rh and ref $rh
!ll&&!rl&&r
000
MC/DC0%0/3
defined $rh and ref $rh and keys %$rh
defined $rh ref $rh keys %$rh
Truth table0%0/4
A and B and C
A= defined $rhB= ref $rhC= keys %$rh
ABCresult
0XX0
10X0
1100
1111
270  
271 0 my %h=%{ $rh }; ## create a copy, as we will delete content... ## BUGFIX !!
272 0 foreach my $k (grep { /^_/ } keys(%h)) { delete($h{$k}); }
273 0 return \%h;
274 }
275  
276 sub get_info_keys
277 {
278 0 ▶ my ($self,$type,$key)=@_;
Subroutine get_info_keys: not called CC=1 SCAR=6.9
Pod undocumented
279 0 my @r=sort { $a cmp $b } keys %{ $self->get_info_all($type,$key) };
280 0 return @r;
281 }
282  
283 ####################################################################################################
284 ## Change profile
285 sub target
286 {
287 0 ▶ my ($self,$profile)=@_;
Subroutine target: not called CC=3 SCAR=24.8
Pod undocumented
288 0 ▶ err_profile_name_does_not_exist($profile) unless ($profile && exists($self->{profiles}->{$profile}));
Branch: 1 branch
BranchTrueFalseTotal
unless $profile and exists $self->{"profiles"}{$profile} 0 0 0
Condition0%0/3
$profile and exists $self->{"profiles"}{$profile}
!ll&&!rl&&r
000
MC/DC0%0/2
$profile and exists $self->{"profiles"}{$profile}
$profile exists $self->{"profiles"}{$profile}
Truth table0%0/3
A and B
A= $profileB= exists $self->{"profiles"}{$profile}
ABresult
0X0
100
111
289 0 $self->{profile}=$profile;
290 0 return;
291 }
292  
293 sub profile_auto_switch
294 {
295 1 ▶ my ($self,$otype,$oaction)=@_;
Subroutine profile_auto_switch: called CC=2 SCAR=8.4
Pod undocumented
296 1 my $p=$self->get_auto_target($otype,$oaction);
297 1 ▶ return unless defined($p);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 1 0 1
298 0 $self->target($p);
299 0 return;
300 }
301  
302 sub set_auto_target
303 {
304 0 ▶ my ($self,$profile,$otype,$oaction)=@_; ## $otype/$oaction may be undef
Subroutine set_auto_target: not called CC=6 SCAR=37.4
Pod undocumented
305 0 ▶ err_profile_name_does_not_exist($profile) unless ($profile && exists($self->{profiles}->{$profile}));
Branch: 1 branch
BranchTrueFalseTotal
unless $profile and exists $self->{"profiles"}{$profile} 0 0 0
Condition0%0/3
$profile and exists $self->{"profiles"}{$profile}
!ll&&!rl&&r
000
MC/DC0%0/2
$profile and exists $self->{"profiles"}{$profile}
$profile exists $self->{"profiles"}{$profile}
Truth table0%0/3
A and B
A= $profileB= exists $self->{"profiles"}{$profile}
ABresult
0X0
100
111
306  
307 0 my $rh=$self->{auto_target};
308 0 ▶ $otype||='_default';
Condition0%0/2
$otype ||= "_default"
l!l
00
MC/DC0%0/1
$otype ||= "_default"
$otype
Truth table0%0/2
A
A= $otype
Aresult
11
00
309 0 ▶ $oaction||='_default';
Condition0%0/2
$oaction ||= "_default"
l!l
00
MC/DC0%0/1
$oaction ||= "_default"
$oaction
Truth table0%0/2
A
A= $oaction
Aresult
11
00
310 0 ▶ $rh->{$otype}={} unless (exists($rh->{$otype}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rh->{$otype} 0 0 0
311 0 $rh->{$otype}->{$oaction}=$profile;
312 0 return;
313 }
314  
315 sub get_auto_target
316 {
317 1 ▶ my ($self,$otype,$oaction)=@_;
Subroutine get_auto_target: called CC=7 SCAR=32.5
Pod undocumented
318 1 my $at=$self->{auto_target};
319 1 ▶ $otype='_default' unless (exists($at->{$otype}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $at->{$otype} 1 0 1
320 1 ▶ return unless (exists($at->{$otype}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $at->{$otype} 1 0 1
321 0 my $ac=$at->{$otype};
322 0 ▶ return unless (defined($ac) && ref($ac));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ac and ref $ac 0 0 0
Condition0%0/3
defined $ac and ref $ac
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ac and ref $ac
defined $ac ref $ac
Truth table0%0/3
A and B
A= defined $acB= ref $ac
ABresult
0X0
100
111
323 0 ▶ $oaction='_default' unless (exists($ac->{$oaction}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ac->{$oaction} 0 0 0
324 0 ▶ return unless (exists($ac->{$oaction}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ac->{$oaction} 0 0 0
325 0 return $ac->{$oaction};
326 }
327  
328 sub add_current_profile
329 {
330 78 ▶ my ($self,@p)=@_;
Subroutine add_current_profile: called CC=2 SCAR=11.6
Pod undocumented
331 78 my $rc=$self->add_profile(@p);
332 0 ▶ $self->target($p[0]) if $rc->is_success();
Branch: 1 branch
BranchTrueFalseTotal
if $rc->is_success 0 0 0
333 0 return $rc;
334 }
335  
336 ## Transport and Protocol parameters are merged (semantically but not chronologically, parameters coming later erase previous ones) in this order;
337 ## - TransportConnectionClass->transport_default() [only for transport parameters]
338 ## - Protocol->transport_default() [only for transport parameters]
339 ## - DRD->transport_protocol_default()
340 ## - user specified parameters to add_profile (they always have precedence over defaults stored in the 3 previous cases)
341  
342 ## API: profile name, profile type, transport params {}, protocol params {}
343 sub add_profile
344 {
345 78 ▶ my ($self,$name,$type,$trans_p,$prot_p)=@_;
Subroutine add_profile: called CC=23 SCAR=49.7
Pod undocumented
346  
347 78 ▶ if (! Net::DRI::Util::all_valid($name,$type)) { Net::DRI::Exception::usererr_insufficient_parameters('add_profile needs at least 2 parameters: new profile name and type'); }
Branch: 1 branch
BranchTrueFalseTotal
unless (Net::DRI::Util::all_valid($name, $type)) 0 78 78
348 78 ▶ if ($self->exist_profile($name)) { Net::DRI::Exception::usererr_invalid_parameters('New profile name "'.$name.'" already in use'); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exist_profile($name)) 0 78 78
349 78 ▶ if (defined $trans_p && ref $trans_p ne 'HASH') { Net::DRI::Exception::usererr_invalid_parameters('If provided, 3rd parameter of add_profile (transport data) must be a ref hash'); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trans_p and ref $trans_p ne "HASH") 0 78 78
Condition33%1/3
defined $trans_p and ref $trans_p ne "HASH"
!ll&&!rl&&r
0780
MC/DC0%0/2
defined $trans_p and ref $trans_p ne "HASH"
defined $trans_p ref $trans_p ne "HASH"
Truth table33%1/3
A and B
A= defined $trans_pB= ref $trans_p ne "HASH"
ABresult
0X0
100
111
350 78 ▶ if (defined $prot_p && ref $prot_p ne 'HASH') { Net::DRI::Exception::usererr_invalid_parameters('If provided, 4th parameter of add_profile (protocol data) must be a ref hash'); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prot_p and ref $prot_p ne "HASH") 0 78 78
Condition66%2/3
defined $prot_p and ref $prot_p ne "HASH"
!ll&&!rl&&r
36420
MC/DC0%0/2
defined $prot_p and ref $prot_p ne "HASH"
defined $prot_p ref $prot_p ne "HASH"
Truth table66%2/3
A and B
A= defined $prot_pB= ref $prot_p ne "HASH"
ABresult
0X0
100
111
351  
352 78 my $drd=$self->driver();
353 78 my ($tc,$tp,$pc,$pp)=$drd->transport_protocol_default($type); ## Transport Class, Transport Params, Protocol Class, Protocol Params
354 78 my $test=0;
355 78 ▶ if (exists $INC{'Test/More.pm'} && defined $trans_p && exists $trans_p->{f_send})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{"Test/More.pm"} and defined $trans_p and exists $trans_p->{"f_send"}) 78 0 78
Condition33%2/6
exists $INC{"Test/More.pm"} and defined $trans_p and exists $trans_p->{"f_send"}
!ll&&!rl&&r
0078
exists $INC{"Test/More.pm"} and defined $trans_p
!ll&&!rl&&r
0078
MC/DC0%0/3
exists $INC{"Test/More.pm"} and defined $trans_p and exists $trans_p->{"f_send"}
exists $INC{"Test/More.pm"} defined $trans_p exists $trans_p->{"f_send"}
Truth table25%1/4
A and B and C
A= exists $INC{"Test/More.pm"}B= defined $trans_pC= exists $trans_p->{"f_send"}
ABCresult
0XX0
10X0
1100
1111
356 {
357 78 $test=1;
358 78 $self->log_output('emergency','core','For profile "'.$name.'", using INTERNAL TESTING configuration! This should not happen in production, but only during "make test"!');
359 78 $tc='Net::DRI::Transport::Dummy';
360 78 $tp={};
361 }
362  
363 78 ▶ if (!Net::DRI::Util::all_valid($tc,$tp,$pc,$pp) || ref $tp ne 'HASH' || ref $pp ne 'HASH') { Net::DRI::Exception::usererr_invalid_parameters(sprintf('Registry "%s" does not provide profile type "%s")',$self->name(),$type)); }
Branch: 1 branch
BranchTrueFalseTotal
if (not Net::DRI::Util::all_valid($tc, $tp, $pc, $pp) or ref $tp ne "HASH" or ref $pp ne "HASH") 0 78 78
Condition33%2/6
not Net::DRI::Util::all_valid($tc, $tp, $pc, $pp) or ref $tp ne "HASH" or ref $pp ne "HASH"
l!l&&r!l&&!r
0078
not Net::DRI::Util::all_valid($tc, $tp, $pc, $pp) or ref $tp ne "HASH"
l!l&&r!l&&!r
0078
MC/DC0%0/3
not Net::DRI::Util::all_valid($tc, $tp, $pc, $pp) or ref $tp ne "HASH" or ref $pp ne "HASH"
not Net::DRI::Util::all_valid($tc, $tp, $pc, $pp) ref $tp ne "HASH" ref $pp ne "HASH"
Truth table25%1/4
not(A) or B or C
A= not Net::DRI::Util::all_valid($tc, $tp, $pc, $pp)B= ref $tp ne "HASH"C= ref $pp ne "HASH"
ABCresult
1XX1
01X1
0011
0000
364  
365 78 ▶ $tp={ %$tp, %$trans_p } if defined $trans_p;
Branch: 1 branch
BranchTrueFalseTotal
if defined $trans_p 78 0 78
366 78 ▶ $pp={ %$pp, %$prot_p } if defined $prot_p;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prot_p 42 36 78
367  
368 78 ▶ $drd->transport_protocol_init($type,$tc,$tp,$pc,$pp,$test) if $drd->can('transport_protocol_init');
Branch: 1 branch
BranchTrueFalseTotal
if $drd->can("transport_protocol_init") 4 74 78
369  
370 78 Net::DRI::Util::load_module($tc,'DRI');
371 78 Net::DRI::Util::load_module($pc,'DRI');
372 0 $self->log_output('debug','core',sprintf('For profile "%s" attempting to initialize transport "%s" and protocol "%s"',$name,$tc,$pc));
373  
374 ## Protocol must come first, as it may be needed during transport setup; it should not die
375 0 my $po=$pc->new({registry=>$self,profile=>$name,transport_class=>$tc},$pp);
376 0 ▶ $tp={ $po->transport_default(), %$tp } if ($po->can('transport_default'));
Branch: 1 branch
BranchTrueFalseTotal
if $po->can("transport_default") 0 0 0
377  
378 0 my ($to,$rc);
379 my $ok=eval
380 0 {
381 0 ($to,$rc)=$tc->new({registry=>$self,profile=>$name,protocol=>$po},$tp); ## this may die !
382 0 1;
383 };
384 0 ▶ if (! $ok) ## some kind of error happened
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
385 {
386 0 my $err=$@;
387 0 ▶ return $err if ref $err eq 'Net::DRI::Protocol::ResultStatus';
Branch: 1 branch
BranchTrueFalseTotal
if ref $err eq "Net::DRI::Protocol::ResultStatus" 0 0 0
388 0 ▶ $err=Net::DRI::Exception->new(1,'internal',0,'Error not handled: '.$err) unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
389 0 die $err;
390 }
391 0 ▶ return $rc if defined $rc && ! $rc->is_success();
Branch: 1 branch
BranchTrueFalseTotal
if defined $rc and not $rc->is_success 0 0 0
Condition0%0/3
defined $rc and not $rc->is_success
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rc and not $rc->is_success
defined $rc not $rc->is_success
Truth table0%0/3
A and not(B)
A= defined $rcB= not $rc->is_success
ABresult
0X0
100
111
392  
393 0 my $fullname=sprintf('%s (%s/%s + %s/%s)',$name,$po->name(),$po->version(),$to->name(),$to->version());
394 0 $self->{profiles}->{$name}={ fullname => $fullname, transport => $to, protocol => $po, status => undef };
395 0 $self->log_output('notice','core','Successfully added profile "'.$fullname.'"');
396 0 my $lrc=Net::DRI::Protocol::ResultStatus->new_success('Profile "'.$name.'" added successfully','en');
397 0 ▶ return $lrc unless defined $rc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rc 0 0 0
398 0 $rc->_set_last($lrc);
399 0 return $rc;
400 }
401  
402 sub del_profile
403 {
404 0 ▶ my ($self,$name)=@_;
Subroutine del_profile: not called CC=9 SCAR=45.0
Pod undocumented
405 0 ▶ if (defined($name))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 0 0 0
406 {
407 0 ▶ err_profile_name_does_not_exist($name) unless $self->exist_profile($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exist_profile($name) 0 0 0
408 } else
409 {
410 0 ▶ err_no_current_profile() unless defined $self->{profile};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"profile"} 0 0 0
411 0 $name=$self->{profile};
412 }
413  
414 0 my $p=$self->{profiles}->{$name};
415 0 ▶ $p->{protocol}->end() if ref $p->{protocol} && $p->{protocol}->can('end');
Branch: 1 branch
BranchTrueFalseTotal
if ref $p->{"protocol"} and $p->{"protocol"}->can("end") 0 0 0
Condition0%0/3
ref $p->{"protocol"} and $p->{"protocol"}->can("end")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $p->{"protocol"} and $p->{"protocol"}->can("end")
ref $p->{"protocol"} $p->{"protocol"}->can("end")
Truth table0%0/3
A and B
A= ref $p->{"protocol"}B= $p->{"protocol"}->can("end")
ABresult
0X0
100
111
416 0 ▶ $p->{transport}->end({registry => $self, profile => $name}) if ref $p->{transport} && $p->{transport}->can('end');
Branch: 1 branch
BranchTrueFalseTotal
if ref $p->{"transport"} and $p->{"transport"}->can("end") 0 0 0
Condition0%0/3
ref $p->{"transport"} and $p->{"transport"}->can("end")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $p->{"transport"} and $p->{"transport"}->can("end")
ref $p->{"transport"} $p->{"transport"}->can("end")
Truth table0%0/3
A and B
A= ref $p->{"transport"}B= $p->{"transport"}->can("end")
ABresult
0X0
100
111
417 0 delete($self->{profiles}->{$name});
418 0 ▶ $self->{profile}=undef if $self->{profile} eq $name; ## current profile is not defined anymore
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"profile"} eq $name 0 0 0
419 0 return Net::DRI::Protocol::ResultStatus->new_success('Profile "'.$name.'" deleted successfully','en');
420 }
421  
422 sub end
423 {
424 78 ▶ my $self=shift;
Subroutine end: called CC=7 SCAR=32.1
Pod undocumented
425 78 foreach my $name (keys %{$self->{profiles}})
426 {
427 0 my $p=$self->{profiles}->{$name};
428 0 ▶ $p->{transport}->end({protocol => $p->{protocol}}) if ref $p->{transport} && $p->{transport}->can('end');
Branch: 1 branch
BranchTrueFalseTotal
if ref $p->{"transport"} and $p->{"transport"}->can("end") 0 0 0
Condition0%0/3
ref $p->{"transport"} and $p->{"transport"}->can("end")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $p->{"transport"} and $p->{"transport"}->can("end")
ref $p->{"transport"} $p->{"transport"}->can("end")
Truth table0%0/3
A and B
A= ref $p->{"transport"}B= $p->{"transport"}->can("end")
ABresult
0X0
100
111
429 0 ▶ $p->{protocol}->end() if ref $p->{protocol} && $p->{protocol}->can('end');
Branch: 1 branch
BranchTrueFalseTotal
if ref $p->{"protocol"} and $p->{"protocol"}->can("end") 0 0 0
Condition0%0/3
ref $p->{"protocol"} and $p->{"protocol"}->can("end")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $p->{"protocol"} and $p->{"protocol"}->can("end")
ref $p->{"protocol"} $p->{"protocol"}->can("end")
Truth table0%0/3
A and B
A= ref $p->{"protocol"}B= $p->{"protocol"}->can("end")
ABresult
0X0
100
111
430 0 delete $self->{profiles}->{$name}
431 }
432  
433 78 ▶ $self->{driver}->end() if $self->{driver}->can('end');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driver"}->can("end") 0 78 78
434 78 return;
435 }
436  
437 sub can
438 {
439 328 ▶ my ($self,$what)=@_;
Subroutine can: called CC=2 SCAR=6.9
Pod undocumented
440 328 ▶ return $self->SUPER::can($what) || $self->driver->can($what);
Condition100%3/3
$self->SUPER::can($what) || $self->driver->can($what)
l!l&&r!l&&!r
1591168
MC/DC100%2/2
$self->SUPER::can($what) || $self->driver->can($what)
$self->SUPER::can($what) $self->driver->can($what)
Truth table100%3/3
A || B
A= $self->SUPER::can($what)B= $self->driver->can($what)
ABresult
1X1
011
000
441 }
442  
443 ####################################################################################################
444 ####################################################################################################
445  
446 sub has_action
447 {
448 0 ▶ my ($self,$otype,$oaction)=@_;
Subroutine has_action: not called CC=1 SCAR=6.9
Pod undocumented
449 0 my ($po,$to)=$self->protocol_transport();
450 0 return $po->has_action($otype,$oaction);
451 }
452  
453 sub process
454 {
455 1 ▶ my ($self,$otype,$oaction,$pa,$ta)=@_;
Subroutine process: called CC=25 SCAR=62.5
Pod undocumented
456 1 ▶ $pa=[] unless defined $pa; ## store them ?
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pa 0 1 1
457 1 ▶ $ta=[] unless defined $ta;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ta 1 0 1
458 1 $self->{last_process}=[$otype,$oaction,$pa,$ta]; ## should be handled more generally by LocalStorage/Exchange
459  
460 ## Automated switch, if enabled
461 1 $self->profile_auto_switch($otype,$oaction);
462  
463 ## Current protocol/transport objects for current profile
464 1 my ($po,$to)=$self->protocol_transport();
465 0 my $trid=$self->generate_trid();
466 0 my $ctx={trid => $trid, otype => $otype, oaction => $oaction, phase => 'active', protocol => $po };
467 0 my $tosend;
468  
469 0 my $ok=eval { $tosend=$po->action($otype,$oaction,$trid,@$pa); 1; }; ## TODO : this may need to be pushed in loop below if we need to change message to send when failure
470 0 ▶ if (! $ok)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
471 {
472 0 my $err=$@;
473 0 return $self->format_error($err);
474 }
475  
476 0 $self->{ops}->{$trid}=[0,$tosend,undef]; ## 0 = todo, not sent ## This will be done in/with LocalStorage
477 0 my $timeout=$to->timeout();
478 0 my $prevalarm=alarm(0); ## removes current alarm
479 0 my $pause=$to->pause();
480 0 my $start=Time::HiRes::time();
481 0 $self->{ops}->{$trid}->[2]=$start;
482  
483 0 my $count=0;
484 0 my $r;
485 0 ▶ while (++$count <= $to->retry())
Branch: 1 branch
BranchTrueFalseTotal
if (++$count <= $to->retry) 0 0 0
486 {
487 0 $self->log_output('debug','core',sprintf('New process loop iteration for TRID=%s with count=%d pause=%f timeout=%f',$trid,$count,$pause,$timeout));
488 0 ▶ Time::HiRes::sleep($pause) if (defined($pause) && $pause && ($count > 1));
Branch: 1 branch
BranchTrueFalseTotal
if defined $pause and $pause and $count > 1 0 0 0
Condition0%0/6
defined $pause and $pause and $count > 1
!ll&&!rl&&r
000
defined $pause and $pause
!ll&&!rl&&r
000
MC/DC0%0/3
defined $pause and $pause and $count > 1
defined $pause $pause $count > 1
Truth table0%0/4
A and B and C
A= defined $pauseB= $pauseC= $count > 1
ABCresult
0XX0
10X0
1100
1111
489 0 ▶ $self->log_output('warning','core',sprintf('Starting try #%d for TRID=%s',$count,$trid)) if $count>1;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 1 0 0 0
490 $r=eval
491 0 {
492 0 ▶ local $SIG{ALRM}=sub { die 'timeout' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
493 0 ▶ alarm($timeout) if ($timeout);
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 0 0 0
494 0 $self->log_output('debug','core',sprintf('Attempting to send data for TRID=%s',$trid));
495 0 $to->send($ctx,$tosend,$count,$ta); ## either success or exception, no result code ## TODO : and if open_connection was called inside send ???
496 0 $self->log_output('debug','core','Successfully sent data to registry for TRID='.$trid);
497 0 $self->{ops}->{$trid}->[0]=1; ## now it is sent
498 0 ▶ return $self->process_back($trid,$po,$to,$otype,$oaction,$count) if $to->is_sync();
Branch: 1 branch
BranchTrueFalseTotal
if $to->is_sync 0 0 0
499 0 my $rc=Net::DRI::Protocol::ResultStatus->new_success('COMMAND_SUCCESSFUL_PENDING');
500 0 $rc->_set_trid([ $trid ]);
501 0 $self->status($rc);
502 0 return $rc;
503 };
504 0 ▶ alarm(0) if $timeout; ## removes our alarm
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 0 0 0
505 0 ▶ if (! defined $r || ! $r) ## some die happened inside the eval (some sources say eval return undef on problem, others say empty string)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $r and $r) 0 0 0
Condition0%0/3
defined $r and $r
!ll&&!rl&&r
000
MC/DC0%0/2
defined $r and $r
defined $r $r
Truth table0%0/3
A and B
A= defined $rB= $r
ABresult
0X0
100
111
506 {
507 0 my $err=$@;
508 0 ▶ return $self->format_error($err) if (ref $err eq 'Net::DRI::Protocol::ResultStatus'); ## should probably be a return here see below TODOXXX
Branch: 1 branch
BranchTrueFalseTotal
if ref $err eq "Net::DRI::Protocol::ResultStatus" 0 0 0
509 0 ▶ my $is_timeout=(!ref $err && ($err=~m/timeout/))? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!ref($err) && $err =~ /timeout/ ? : 0 0 0
Condition0%0/3
not ref $err and $err =~ /timeout/
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $err and $err =~ /timeout/
not ref $err $err =~ /timeout/
Truth table0%0/3
not(A) and B
A= not ref $errB= $err =~ /timeout/
ABresult
0X0
100
111
510 0 ▶ $err=$is_timeout? Net::DRI::Exception->new(1,'transport',1,'timeout') : Net::DRI::Exception->new(1,'internal',0,'Error not handled: '.$err) unless ref $err;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $err 0 0 0
$is_timeout ? : 0 0 0
511 0 ▶ $self->log_output('debug','core',$is_timeout? 'Got timeout for TRID='.$trid : 'Got error for TRID='.$trid.' : '.$err->as_string());
Branch: 1 branch
BranchTrueFalseTotal
$is_timeout ? : 0 0 0
512 0 ▶ next if $to->try_again($ctx,$po,$err,$count,$is_timeout,$self->{ops}->{$trid}->[0],\$pause,\$timeout); ## will determine if 1) we break now the loop/we propagate the error (fatal error) 2) we retry
Branch: 1 branch
BranchTrueFalseTotal
if $to->try_again($ctx, $po, $err, $count, $is_timeout, $self->{"ops"}{$trid}[0], \$pause, \$timeout) 0 0 0
513 0 die $err;
514 }
515 0 ▶ last if defined $r;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 0 0 0
516 } ## end of while
517 0 ▶ if ($prevalarm) ## re-enable previous alarm
Branch: 1 branch
BranchTrueFalseTotal
if ($prevalarm) 0 0 0
518 {
519 0 $prevalarm-=Time::HiRes::time()-$start; ## try to take into account the time spent here
520 0 ▶ alarm($prevalarm) if $prevalarm > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $prevalarm > 0 0 0 0
521 }
522 0 ▶ Net::DRI::Exception->die(0,'transport',1,sprintf('Unable to communicate with registry after %d tries for a total delay of %.03f seconds',$to->retry(),Time::HiRes::time()-$start)) unless defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 0 0 0
523 0 return $r;
524 }
525  
526 sub format_error
527 {
528 0 ▶ my ($self,$err)=@_;
Subroutine format_error: not called CC=3 SCAR=24.8
Pod undocumented
529 0 ▶ if (ref($err) eq 'Net::DRI::Protocol::ResultStatus')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $err eq "Net::DRI::Protocol::ResultStatus") 0 0 0
530 {
531 0 $self->status($err); ## should that be done above also ? TODOXXX
532 0 return $err;
533 }
534 0 ▶ $err=Net::DRI::Exception->new(1,'internal',0,'Error not handled: '.$err) unless ref($err);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
535 0 die($err);
536 }
537  
538 ## also called directly , when we found something to do for asynchronous case, through TRID (TODO)
539 ## We are already in an eval here, and a while loop for retries
540 sub process_back
541 {
542 0 ▶ my ($self,$trid,$po,$to,$otype,$oaction,$count)=@_;
Subroutine process_back: not called CC=19 SCAR=59.4
Pod undocumented
543 0 my $ctx={trid => $trid, otype => $otype, oaction => $oaction, protocol => $po }; ## How will we fill that in case of async operation (direct call here) ?
544 0 my ($rc,$ri,$oname);
545  
546 0 $self->log_output('debug','core','Attempting to receive data from registry for TRID='.$trid);
547 0 my $res=$to->receive($ctx,$count); ## a Net::DRI::Data::Raw or die inside
548 0 my $stop=Time::HiRes::time();
549 0 ▶ Net::DRI::Exception->die(0,'transport',5,'Unable to receive message from registry') unless defined $res;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
550 0 $self->log_output('debug','core','Successfully received data from registry for TRID='.$trid);
551 0 $self->{ops}->{$trid}->[0]=2; ## now it is received
552 0 $self->clear_info(); ## make sure we will overwrite current latest info
553 0 $oname=_extract_oname($otype,$oaction,$self->{last_process}->[2]); ## lc() would be good here but this breaks a lot of things !
554 0 ($rc,$ri)=$po->reaction($otype,$oaction,$res,$self->{ops}->{$trid}->[1],$oname,$trid); ## $tosend needed to propagate EPP version, for example
555  
556 0 ▶ if ($rc->is_closing() || (exists $ri->{_internal} && exists $ri->{_internal}->{must_reconnect} && $ri->{_internal}->{must_reconnect}))
Branch: 1 branch
BranchTrueFalseTotal
if ($rc->is_closing or exists $ri->{"_internal"} and exists $ri->{"_internal"}{"must_reconnect"} and $ri->{"_internal"}{"must_reconnect"}) 0 0 0
Condition0%0/9
$rc->is_closing or exists $ri->{"_internal"} and exists $ri->{"_internal"}{"must_reconnect"} and $ri->{"_internal"}{"must_reconnect"}
l!l&&r!l&&!r
000
exists $ri->{"_internal"} and exists $ri->{"_internal"}{"must_reconnect"} and $ri->{"_internal"}{"must_reconnect"}
!ll&&!rl&&r
000
exists $ri->{"_internal"} and exists $ri->{"_internal"}{"must_reconnect"}
!ll&&!rl&&r
000
MC/DC0%0/4
$rc->is_closing or exists $ri->{"_internal"} and exists $ri->{"_internal"}{"must_reconnect"} and $ri->{"_internal"}{"must_reconnect"}
$rc->is_closing exists $ri->{"_internal"} exists $ri->{"_internal"}{"must_reconnect"} $ri->{"_internal"}{"must_reconnect"}
Truth table0%0/5
A or B and C and D
A= $rc->is_closingB= exists $ri->{"_internal"}C= exists $ri->{"_internal"}{"must_reconnect"}D= $ri->{"_internal"}{"must_reconnect"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
557 {
558 0 $self->log_output('notice','core','Registry closed connection, we will automatically reconnect during next exchange');
559 0 $to->current_state(0);
560 }
561 0 delete($ri->{_internal});
562  
563 ## Set latest status from what we got
564 0 $self->status($rc);
565  
566 0 $ri->{session}->{exchange}->{transport}=$to->name().'/'.$to->version();
567 0 $ri->{session}->{exchange}->{registry}=$self->name();
568 0 $ri->{session}->{exchange}->{profile}=$self->profile();
569  
570 ## set_info stores also data in last_data, so we make sure to call last for current object
571 0 foreach my $type (keys(%$ri))
572 {
573 0 foreach my $key (keys(%{$ri->{$type}}))
574 {
575 0 ▶ next if ($oname && ($type eq $otype) && ($key eq $oname));
Branch: 1 branch
BranchTrueFalseTotal
if $oname and $type eq $otype and $key eq $oname 0 0 0
Condition0%0/6
$oname and $type eq $otype and $key eq $oname
!ll&&!rl&&r
000
$oname and $type eq $otype
!ll&&!rl&&r
000
MC/DC0%0/3
$oname and $type eq $otype and $key eq $oname
$oname $type eq $otype $key eq $oname
Truth table0%0/4
A and B and C
A= $onameB= $type eq $otypeC= $key eq $oname
ABCresult
0XX0
10X0
1100
1111
576 0 $self->set_info($type,$key,$ri->{$type}->{$key});
577 }
578 }
579  
580 ## Now set the last info, the one regarding directly the object
581 0 ▶ if ($oname && $otype)
Branch: 1 branch
BranchTrueFalseTotal
if ($oname and $otype) 0 0 0
Condition0%0/3
$oname and $otype
!ll&&!rl&&r
000
MC/DC0%0/2
$oname and $otype
$oname $otype
Truth table0%0/3
A and B
A= $onameB= $otype
ABresult
0X0
100
111
582 {
583 0 my $rli={ result_status => $rc };
584 0 ▶ $rli=$ri->{$otype}->{$oname} if (exists($ri->{$otype}) && exists($ri->{$otype}->{$oname})); ## result_status already done in Protocol
Branch: 1 branch
BranchTrueFalseTotal
if exists $ri->{$otype} and exists $ri->{$otype}{$oname} 0 0 0
Condition0%0/3
exists $ri->{$otype} and exists $ri->{$otype}{$oname}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ri->{$otype} and exists $ri->{$otype}{$oname}
exists $ri->{$otype} exists $ri->{$otype}{$oname}
Truth table0%0/3
A and B
A= exists $ri->{$otype}B= exists $ri->{$otype}{$oname}
ABresult
0X0
100
111
585 0 $self->set_info($otype,$oname,$rli);
586 }
587  
588 ## Not before !
589 ## Remove all ResultStatus object, to avoid all circular references
590 0 foreach my $v1 (values(%$ri))
591 {
592 0 foreach my $v2 (values(%{$v1}))
593 {
594 0 ▶ delete($v2->{result_status}) if exists($v2->{result_status});
Branch: 1 branch
BranchTrueFalseTotal
if exists $v2->{"result_status"} 0 0 0
595 }
596 }
597  
598 ## the fact that here we copy the session/exchange branch before putting it inside the $rc object is very important
599 ## see comments above in try_restore_from_cache() for details
600 0 $ri->{session}->{exchange}={ %{$ri->{session}->{exchange}}, duration_seconds => $stop-$self->{ops}->{$trid}->[2], raw_command => $self->{ops}->{$trid}->[1]->as_string(), raw_reply => $res->as_string(), object_type => $otype, object_action => $oaction };
601 0 ▶ $ri->{session}->{exchange}->{object_name}=$oname if $oname;
Branch: 1 branch
BranchTrueFalseTotal
if $oname 0 0 0
602 0 $rc->_set_data($ri);
603 0 delete($self->{ops}->{$trid});
604 0 return $rc;
605 }
606  
607 sub _extract_oname
608 {
609 0 ▶ my ($otype,$oaction,$pa)=@_;
Subroutine _extract_oname: not called CC=9 SCAR=45.0
610  
611 0 ▶ return 'domains' if ($otype eq 'account' && $oaction eq 'list_domains');
Branch: 1 branch
BranchTrueFalseTotal
if $otype eq "account" and $oaction eq "list_domains" 0 0 0
Condition0%0/3
$otype eq "account" and $oaction eq "list_domains"
!ll&&!rl&&r
000
MC/DC0%0/2
$otype eq "account" and $oaction eq "list_domains"
$otype eq "account" $oaction eq "list_domains"
Truth table0%0/3
A and B
A= $otype eq "account"B= $oaction eq "list_domains"
ABresult
0X0
100
111
612 0 my $o=$pa->[0];
613 0 ▶ return 'session' unless defined($o);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 0 0
614 0 ▶ $o=$o->[1] if (ref($o) eq 'ARRAY'); ## should be enough for _multi but still a little strange
Branch: 1 branch
BranchTrueFalseTotal
if ref $o eq "ARRAY" 0 0 0
615 0 ▶ return (Net::DRI::Util::normalize_name($otype,$o))[1] unless ref($o); ## ?? ## TODO ## this fails t/Net/DRI/Protocol/EPP/Extensions/Nominet.t line 306
Branch: 1 branch
BranchTrueFalseTotal
unless ref $o 0 0 0
616 0 ▶ return (Net::DRI::Util::normalize_name('nsgroup',$otype eq 'nsgroup'? $o->name() : $o->get_details(1)))[1] if Net::DRI::Util::isa_hosts($o);
Branch: 2 branches
BranchTrueFalseTotal
if Net::DRI::Util::isa_hosts($o) 0 0 0
$otype eq 'nsgroup' ? : 0 0 0
617 0 ▶ return $o->srid() if Net::DRI::Util::isa_contact($o);
Branch: 1 branch
BranchTrueFalseTotal
if Net::DRI::Util::isa_contact($o) 0 0 0
618 0 return 'session';
619 }
620  
621 ####################################################################################################
622  
623 sub protocol_capable
624 {
625 0 ▶ my ($ndr,$op,$subop,$action)=@_;
Subroutine protocol_capable: not called CC=13 SCAR=52.0
Pod undocumented
626 0 ▶ return 0 unless ($op && $subop); ## $action may be undefined
Branch: 1 branch
BranchTrueFalseTotal
unless $op and $subop 0 0 0
Condition0%0/3
$op and $subop
!ll&&!rl&&r
000
MC/DC0%0/2
$op and $subop
$op $subop
Truth table0%0/3
A and B
A= $opB= $subop
ABresult
0X0
100
111
627 0 my $po=$ndr->protocol();
628 0 my $cap=$po->capabilities(); ## hashref
629  
630 return 0 unless ($cap && (ref($cap) eq 'HASH') && exists($cap->{$op})
631 && (ref($cap->{$op}) eq 'HASH') && exists($cap->{$op}->{$subop})
632 0 ▶ && (ref($cap->{$op}->{$subop}) eq 'ARRAY'));
Branch: 1 branch
BranchTrueFalseTotal
unless $cap and ref $cap eq "HASH" and exists $cap->{$op} and ref $cap->{$op} eq "HASH" and exists $cap->{$op}{$subop} and ref $cap->{$op}{$subop} eq "ARRAY" 0 0 0
Condition0%0/15
$cap and ref $cap eq "HASH" and exists $cap->{$op} and ref $cap->{$op} eq "HASH" and exists $cap->{$op}{$subop} and ref $cap->{$op}{$subop} eq "ARRAY"
!ll&&!rl&&r
000
$cap and ref $cap eq "HASH" and exists $cap->{$op} and ref $cap->{$op} eq "HASH" and exists $cap->{$op}{$subop}
!ll&&!rl&&r
000
$cap and ref $cap eq "HASH" and exists $cap->{$op} and ref $cap->{$op} eq "HASH"
!ll&&!rl&&r
000
$cap and ref $cap eq "HASH" and exists $cap->{$op}
!ll&&!rl&&r
000
$cap and ref $cap eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/6
$cap and ref $cap eq "HASH" and exists $cap->{$op} and ref $cap->{$op} eq "HASH" and exists $cap->{$op}{$subop} and ref $cap->{$op}{$subop} eq "ARRAY"
$cap ref $cap eq "HASH" exists $cap->{$op} ref $cap->{$op} eq "HASH" exists $cap->{$op}{$subop} ref $cap->{$op}{$subop} eq "ARRAY"
Truth table0%0/7
A and B and C and D and E and F
A= $capB= ref $cap eq "HASH"C= exists $cap->{$op}D= ref $cap->{$op} eq "HASH"E= exists $cap->{$op}{$subop}F= ref $cap->{$op}{$subop} eq "ARRAY"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
633  
634 0 ▶ return 1 unless (defined($action) && $action);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $action and $action 0 0 0
Condition0%0/3
defined $action and $action
!ll&&!rl&&r
000
MC/DC0%0/2
defined $action and $action
defined $action $action
Truth table0%0/3
A and B
A= defined $actionB= $action
ABresult
0X0
100
111
635  
636 0 foreach my $a (@{$cap->{$op}->{$subop}})
637 {
638 0 ▶ return 1 if ($a eq $action);
Branch: 1 branch
BranchTrueFalseTotal
if $a eq $action 0 0 0
639 }
640 0 return 0;
641 }
642  
643 sub log_output
644 {
645 79 ▶ my ($self,$level,$where,$msg)=@_;
Subroutine log_output: called CC=2 SCAR=7.0
Pod undocumented
646 79 my $r=$self->name();
647 79 ▶ $r.='.'.$self->{profile} if (defined $self->{profile});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"profile"} 0 79 79
648 79 $msg='('.$r.') '.$msg;
649 79 return $self->SUPER::log_output($level,$where,$msg);
650 }
651  
652 ####################################################################################################
653  
654 sub AUTOLOAD
655 {
656 79 ▶ my ($self,@args)=@_;
Subroutine AUTOLOAD: called CC=4 SCAR=14.2
657 79 my $attr=$AUTOLOAD;
658 79 $attr=~s/.*:://;
659 79 ▶ return unless $attr=~m/[^A-Z]/; ## skip DESTROY and all-cap methods
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /[^A-Z]/ 78 1 79
660  
661 1 my $drd=$self->driver(); ## This is a DRD object
662 1 ▶ Net::DRI::Exception::method_not_implemented($attr,$drd) unless ref $drd && $drd->can($attr);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $drd and $drd->can($attr) 0 1 1
Condition33%1/3
ref $drd and $drd->can($attr)
!ll&&!rl&&r
001
MC/DC0%0/2
ref $drd and $drd->can($attr)
ref $drd $drd->can($attr)
Truth table33%1/3
A and B
A= ref $drdB= $drd->can($attr)
ABresult
0X0
100
111
663 1 $self->log_output('debug','core',sprintf('Calling %s from Net::DRI::Registry',$attr));
664 1 return $drd->$attr($self,@args);
665 }
666  
667 ####################################################################################################
668 85 1;
« DRI/Protocol/EPP/Extensions/UnitedTLD/Charge.pm ↑ Summary DRI/Protocol/EPP/Extensions/ChangePoll.pm »