DRI/Data/ContactSet.pm

filter: Statementstmt 51.2% 80 / 156 Branchbran 36.0% 31 / 86 Conditioncond 23.0% 9 / 39 MC/DCmcdc 15.3% 4 / 26 Subroutinesub 60.0% 12 / 20 Podpod 76.9% 10 / 13 totaltotal 42.9% 146 / 340 CC 63 SCAR 38.7
CC
63
Cov
43%
has_contact
132.0
del
90.0
match
90.0
CRAP 47.8
« DRI/Protocol/EPP/Extensions/CIRA/IDN.pm ↑ Summary DRI/Protocol/OVH/WS/Domain.pm »
1 ## Domain Registry Interface, Stores ordered list of contacts + type (registrant, admin, tech, bill, etc...)
2 ##
3 ## Copyright (c) 2005-2009,2011-2014,2016 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::Data::ContactSet;
16  
17 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 82 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 82 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 82 ▶use Net::DRI::Data::Contact;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 82 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 =pod
25  
26 =head1 NAME
27  
28 Net::DRI::Data::ContactSet - Handle an ordered collection of contacts for Net::DRI
29  
30 =head1 DESCRIPTION
31  
32 This class encapsulates a set of contacts, with associated types. For each type, it can stores as many contacts as needed.
33 Contacts are compared among themselves by calling the id() method on them. Thus all Contact classes
34 must define such a method, which returns a string.
35  
36 =head1 METHODS
37  
38 =head2 new()
39  
40 creates a new object
41  
42 =head2 types()
43  
44 returns the list of current types stored in this class
45  
46 =head2 has_type()
47  
48 returns 1 if the given type as first argument has some contacts in this object, 0 otherwise
49  
50 =head2 add()
51  
52 with the first argument being a contact, and the second (optional) a type, adds the contact
53 to the list of contacts for this type or all types (if no second argument). If the contact already exists
54 (same id()), it will be replaced when found. Returns the object itself.
55  
56 =head2 del()
57  
58 the opposite of add()
59  
60 =head2 rem()
61  
62 alias for del()
63  
64 =head2 clear()
65  
66 removes all contact currently associated to all types
67  
68 =head2 set()
69  
70 with an array ref as first argument, and a type (optional) as second, set the current list
71 of the given type (or all types) to be the list of contacts in first argument. Returns the object itself.
72  
73 =head2 get()
74  
75 returns list (in list context) or first element of list (in scalar context) for the type given as argument
76  
77 =head2 get_all()
78  
79 returns list of contacts, without duplicates, for all types
80  
81 =head1 SUPPORT
82  
83 For now, support questions should be sent to:
84  
85 E<lt>netdri@dotandco.comE<gt>
86  
87 Please also see the SUPPORT file in the distribution.
88  
89 =head1 SEE ALSO
90  
91 http://www.dotandco.com/services/software/Net-DRI/
92  
93 =head1 AUTHOR
94  
95 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
96  
97 =head1 COPYRIGHT
98  
99 Copyright (c) 2005-2009,2011-2014,2016 Patrick Mevzek <netdri@dotandco.com>.
100 All rights reserved.
101  
102 This program is free software; you can redistribute it and/or modify
103 it under the terms of the GNU General Public License as published by
104 the Free Software Foundation; either version 2 of the License, or
105 (at your option) any later version.
106  
107 See the LICENSE file that comes with this distribution for more details.
108  
109 =cut
110  
111 ################################################################################################################
112  
113 82 our $AUTOLOAD;
114  
115 sub new
116 {
117 4 ▶ my ($class,@r)=@_;
Subroutine new: called CC=10 SCAR=23.3
Pod documented
118 4 my $self={ c => {} };
119 4 bless $self,$class;
120 4 ▶ if (@r)
Branch: 1 branch
BranchTrueFalseTotal
if (@r) 3 1 4
121 {
122 3 ▶ @r=%{$r[0]} if defined $r[0] && ref $r[0] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if defined $r[0] and ref $r[0] eq "HASH" 1 2 3
Condition66%2/3
defined $r[0] and ref $r[0] eq "HASH"
!ll&&!rl&&r
021
MC/DC50%1/2
defined $r[0] and ref $r[0] eq "HASH"
defined $r[0] ref $r[0] eq "HASH"
Truth table66%2/3
A and B
A= defined $r[0]B= ref $r[0] eq "HASH"
ABresult
0X0
100
111
123 3 ▶ Net::DRI::Exception::usererr_invalid_parameters('Invalid number of parameters passed') unless @r%2==0;
Branch: 1 branch
BranchTrueFalseTotal
unless @r % 2 == 0 0 3 3
124 3 ▶ while(my ($ctype,$ids)=splice(@r,0,2))
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@r, 0, 2)) 7 3 10
125 {
126 7 my %ccache;
127 7 ▶ foreach my $id (ref $ids eq 'ARRAY' ? @$ids : ($ids))
Branch: 1 branch
BranchTrueFalseTotal
ref $ids eq 'ARRAY' ? : 1 6 7
128 {
129 9 my $o;
130 9 ▶ if (Net::DRI::Util::isa_contact($id))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::isa_contact($id)) { } 0 9 9
131 {
132 0 $o=$id;
133 } else
134 {
135 9 ▶ $ccache{$id}=Net::DRI::Data::Contact->new()->srid($id) unless exists $ccache{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ccache{$id} 9 0 9
136 9 $o=$ccache{$id};
137 }
138 9 $self->add($o,$ctype);
139 }
140 }
141 }
142 4 return $self;
143 }
144  
145 sub types
146 {
147 2 ▶ my ($self)=@_;
Subroutine types: called CC=1 SCAR=0.0
Pod documented
148 2 my @r=sort { $a cmp $b } grep { @{$self->{c}->{$_}} } keys %{$self->{c}};
149 2 return @r;
150 }
151  
152 sub has_type
153 {
154 3 ▶ my ($self,$ctype)=@_;
Subroutine has_type: called CC=4 SCAR=13.9
Pod documented
155 3 ▶ return 0 unless defined $ctype;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctype 1 2 3
156 2 ▶ return exists $self->{c}->{$ctype} && @{$self->{c}->{$ctype}} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'c'}{$ctype} && @{$self->{'c'}{$ctype};} ? : 1 1 2
Condition66%2/3
exists $self->{"c"}{$ctype} and @{$self->{"c"}{$ctype};}
!ll&&!rl&&r
101
MC/DC50%1/2
exists $self->{"c"}{$ctype} and @{$self->{"c"}{$ctype};}
exists $self->{"c"}{$ctype} @{$self->{"c"}{$ctype};}
Truth table66%2/3
A and B
A= exists $self->{"c"}{$ctype}B= @{$self->{"c"}{$ctype};}
ABresult
0X0
100
111
157 }
158  
159 sub is_empty
160 {
161 0 ▶ my $self=shift;
Subroutine is_empty: not called CC=2 SCAR=17.9
Pod undocumented
162 0 my @a=$self->types();
163 0 ▶ return (@a)? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 0 0 0
164 }
165  
166 sub _pos
167 {
168 9 ▶ my ($self,$t,$id)=@_;
Subroutine _pos: called CC=4 SCAR=14.5
169 9 my $c=$self->{c};
170 9 my $l=$#{$c->{$t}};
171 9 ▶ my @p=grep { my $i=$c->{$t}->[$_]->id(); (defined($i) && ($i eq $id))? 1 : 0 } (0..$l);
Branch: 1 branch
BranchTrueFalseTotal
defined $i && $i eq $id ? : 0 3 3
Condition33%1/3
defined $i and $i eq $id
!ll&&!rl&&r
030
MC/DC0%0/2
defined $i and $i eq $id
defined $i $i eq $id
Truth table33%1/3
A and B
A= defined $iB= $i eq $id
ABresult
0X0
100
111
172 9 ▶ return $p[0] if @p;
Branch: 1 branch
BranchTrueFalseTotal
if @p 0 9 9
173 9 return;
174 }
175  
176 sub add
177 {
178 9 ▶ my ($self,$cobj,$ctype)=@_;
Subroutine add: called CC=9 SCAR=22.9
Pod documented
179 9 ▶ return unless defined($cobj);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cobj 0 9 9
180 9 my $c=$self->{c};
181 9 ▶ $c->{$ctype}=[] if (defined($ctype) && !exists($c->{$ctype}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and not exists $c->{$ctype} 7 2 9
Condition66%2/3
defined $ctype and not exists $c->{$ctype}
!ll&&!rl&&r
027
MC/DC50%1/2
defined $ctype and not exists $c->{$ctype}
defined $ctype not exists $c->{$ctype}
Truth table66%2/3
A and not(B)
A= defined $ctypeB= not exists $c->{$ctype}
ABresult
0X0
100
111
182 9 my $id=$cobj->id();
183 9 foreach my $k (sort { $a cmp $b } keys %$c)
184 {
185 15 ▶ next if (defined($ctype) && ($k ne $ctype));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and $k ne $ctype 6 9 15
Condition66%2/3
defined $ctype and $k ne $ctype
!ll&&!rl&&r
096
MC/DC50%1/2
defined $ctype and $k ne $ctype
defined $ctype $k ne $ctype
Truth table66%2/3
A and B
A= defined $ctypeB= $k ne $ctype
ABresult
0X0
100
111
186 9 ▶ if ($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 9 0 9
187 {
188 9 my $p=$self->_pos($k,$id);
189 9 ▶ if (defined($p))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p) 0 9 9
190 {
191 0 $c->{$k}->[$p]=$cobj;
192 0 next;
193 }
194 }
195 9 push @{$c->{$k}},$cobj;
196 }
197 9 return $self;
198 }
199  
200 sub del
201 {
202 0 ▶ my ($self,$cobj,$ctype)=@_;
Subroutine del: not called CC=9 SCAR=45.0
Pod documented
203 0 ▶ return unless defined($ctype);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctype 0 0 0
204 0 my $c=$self->{c};
205 0 ▶ return if (defined($ctype) && !exists($c->{$ctype}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and not exists $c->{$ctype} 0 0 0
Condition0%0/3
defined $ctype and not exists $c->{$ctype}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctype and not exists $c->{$ctype}
defined $ctype not exists $c->{$ctype}
Truth table0%0/3
A and not(B)
A= defined $ctypeB= not exists $c->{$ctype}
ABresult
0X0
100
111
206 0 my $id=$cobj->id();
207 0 ▶ return unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
208 0 foreach my $k (sort { $a cmp $b } keys %$c)
209 {
210 0 ▶ next if (defined($ctype) && ($k ne $ctype));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and $k ne $ctype 0 0 0
Condition0%0/3
defined $ctype and $k ne $ctype
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctype and $k ne $ctype
defined $ctype $k ne $ctype
Truth table0%0/3
A and B
A= defined $ctypeB= $k ne $ctype
ABresult
0X0
100
111
211 0 my $p=$self->_pos($k,$id);
212 0 ▶ next unless defined($p);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 0 0
213 0 splice(@{$c->{$k}},$p,1);
214 }
215 0 return $self;
216 }
217  
218 0 ▶sub rem { my ($self,@args)=@_; return $self->del(@args); }
Subroutine rem: not called CC=1 SCAR=6.9
Pod documented
219  
220 sub clear
221 {
222 0 ▶ my ($self,$ctype)=@_;
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
223 0 return $self->set($ctype,[]);
224 }
225  
226 sub set
227 {
228 0 ▶ my ($self,$robj,$ctype)=@_;
Subroutine set: not called CC=8 SCAR=42.8
Pod documented
229 0 ▶ return unless defined($robj);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $robj 0 0 0
230 0 my $c=$self->{c};
231 0 ▶ $c->{$ctype}=[] if (defined($ctype) && !exists($c->{$ctype}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and not exists $c->{$ctype} 0 0 0
Condition0%0/3
defined $ctype and not exists $c->{$ctype}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctype and not exists $c->{$ctype}
defined $ctype not exists $c->{$ctype}
Truth table0%0/3
A and not(B)
A= defined $ctypeB= not exists $c->{$ctype}
ABresult
0X0
100
111
232 0 foreach my $k (sort { $a cmp $b } keys %$c)
233 {
234 0 ▶ next if (defined($ctype) && ($k ne $ctype));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and $k ne $ctype 0 0 0
Condition0%0/3
defined $ctype and $k ne $ctype
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctype and $k ne $ctype
defined $ctype $k ne $ctype
Truth table0%0/3
A and B
A= defined $ctypeB= $k ne $ctype
ABresult
0X0
100
111
235 0 ▶ $c->{$k}=(ref($robj) eq 'ARRAY')? $robj : [$robj];
Branch: 1 branch
BranchTrueFalseTotal
ref $robj eq 'ARRAY' ? : 0 0 0
236 }
237 0 return $self;
238 }
239  
240 sub get
241 {
242 6 ▶ my ($self,$ctype)=@_;
Subroutine get: called CC=4 SCAR=14.0
Pod documented
243 6 ▶ return unless defined $ctype;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctype 0 6 6
244 6 my $c=$self->{c};
245 6 ▶ return unless exists $c->{$ctype};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $c->{$ctype} 0 6 6
246 6 ▶ return wantarray ? @{$c->{$ctype}} : $c->{$ctype}->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 4 6
247 }
248  
249 sub get_all
250 {
251 0 ▶ my ($self)=@_;
Subroutine get_all: not called CC=1 SCAR=6.9
Pod documented
252 0 my %r=map { $_->id() => $_ } map { @{$_} } values(%{$self->{c}});
253 0 my @r=sort { $a cmp $b } keys %r;
254 0 return map { $r{$_} } @r;
255 }
256  
257 sub match ## compare two contact lists
258 {
259 0 ▶ my ($self,$other)=@_;
Subroutine match: not called CC=9 SCAR=45.0
Pod undocumented
260 0 ▶ return 0 unless (defined($other) && (ref($other) eq ref($self)));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other and ref $other eq ref $self 0 0 0
Condition0%0/3
defined $other and ref $other eq ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $other and ref $other eq ref $self
defined $other ref $other eq ref $self
Truth table0%0/3
A and B
A= defined $otherB= ref $other eq ref $self
ABresult
0X0
100
111
261 0 my $c1=$self->{c};
262 0 my $c2=$other->{c};
263 0 ▶ return 0 unless (keys(%$c1)==keys(%$c2));
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$c1 == keys %$c2 0 0 0
264 0 ▶ return 0 if grep { ! exists($c1->{$_}) } keys(%$c2);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not exists $c1->{$_};} keys %$c2 0 0 0
265 0 ▶ return 0 if grep { ! exists($c2->{$_}) } keys(%$c1);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not exists $c2->{$_};} keys %$c1 0 0 0
266 0 foreach my $k (sort { $a cmp $b } keys %$c1)
267 {
268 0 my %tmp1=map { $_->id() => 1 } @{$c1->{$k}};
269 0 my %tmp2=map { $_->id() => 1 } @{$c2->{$k}};
270 0 ▶ return 0 if grep { ! exists($tmp2{$_}) } keys(%tmp1);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not exists $tmp2{$_};} keys %tmp1 0 0 0
271 0 ▶ return 0 if grep { ! exists($tmp1{$_}) } keys(%tmp2);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not exists $tmp1{$_};} keys %tmp2 0 0 0
272 }
273  
274 0 return 1;
275 }
276  
277 sub has_contact
278 {
279 0 ▶ my ($self,$cobj,$ctype)=@_;
Subroutine has_contact: not called CC=11 SCAR=48.8
Pod undocumented
280 0 ▶ return 0 unless defined($cobj);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cobj 0 0 0
281 0 my $c=$self->{c};
282 0 ▶ return 0 if (defined($ctype) && !exists($c->{$ctype}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and not exists $c->{$ctype} 0 0 0
Condition0%0/3
defined $ctype and not exists $c->{$ctype}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctype and not exists $c->{$ctype}
defined $ctype not exists $c->{$ctype}
Truth table0%0/3
A and not(B)
A= defined $ctypeB= not exists $c->{$ctype}
ABresult
0X0
100
111
283 0 ▶ my $id=(ref($cobj))? $cobj->id() : $cobj;
Branch: 1 branch
BranchTrueFalseTotal
ref $cobj ? : 0 0 0
284 0 ▶ return 0 unless (defined($id) && $id);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and $id 0 0 0
Condition0%0/3
defined $id and $id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $id and $id
defined $id $id
Truth table0%0/3
A and B
A= defined $idB= $id
ABresult
0X0
100
111
285 0 foreach my $k (sort { $a cmp $b } keys %$c)
286 {
287 0 ▶ next if (defined($ctype) && ($k ne $ctype));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and $k ne $ctype 0 0 0
Condition0%0/3
defined $ctype and $k ne $ctype
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctype and $k ne $ctype
defined $ctype $k ne $ctype
Truth table0%0/3
A and B
A= defined $ctypeB= $k ne $ctype
ABresult
0X0
100
111
288 0 ▶ return 1 if defined($self->_pos($k,$id));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_pos($k, $id) 0 0 0
289 }
290 0 return 0;
291 }
292  
293 sub AUTOLOAD
294 {
295 9 ▶ my $self=shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
296 9 my $attr=$AUTOLOAD;
297 9 $attr=~s/.*:://;
298 9 ▶ return unless $attr=~m/[^A-Z]/; ## skip DESTROY and all-cap methods
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /[^A-Z]/ 4 5 9
299  
300 5 my $ctype;
301 5 ▶ Net::DRI::Exception::method_not_implemented($attr,__PACKAGE__) unless ($ctype)=($attr=~m/^contact_(\S+)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctype) = $attr =~ /^contact_(\S+)$/ 0 5 5
302 5 return $self->get($ctype);
303 }
304  
305 ##############################################################################
306 82 1;
« DRI/Protocol/EPP/Extensions/CIRA/IDN.pm ↑ Summary DRI/Protocol/OVH/WS/Domain.pm »