| 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 | 81 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 81 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 81 | ▶ | use Net::DRI::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 81 | ▶ | use Net::DRI::Data::Contact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 81 | ▶ | 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 | 81 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | sub new | ||||||||||||||||||||||||||||
| 116 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 4 | my ($class,@r)=@_; | |||||||||||||||||||||||||||
| 118 | 4 | my $self={ c => {} }; | |||||||||||||||||||||||||||
| 119 | 4 | bless $self,$class; | |||||||||||||||||||||||||||
| 120 | 4 | ▶ | if (@r) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||
| 122 | 3 | ▶ | @r=%{$r[0]} if defined $r[0] && ref $r[0] eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $r[0] and ref $r[0] eq "HASH"
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"
| |||||||||||||||||||||||||||||
| 123 | 3 | ▶ | Net::DRI::Exception::usererr_invalid_parameters('Invalid number of parameters passed') unless @r%2==0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 3 | ▶ | while(my ($ctype,$ids)=splice(@r,0,2)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 7 | my %ccache; | |||||||||||||||||||||||||||
| 127 | 7 | ▶ | foreach my $id (ref $ids eq 'ARRAY' ? @$ids : ($ids)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||
| 129 | 9 | my $o; | |||||||||||||||||||||||||||
| 130 | 9 | ▶ | if (Net::DRI::Util::isa_contact($id)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 2 | my ($self)=@_; | |||||||||||||||||||||||||||
| 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 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
has_type: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 3 | my ($self,$ctype)=@_; | |||||||||||||||||||||||||||
| 155 | 3 | ▶ | return 0 unless defined $ctype; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 2 | ▶ | return exists $self->{c}->{$ctype} && @{$self->{c}->{$ctype}} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->{"c"}{$ctype} and @{$self->{"c"}{$ctype};}
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};}
| |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | sub is_empty | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_empty: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 161 | 0 | my $self=shift; | |||||||||||||||||||||||||||
| 162 | 0 | my @a=$self->types(); | |||||||||||||||||||||||||||
| 163 | 0 | ▶ | return (@a)? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | sub _pos | ||||||||||||||||||||||||||||
| 167 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_pos: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 168 | 9 | my ($self,$t,$id)=@_; | |||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $i and $i eq $id
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
| |||||||||||||||||||||||||||||
| 172 | 9 | ▶ | return $p[0] if @p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 9 | return; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | sub add | ||||||||||||||||||||||||||||
| 177 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=9 SCAR=22.9
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 9 | my ($self,$cobj,$ctype)=@_; | |||||||||||||||||||||||||||
| 179 | 9 | ▶ | return unless defined($cobj); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 9 | my $c=$self->{c}; | |||||||||||||||||||||||||||
| 181 | 9 | ▶ | $c->{$ctype}=[] if (defined($ctype) && !exists($c->{$ctype})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ctype and not exists $c->{$ctype}
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}
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $ctype and $k ne $ctype
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
| |||||||||||||||||||||||||||||
| 186 | 9 | ▶ | if ($id) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||
| 188 | 9 | my $p=$self->_pos($k,$id); | |||||||||||||||||||||||||||
| 189 | 9 | ▶ | if (defined($p)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
del: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 0 | my ($self,$cobj,$ctype)=@_; | |||||||||||||||||||||||||||
| 203 | 0 | ▶ | return unless defined($ctype); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | my $c=$self->{c}; | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | return if (defined($ctype) && !exists($c->{$ctype})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ctype and not exists $c->{$ctype}
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}
| |||||||||||||||||||||||||||||
| 206 | 0 | my $id=$cobj->id(); | |||||||||||||||||||||||||||
| 207 | 0 | ▶ | return unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | foreach my $k (sort { $a cmp $b } keys %$c) | |||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | next if (defined($ctype) && ($k ne $ctype)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ctype and $k ne $ctype
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
| |||||||||||||||||||||||||||||
| 211 | 0 | my $p=$self->_pos($k,$id); | |||||||||||||||||||||||||||
| 212 | 0 | ▶ | next unless defined($p); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 222 | 0 | my ($self,$ctype)=@_; | |||||||||||||||||||||||||||
| 223 | 0 | return $self->set($ctype,[]); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | sub set | ||||||||||||||||||||||||||||
| 227 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | 0 | my ($self,$robj,$ctype)=@_; | |||||||||||||||||||||||||||
| 229 | 0 | ▶ | return unless defined($robj); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | my $c=$self->{c}; | |||||||||||||||||||||||||||
| 231 | 0 | ▶ | $c->{$ctype}=[] if (defined($ctype) && !exists($c->{$ctype})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ctype and not exists $c->{$ctype}
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}
| |||||||||||||||||||||||||||||
| 232 | 0 | foreach my $k (sort { $a cmp $b } keys %$c) | |||||||||||||||||||||||||||
| 233 | { | ||||||||||||||||||||||||||||
| 234 | 0 | ▶ | next if (defined($ctype) && ($k ne $ctype)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ctype and $k ne $ctype
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
| |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $c->{$k}=(ref($robj) eq 'ARRAY')? $robj : [$robj]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | 0 | return $self; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | sub get | ||||||||||||||||||||||||||||
| 241 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 242 | 6 | my ($self,$ctype)=@_; | |||||||||||||||||||||||||||
| 243 | 6 | ▶ | return unless defined $ctype; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 6 | my $c=$self->{c}; | |||||||||||||||||||||||||||
| 245 | 6 | ▶ | return unless exists $c->{$ctype}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 6 | ▶ | return wantarray ? @{$c->{$ctype}} : $c->{$ctype}->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | sub get_all | ||||||||||||||||||||||||||||
| 250 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_all: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 251 | 0 | my ($self)=@_; | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
match: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 259 | 0 | my ($self,$other)=@_; | |||||||||||||||||||||||||||
| 260 | 0 | ▶ | return 0 unless (defined($other) && (ref($other) eq ref($self))); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $other and ref $other eq ref $self
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
| |||||||||||||||||||||||||||||
| 261 | 0 | my $c1=$self->{c}; | |||||||||||||||||||||||||||
| 262 | 0 | my $c2=$other->{c}; | |||||||||||||||||||||||||||
| 263 | 0 | ▶ | return 0 unless (keys(%$c1)==keys(%$c2)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | return 0 if grep { ! exists($c1->{$_}) } keys(%$c2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | ▶ | return 0 if grep { ! exists($c2->{$_}) } keys(%$c1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | return 0 if grep { ! exists($tmp1{$_}) } keys(%tmp2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | return 1; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | sub has_contact | ||||||||||||||||||||||||||||
| 278 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
has_contact: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 279 | 0 | my ($self,$cobj,$ctype)=@_; | |||||||||||||||||||||||||||
| 280 | 0 | ▶ | return 0 unless defined($cobj); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | 0 | my $c=$self->{c}; | |||||||||||||||||||||||||||
| 282 | 0 | ▶ | return 0 if (defined($ctype) && !exists($c->{$ctype})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ctype and not exists $c->{$ctype}
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}
| |||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my $id=(ref($cobj))? $cobj->id() : $cobj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 0 | ▶ | return 0 unless (defined($id) && $id); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $id and $id
MC/DC0%0/2
defined $id and $id
defined $id
$id
Truth table0%0/3
A and B
A= defined $idB= $id
| |||||||||||||||||||||||||||||
| 285 | 0 | foreach my $k (sort { $a cmp $b } keys %$c) | |||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||
| 287 | 0 | ▶ | next if (defined($ctype) && ($k ne $ctype)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ctype and $k ne $ctype
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
| |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return 1 if defined($self->_pos($k,$id)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | 0 | return 0; | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 294 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 295 | 9 | my $self=shift; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 5 | my $ctype; | |||||||||||||||||||||||||||
| 301 | 5 | ▶ | Net::DRI::Exception::method_not_implemented($attr,__PACKAGE__) unless ($ctype)=($attr=~m/^contact_(\S+)$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | 5 | return $self->get($ctype); | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | ############################################################################## | ||||||||||||||||||||||||||||
| 306 | 81 | 1; | |||||||||||||||||||||||||||