DRI/Data/StatusList.pm

filter: Statementstmt 70.0% 63 / 90 Branchbran 60.7% 17 / 28 Conditioncond 33.3% 5 / 15 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 56.5% 13 / 23 Podpod 78.9% 15 / 19 totaltotal 61.6% 114 / 185 CC 24 SCAR 20.1
CC
24
Cov
64%
list_status
28.4
no
8.6
rem
6.0
CRAP 7.4
« DRI.pm ↑ Summary DRI/Protocol/EPP/Extensions/Afilias/MaintainerUrl.pm »
1 ## Domain Registry Interface, Handling of statuses list (order is irrelevant) (base class)
2 ##
3 ## Copyright (c) 2005-2008,2010-2011,2013-2014 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::StatusList;
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  
22 =pod
23  
24 =head1 NAME
25  
26 Net::DRI::Data::StatusList - Handle a collection of statuses for an object, in a registry independent fashion for Net::DRI
27  
28 =head1 DESCRIPTION
29  
30 You should never have to use this class directly, but you may get back objects that
31 are instances of subclasses of this class. An object of this class can store the statuses' names,
32 with a message for each and a language tag, and any other stuff, depending on registry.
33  
34 =head1 METHODS
35  
36 =head2 is_active()
37  
38 returns 1 if these statuses enable an object to be active
39  
40 =head2 is_published()
41  
42 returns 1 if these statuses enable the object to be published on registry DNS servers
43  
44 =head2 is_pending()
45  
46 returns 1 if these statuses are for an object that is pending some action at registry
47  
48 =head2 is_linked()
49  
50 returns 1 if these statuses are for an object that is linked to another one at registry
51  
52 =head2 is_grace()
53  
54 returns 1 if these statuses are for an object into some grace period at registry
55  
56 =head2 can_update()
57  
58 returns 1 if these statuses allow to update the object at registry
59  
60 =head2 can_transfer()
61  
62 returns 1 if these statuses allow to transfer the object at registry
63  
64 =head2 can_delete()
65  
66 returns 1 if these statuses allow to delete the object at registry
67  
68 =head2 can_renew()
69  
70 returns 1 if these statuses allow to renew the object at registry
71  
72 =head2 possible_no()
73  
74 returns an array with the list of available status to use in the no() call
75  
76 =head2 no()
77  
78 can be used to build a status, which will be added to the list. Must be given three parameters:
79 a status (from list given by C<possible_no()>), a message (optional), a lang (optional, default to 'en')
80  
81 =head1 INTERNAL METHODS
82  
83 You may also use the following methods, but they should be less useful as
84 the purpose of the module is to give an abstract view of the underlying statuses.
85  
86 =head2 list_status()
87  
88 to get only the statuses' names, as an array of sorted names;
89 if passed a true value, will return an array of strings, each one
90 being the status name, plus message & lang if available, plus short description
91 of other information tied to this status name
92  
93 =head2 status_details()
94  
95 to get an hash ref with all status information
96  
97 =head2 has_any()
98  
99 returns 1 if the object has any of the statuses given as arguments
100  
101 =head2 has_not()
102  
103 returns 1 if the object has none of the statuses given as arguments
104  
105 =head1 SUPPORT
106  
107 For now, support questions should be sent to:
108  
109 E<lt>netdri@dotandco.comE<gt>
110  
111 Please also see the SUPPORT file in the distribution.
112  
113 =head1 SEE ALSO
114  
115 http://www.dotandco.com/services/software/Net-DRI/
116  
117 =head1 AUTHOR
118  
119 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
120  
121 =head1 COPYRIGHT
122  
123 Copyright (c) 2005-2008,2010-2011,2013-2014 Patrick Mevzek <netdri@dotandco.com>.
124 All rights reserved.
125  
126 This program is free software; you can redistribute it and/or modify
127 it under the terms of the GNU General Public License as published by
128 the Free Software Foundation; either version 2 of the License, or
129 (at your option) any later version.
130  
131 See the LICENSE file that comes with this distribution for more details.
132  
133 =cut
134  
135 ####################################################################################################
136  
137 sub new
138 5 ▶{
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
139 5 my ($class,$pname,$pversion,@args)=@_;
140 5 ▶ $pname='?' unless defined $pname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pname 2 3 5
141 5 ▶ $pversion='?' unless defined $pversion;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pversion 2 3 5
142  
143 5 my $self={ proto_name => $pname,
144 proto_version => $pversion,
145 sl => {}, ## statusname => { lang => lc(lang), msg => '', other per class }
146 };
147  
148 5 bless($self,$class);
149 5 ▶ $self->add(@args) if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 2 3 5
150 5 return $self;
151 }
152  
153 sub _register_pno
154 1 ▶{
Subroutine _register_pno: called CC=1 SCAR=0.0
155 1 my ($self,$rs)=@_;
156 1 $self->{possible_no}=$rs;
157 1 return;
158 }
159  
160 sub add
161 5 ▶{
Subroutine add: called CC=3 SCAR=11.0
Pod undocumented
162 5 my ($self,@args)=@_;
163 5 my $rs=$self->{sl};
164  
165 5 foreach my $el (@args)
166 {
167 5 ▶ if (ref($el))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $el) { } 2 3 5
168 {
169 2 my %tmp=%{$el};
170 2 my $name=$tmp{name};
171 2 delete($tmp{name});
172 2 $rs->{$name}=\%tmp;
173 } else
174 {
175 3 $rs->{$el}={};
176 }
177 }
178 5 return $self;
179 }
180  
181 sub rem
182 0 ▶{
Subroutine rem: not called CC=2 SCAR=17.9
Pod undocumented
183 0 my ($self,$status)=@_;
184 0 my $rs=$self->{sl};
185 0 ▶ delete($rs->{$status}) if exists($rs->{$status});
Branch: 1 branch
BranchTrueFalseTotal
if exists $rs->{$status} 0 0 0
186 0 return $self;
187 }
188  
189 sub list_status
190 10 ▶{
Subroutine list_status: called CC=7 SCAR=33.5
Pod documented
191 10 my ($self,$full)=@_;
192 10 my @names=sort { $a cmp $b } keys %{$self->{sl}};
193 10 ▶ return @names if ! defined $full || ! $full;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $full and $full 10 0 10
Condition33%1/3
defined $full and $full
!ll&&!rl&&r
1000
MC/DC0%0/2
defined $full and $full
defined $full $full
Truth table33%1/3
A and B
A= defined $fullB= $full
ABresult
0X0
100
111
194  
195 0 my @r;
196 0 foreach my $name (@names)
197 {
198 0 my $r=$name;
199 0 ▶ $r.=sprintf(' (%s:%s)',$self->{sl}->{$name}->{lang},$self->{sl}->{$name}->{msg}) if exists $self->{sl}->{$name}->{lang} && $self->{sl}->{$name}->{msg};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"sl"}{$name}{"lang"} and $self->{"sl"}{$name}{"msg"} 0 0 0
Condition0%0/3
exists $self->{"sl"}{$name}{"lang"} and $self->{"sl"}{$name}{"msg"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"sl"}{$name}{"lang"} and $self->{"sl"}{$name}{"msg"}
exists $self->{"sl"}{$name}{"lang"} $self->{"sl"}{$name}{"msg"}
Truth table0%0/3
A and B
A= exists $self->{"sl"}{$name}{"lang"}B= $self->{"sl"}{$name}{"msg"}
ABresult
0X0
100
111
200 0 my @ek=sort { $a cmp $b } grep { ! /^(?:lang|msg)$/ } keys %{$self->{sl}->{$name}};
201 0 ▶ $r.=join('',map { '['.$_.']' } @ek) if @ek;
Branch: 1 branch
BranchTrueFalseTotal
if @ek 0 0 0
202 0 push @r,$r;
203 }
204 0 return @r;
205 }
206  
207 sub status_details
208 1 ▶{
Subroutine status_details: called CC=1 SCAR=0.0
Pod documented
209 1 my $self=shift;
210 1 return $self->{sl};
211 }
212  
213 sub is_empty
214 4 ▶{
Subroutine is_empty: called CC=2 SCAR=6.9
Pod undocumented
215 4 my $self=shift;
216 4 my @a=$self->list_status();
217 4 ▶ return (@a > 0)? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@a > 0 ? : 2 2 4
218 }
219  
220 sub has_any
221 1 ▶{
Subroutine has_any: called CC=3 SCAR=11.4
Pod documented
222 1 my ($self,@args)=@_;
223 1 my %tmp=map { uc($_) => 1 } $self->list_status();
224  
225 1 foreach my $el (@args)
226 {
227 1 ▶ return 1 if exists($tmp{uc($el)});
Branch: 1 branch
BranchTrueFalseTotal
if exists $tmp{uc $el} 1 0 1
228 }
229 0 return 0;
230 }
231  
232 sub has_not
233 1 ▶{
Subroutine has_not: called CC=3 SCAR=11.4
Pod documented
234 1 my ($self,@args)=@_;
235 1 my %tmp=map { uc($_) => 1 } $self->list_status();
236  
237 1 foreach my $el (@args)
238 {
239 1 ▶ return 0 if exists($tmp{uc($el)});
Branch: 1 branch
BranchTrueFalseTotal
if exists $tmp{uc $el} 1 0 1
240 }
241 0 return 1;
242 }
243  
244 sub possible_no
245 1 ▶{
Subroutine possible_no: called CC=1 SCAR=0.0
Pod documented
246 1 my $self=shift;
247 1 my @r=sort { $a cmp $b } keys %{$self->{possible_no}};
248 1 return @r;
249 }
250  
251 sub no ## no critic (Subroutines::ProhibitBuiltinHomonyms)
252 2 ▶{
Subroutine no: called CC=7 SCAR=21.5
Pod documented
253 2 my ($self,$what,$msg,$lang)=@_;
254 2 my $rs=$self->{possible_no};
255 2 ▶ return $self unless (defined($what) && exists($rs->{$what}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what and exists $rs->{$what} 0 2 2
Condition33%1/3
defined $what and exists $rs->{$what}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $what and exists $rs->{$what}
defined $what exists $rs->{$what}
Truth table33%1/3
A and B
A= defined $whatB= exists $rs->{$what}
ABresult
0X0
100
111
256 2 ▶ if (defined($msg) && $msg)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $msg and $msg) { } 1 1 2
Condition66%2/3
defined $msg and $msg
!ll&&!rl&&r
101
MC/DC50%1/2
defined $msg and $msg
defined $msg $msg
Truth table66%2/3
A and B
A= defined $msgB= $msg
ABresult
0X0
100
111
257 {
258 1 ▶ $self->add({name=>$rs->{$what},msg=>$msg,lang=>(defined($lang) && $lang)? $lang : 'en'});
Branch: 1 branch
BranchTrueFalseTotal
defined $lang && $lang ? : 1 0 1
Condition33%1/3
defined $lang and $lang
!ll&&!rl&&r
001
MC/DC0%0/2
defined $lang and $lang
defined $lang $lang
Truth table33%1/3
A and B
A= defined $langB= $lang
ABresult
0X0
100
111
259 } else
260 {
261 1 $self->add($rs->{$what});
262 }
263 2 return $self;
264 }
265  
266 ####################################################################################################
267 ## Methods that must be defined in subclasses
268  
269 0 ▶sub is_active { Net::DRI::Exception::method_not_implemented('is_active',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine is_active: not called CC=1 SCAR=6.9
Pod documented
270 0 ▶sub is_published { Net::DRI::Exception::method_not_implemented('is_published',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine is_published: not called CC=1 SCAR=6.9
Pod documented
271 0 ▶sub is_pending { Net::DRI::Exception::method_not_implemented('is_pending',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine is_pending: not called CC=1 SCAR=6.9
Pod documented
272 0 ▶sub is_linked { Net::DRI::Exception::method_not_implemented('is_linked',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine is_linked: not called CC=1 SCAR=6.9
Pod documented
273 0 ▶sub is_grace { Net::DRI::Exception::method_not_implemented('is_grace',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine is_grace: not called CC=1 SCAR=6.9
Pod documented
274 0 ▶sub can_update { Net::DRI::Exception::method_not_implemented('can_update',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine can_update: not called CC=1 SCAR=6.9
Pod documented
275 0 ▶sub can_transfer { Net::DRI::Exception::method_not_implemented('can_transfer',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine can_transfer: not called CC=1 SCAR=6.9
Pod documented
276 0 ▶sub can_delete { Net::DRI::Exception::method_not_implemented('can_delete',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine can_delete: not called CC=1 SCAR=6.9
Pod documented
277 0 ▶sub can_renew { Net::DRI::Exception::method_not_implemented('can_renew',ref $_[0]); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn)
Subroutine can_renew: not called CC=1 SCAR=6.9
Pod documented
278  
279 ####################################################################################################
280 81 1;
« DRI.pm ↑ Summary DRI/Protocol/EPP/Extensions/Afilias/MaintainerUrl.pm »