Object/MakeMethods/Generic.pm

filter: Statementstmt 86.3% 222 / 257 Branchbran 72.2% 185 / 256 Conditioncond 63.8% 46 / 72 MC/DCmcdc 39.5% 17 / 43 Subroutinesub 94.4% 34 / 36 Podpod 100% 4 / 4 totaltotal 76.0% 508 / 668 CC 154 SCAR 24.4
CC
154
Cov
77%
__ANON__
42.0
hash
22.7
__ANON__
20.8
CRAP 11.5
« Object/MakeMethods.pm ↑ Summary Object.pm »
1 package Rose::Object::MakeMethods::Generic;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '0.859';
8  
9 4 ▶use Rose::Object::MakeMethods;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 our @ISA = qw(Rose::Object::MakeMethods);
11  
12 4 our $Have_CXSA;
13  
14 TRY:
15 {
16 4 local $@;
17  
18 eval
19 4 {
20 4 require Class::XSAccessor;
21  
22 4 (my $version = $Class::XSAccessor::VERSION) =~ s/_//g;
23  
24 4 ▶ unless($version >= 0.14)
Branch: 1 branch
BranchTrueFalseTotal
unless ($version >= "0.14") 0 4 4
25 {
26 0 die "Class::XSAccessor $Class::XSAccessor::VERSION is too old";
27 }
28 };
29  
30 4 ▶ $Have_CXSA = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 4 4
31 }
32  
33 4 our $Debug = 0;
34  
35 sub scalar
36 8 ▶{
Subroutine scalar: called CC=8 SCAR=21.2
Pod documented
37 8 my($class, $name, $args) = @_;
38  
39 8 my %methods;
40  
41 8 ▶ my $key = $args->{'hash_key'} || $name;
Condition33%1/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
080
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table33%1/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
42 8 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition100%2/2
$args->{'interface'} || 'get_set'
l!l
26
MC/DC100%1/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table100%2/2
A
A= $args->{'interface'}
Aresult
11
00
43  
44 8 ▶ if($interface eq 'get_set_init')
Branch: 2 branches
BranchTrueFalseTotal
if ($interface eq 'get_set_init') { } 2 6 8
elsif ($interface eq 'get_set') { } 6 0 6
45 {
46 2 ▶ my $init_method = $args->{'init_method'} || "init_$name";
Condition50%1/2
$args->{'init_method'} || "init_$name"
l!l
02
MC/DC0%0/1
$args->{'init_method'} || "init_$name"
$args->{'init_method'}
Truth table50%1/2
A
A= $args->{'init_method'}
Aresult
11
00
47  
48 $methods{$name} = sub
49 6 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
50 6 ▶ return $_[0]->{$key} = $_[1] if(@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 2 4 6
51  
52 return defined $_[0]->{$key} ? $_[0]->{$key} :
53 4 ▶ ($_[0]->{$key} = $_[0]->$init_method());
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$key} ? : 2 2 4
54 }
55 2 }
56 elsif($interface eq 'get_set')
57 {
58 6 ▶ if($Have_CXSA && !$ENV{'ROSE_OBJECT_NO_CLASS_XSACCESOR'})
Branch: 1 branch
BranchTrueFalseTotal
if ($Rose::Object::MakeMethods::Generic::Have_CXSA and not $ENV{'ROSE_OBJECT_NO_CLASS_XSACCESOR'}) { } 5 1 6
Condition66%2/3
$Rose::Object::MakeMethods::Generic::Have_CXSA and not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
!ll&&!rl&&r
015
MC/DC50%1/2
$Rose::Object::MakeMethods::Generic::Have_CXSA and not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
$Rose::Object::MakeMethods::Generic::Have_CXSA not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
Truth table66%2/3
A and not(B)
A= $Rose::Object::MakeMethods::Generic::Have_CXSAB= not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
ABresult
0X0
100
111
59 {
60 $methods{$name} =
61 {
62 make_method => sub
63 4 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.7
64 4 my($name, $target_class, $options) = @_;
65  
66 4 ▶ $Debug && warn "Class::XSAccessor make method ($name => $key) in $target_class\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::Object::MakeMethods::Generic::Debug and warn "Class::XSAccessor make method ($name => $key) in $target_class\n" 0 4 4
67  
68 Class::XSAccessor->import(
69 accessors => { $name => $key },
70 class => $target_class,
71 4 ▶ replace => $options->{'override_existing'} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$options->{'override_existing'} ? : 0 4 4
72 },
73 5 };
74 }
75 else
76 {
77 $methods{$name} = sub
78 3 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
79 3 ▶ return $_[0]->{$key} = $_[1] if(@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 1 2 3
80 2 return $_[0]->{$key};
81 }
82 1 }
83 }
84 0 else { Carp::croak "Unknown interface: $interface" }
85  
86 8 return \%methods;
87 }
88  
89 sub boolean
90 8 ▶{
Subroutine boolean: called CC=8 SCAR=21.9
Pod documented
91 8 my($class, $name, $args) = @_;
92  
93 8 my %methods;
94  
95 8 ▶ my $key = $args->{'hash_key'} || $name;
Condition33%1/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
080
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table33%1/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
96 8 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition100%2/2
$args->{'interface'} || 'get_set'
l!l
26
MC/DC100%1/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table100%2/2
A
A= $args->{'interface'}
Aresult
11
00
97  
98 8 ▶ if($interface eq 'get_set_init')
Branch: 2 branches
BranchTrueFalseTotal
if ($interface eq 'get_set_init') { } 2 6 8
elsif ($interface eq 'get_set') { } 6 0 6
99 {
100 2 ▶ my $init_method = $args->{'init_method'} || "init_$name";
Condition50%1/2
$args->{'init_method'} || "init_$name"
l!l
02
MC/DC0%0/1
$args->{'init_method'} || "init_$name"
$args->{'init_method'}
Truth table50%1/2
A
A= $args->{'init_method'}
Aresult
11
00
101  
102 $methods{$name} = sub
103 6 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.5
104 6 ▶ return $_[0]->{$key} = $_[1] ? 1 : 0 if(@_ > 1);
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 2 4 6
$_[1] ? : 0 2 2
105  
106 return defined $_[0]->{$key} ? $_[0]->{$key} :
107 4 ▶ ($_[0]->{$key} = $_[0]->$init_method() ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
defined $_[0]{$key} ? : 2 2 4
$_[0]->$init_method ? : 2 0 2
108 }
109 2 }
110 elsif($interface eq 'get_set')
111 {
112 6 ▶ if(exists $args->{'default'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{'default'}) { } 4 2 6
113 {
114 4 ▶ if($args->{'default'})
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'default'}) { } 2 2 4
115 {
116 $methods{$name} = sub
117 2 ▶ {
Subroutine __ANON__: called CC=4 SCAR=17.9
118 2 ▶ return $_[0]->{$key} = $_[1] ? 1 : 0 if(@_ > 1);
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 0 2 2
$_[1] ? : 0 0 0
119 2 ▶ return defined $_[0]->{$key} ? $_[0]->{$key} : ($_[0]->{$key} = 1)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$key} ? : 0 2 2
120 }
121 2 }
122 else
123 {
124 $methods{$name} = sub
125 2 ▶ {
Subroutine __ANON__: called CC=4 SCAR=17.9
126 2 ▶ return $_[0]->{$key} = $_[1] ? 1 : 0 if(@_ > 1);
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 0 2 2
$_[1] ? : 0 0 0
127 2 ▶ return defined $_[0]->{$key} ? $_[0]->{$key} : ($_[0]->{$key} = 0)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$key} ? : 0 2 2
128 }
129 2 }
130 }
131 else
132 {
133 $methods{$name} = sub
134 12 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
135 12 ▶ return $_[0]->{$key} = $_[1] ? 1 : 0 if(@_ > 1);
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 6 6 12
$_[1] ? : 2 4 6
136 6 return $_[0]->{$key};
137 }
138 2 }
139 }
140 0 else { Carp::croak "Unknown interface: $interface" }
141  
142 8 return \%methods;
143 }
144  
145 sub hash
146 30 ▶{
Subroutine hash: called CC=18 SCAR=31.2
Pod documented
147 30 my($class, $name, $args) = @_;
148  
149 30 my %methods;
150  
151 30 ▶ my $key = $args->{'hash_key'} || $name;
Condition66%2/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
2280
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table66%2/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
152 30 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition100%2/2
$args->{'interface'} || 'get_set'
l!l
282
MC/DC100%1/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table100%2/2
A
A= $args->{'interface'}
Aresult
11
00
153  
154 30 ▶ if($interface eq 'get_set_init')
Branch: 11 branches
BranchTrueFalseTotal
if ($interface eq 'get_set_init') { } 2 28 30
elsif ($interface eq 'get_set_inited') { } 2 26 28
elsif ($interface eq 'get_set_all') { } 2 24 26
elsif ($interface eq 'get_set_init_all') { } 2 22 24
elsif ($interface eq 'clear') { } 6 16 22
elsif ($interface eq 'reset') { } 6 10 16
elsif ($interface eq 'delete') { } 2 8 10
elsif ($interface eq 'exists') { } 2 6 8
elsif ($interface =~ /^(?:keys|names)$/) { } 2 4 6
elsif ($interface eq 'values') { } 2 2 4
elsif ($interface eq 'get_set') { } 2 0 2
155 {
156 2 ▶ my $init_method = $args->{'init_method'} || "init_$name";
Condition50%1/2
$args->{'init_method'} || "init_$name"
l!l
02
MC/DC0%0/1
$args->{'init_method'} || "init_$name"
$args->{'init_method'}
Truth table50%1/2
A
A= $args->{'init_method'}
Aresult
11
00
157  
158 $methods{$name} = sub
159 16 ▶ {
Subroutine __ANON__: called CC=12 SCAR=25.4
160 16 my($self) = shift;
161  
162 # If called with no arguments, return hash contents
163 16 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 10 6 16
164 {
165 10 ▶ $self->{$key} = $self->$init_method() unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 4 6 10
166 10 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 4 10
167 }
168  
169 # If called with a hash ref, set value
170 6 ▶ if(@_ == 1 && ref $_[0] eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 2 4 6
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
222
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
171 {
172 2 $self->{$key} = $_[0];
173 }
174 else
175 {
176 # If called with an index, get that value, or a slice for array refs
177 4 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 2 2 4
178 {
179 # Initialize hash if undefined
180 2 ▶ $self->{$key} = $self->$init_method() unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 2 0 2
181  
182 0 return ref $_[0] eq 'ARRAY' ? @{$self->{$key}}{@{$_[0]}} :
183 2 ▶ $self->{$key}{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 2 2
184 }
185  
186 # Push on new values and return complete set
187 2 ▶ Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
188  
189 2 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 2 6
190 {
191 4 local $_ = shift;
192 4 $self->{$key}{$_} = shift;
193 }
194 }
195  
196 0 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
197 }
198 2 }
199 elsif($interface eq 'get_set_inited')
200 {
201 $methods{$name} = sub
202 12 ▶ {
Subroutine __ANON__: called CC=11 SCAR=25.8
203 12 my($self) = shift;
204  
205 # If called with no arguments, return hash contents
206 12 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 8 4 12
207 {
208 8 ▶ $self->{$key} = {} unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 2 6 8
209 8 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 4 8
210 }
211  
212 # If called with a hash ref, set value
213 4 ▶ if(@_ == 1 && ref $_[0] eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 2 2 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
202
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
214 {
215 2 $self->{$key} = $_[0];
216 }
217 else
218 {
219 # If called with an index, get that value, or a slice for array refs
220 2 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 2 2
221 {
222 0 return ref $_[0] eq 'ARRAY' ? @{$self->{$key}}{@{$_[0]}} :
223 0 ▶ $self->{$key}{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
224 }
225  
226 # Push on new values and return complete set
227 2 ▶ Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
228  
229 2 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 2 6
230 {
231 4 local $_ = shift;
232 4 $self->{$key}{$_} = shift;
233 }
234 }
235  
236 0 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
237 }
238 2 }
239 elsif($interface eq 'get_set_all')
240 {
241 $methods{$name} = sub
242 10 ▶ {
Subroutine __ANON__: called CC=8 SCAR=21.1
243 10 my($self) = shift;
244  
245 # If called with no arguments, return hash contents
246 10 ▶ return wantarray ? %{$self->{$key}} : $self->{$key} unless(@_);
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 6 4 10
wantarray ? : 2 4 6
247  
248 # Set hash to arguments
249 4 ▶ if(@_ == 1 && ref $_[0] eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 2 2 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
202
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
250 {
251 2 $self->{$key} = $_[0];
252 }
253 else
254 {
255 # Push on new values and return complete set
256 2 ▶ Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
257  
258 2 $self->{$key} = {};
259  
260 2 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 2 6
261 {
262 4 local $_ = shift;
263 4 $self->{$key}{$_} = shift;
264 }
265 }
266  
267 0 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
268 }
269 2 }
270 elsif($interface eq 'get_set_init_all')
271 {
272 2 ▶ my $init_method = $args->{'init_method'} || "init_$name";
Condition50%1/2
$args->{'init_method'} || "init_$name"
l!l
02
MC/DC0%0/1
$args->{'init_method'} || "init_$name"
$args->{'init_method'}
Truth table50%1/2
A
A= $args->{'init_method'}
Aresult
11
00
273  
274 $methods{$name} = sub
275 16 ▶ {
Subroutine __ANON__: called CC=11 SCAR=25.0
276 16 my($self) = shift;
277  
278 # If called with no arguments, return hash contents
279 16 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 12 4 16
280 {
281 12 ▶ $self->{$key} = $self->$init_method() unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 2 10 12
282 12 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 6 12
283 }
284  
285 # If called with no arguments, return hash contents
286 0 ▶ return wantarray ? %{$self->{$key}} : $self->{$key} unless(@_);
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 0 4 4
wantarray ? : 0 0 0
287  
288 # Set hash to arguments
289 4 ▶ if(@_ == 1 && ref $_[0] eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 2 2 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
202
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
290 {
291 2 $self->{$key} = $_[0];
292 }
293 else
294 {
295 # Push on new values and return complete set
296 2 ▶ Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
297  
298 2 $self->{$key} = {};
299  
300 2 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 2 6
301 {
302 4 local $_ = shift;
303 4 $self->{$key}{$_} = shift;
304 }
305 }
306  
307 0 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
308 }
309 2 }
310 elsif($interface eq 'clear')
311 {
312 $methods{$name} = sub
313 4 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
314 4 $_[0]->{$key} = {}
315 }
316 6 }
317 elsif($interface eq 'reset')
318 {
319 $methods{$name} = sub
320 2 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
321 2 $_[0]->{$key} = undef;
322 }
323 6 }
324 elsif($interface eq 'delete')
325 {
326 $methods{($interface eq 'manip' ? 'delete_' : '') . $name} = sub
327 2 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.1
328 2 ▶ Carp::croak "Missing key(s) to delete" unless(@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 0 2 2
329  
330 2 delete @{shift->{$key}}{@_};
331 }
332 2 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$interface eq 'manip' ? : 0 2 2
333 elsif($interface eq 'exists')
334 {
335 $methods{$name . ($interface eq 'manip' ? '_exists' : '')} = sub
336 2 ▶ {
Subroutine __ANON__: called CC=3 SCAR=12.0
337 2 ▶ Carp::croak "Missing key argument" unless(@_ == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 2 2
338 2 ▶ defined $_[0]->{$key} ? exists $_[0]->{$key}{$_[1]} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$key} ? : 2 0 2
339 }
340 2 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$interface eq 'manip' ? : 0 2 2
341 elsif($interface =~ /^(?:keys|names)$/)
342 {
343 $methods{$name} = sub
344 4 ▶ {
Subroutine __ANON__: called CC=4 SCAR=19.1
345 4 ▶ wantarray ? (defined $_[0]->{$key} ? keys %{$_[0]->{$key}} : ()) :
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$key} ? : 0 0 0
346 0 ▶ (defined $_[0]->{$key} ? [ keys %{$_[0]->{$key}} ] : []);
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 4 0 4
defined $_[0]{$key} ? : 4 0 4
347 }
348 2 }
349 elsif($interface eq 'values')
350 {
351 $methods{$name} = sub
352 4 ▶ {
Subroutine __ANON__: called CC=4 SCAR=19.1
353 4 ▶ wantarray ? (defined $_[0]->{$key} ? values %{$_[0]->{$key}} : ()) :
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$key} ? : 0 0 0
354 0 ▶ (defined $_[0]->{$key} ? [ values %{$_[0]->{$key}} ] : []);
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 4 0 4
defined $_[0]{$key} ? : 4 0 4
355 }
356 2 }
357 elsif($interface eq 'get_set')
358 {
359 $methods{$name} = sub
360 4 ▶ {
Subroutine __ANON__: called CC=11 SCAR=30.3
361 4 my($self) = shift;
362  
363 # If called with no arguments, return hash contents
364 4 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 4 4
365 {
366 0 ▶ return wantarray ? (defined $self->{$key} ? %{$self->{$key}} : ()) : $self->{$key}
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
defined $self->{$key} ? : 0 0 0
367 }
368  
369 # If called with a hash ref, set value
370 4 ▶ if(@_ == 1 && ref $_[0] eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 4 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
220
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
371 {
372 0 $self->{$key} = $_[0];
373 }
374 else
375 {
376 # If called with an index, get that value, or a slice for array refs
377 4 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 2 2 4
378 {
379 0 return ref $_[0] eq 'ARRAY' ? @{$self->{$key}}{@{$_[0]}} :
380 2 ▶ $self->{$key}{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 2 2
381 }
382  
383 # Push on new values and return complete set
384 2 ▶ Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
385  
386 2 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 2 6
387 {
388 4 local $_ = shift;
389 4 $self->{$key}{$_} = shift;
390 }
391 }
392  
393 0 ▶ return wantarray ? %{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
394 2 };
395 }
396 0 else { Carp::croak "Unknown interface: $interface" }
397  
398 30 return \%methods;
399 }
400  
401 sub array
402 18 ▶{
Subroutine array: called CC=15 SCAR=28.5
Pod documented
403 18 my($class, $name, $args) = @_;
404  
405 18 my %methods;
406  
407 18 ▶ my $key = $args->{'hash_key'} || $name;
Condition66%2/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
1260
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table66%2/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
408 18 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition100%2/2
$args->{'interface'} || 'get_set'
l!l
162
MC/DC100%1/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table100%2/2
A
A= $args->{'interface'}
Aresult
11
00
409  
410 18 ▶ if($interface eq 'get_set_init')
Branch: 10 branches
BranchTrueFalseTotal
if ($interface eq 'get_set_init') { } 2 16 18
elsif ($interface eq 'get_set_inited') { } 2 14 16
elsif ($interface eq 'get_set_item') { } 2 12 14
elsif ($interface eq 'unshift') { } 2 10 12
elsif ($interface eq 'shift') { } 2 8 10
elsif ($interface eq 'clear') { } 2 6 8
elsif ($interface eq 'reset') { } 0 6 6
elsif ($interface =~ /^(?:push|add)$/) { } 2 4 6
elsif ($interface eq 'pop') { } 2 2 4
elsif ($interface eq 'get_set') { } 2 0 2
411 {
412 2 ▶ my $init_method = $args->{'init_method'} || "init_$name";
Condition50%1/2
$args->{'init_method'} || "init_$name"
l!l
02
MC/DC0%0/1
$args->{'init_method'} || "init_$name"
$args->{'init_method'}
Truth table50%1/2
A
A= $args->{'init_method'}
Aresult
11
00
413  
414 $methods{$name} = sub
415 12 ▶ {
Subroutine __ANON__: called CC=7 SCAR=19.6
416 12 my($self) = shift;
417  
418 # If called with no arguments, return array contents
419 12 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 8 4 12
420 {
421 8 ▶ $self->{$key} = $self->$init_method() unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 2 6 8
422 8 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 2 8
423 }
424  
425 # If called with a array ref, set new value
426 4 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 2 2 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
202
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
427 {
428 2 $self->{$key} = $_[0];
429 }
430 else
431 {
432 2 $self->{$key} = [ @_ ];
433 }
434  
435 0 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
436 }
437 2 }
438 elsif($interface eq 'get_set_inited')
439 {
440 $methods{$name} = sub
441 14 ▶ {
Subroutine __ANON__: called CC=7 SCAR=19.6
442 14 my($self) = shift;
443  
444 # If called with no arguments, return array contents
445 14 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 10 4 14
446 {
447 10 ▶ $self->{$key} = [] unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 2 8 10
448 10 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 4 10
449 }
450  
451 # If called with a array ref, set new value
452 4 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 2 2 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
202
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
453 {
454 2 $self->{$key} = $_[0];
455 }
456 else
457 {
458 2 $self->{$key} = [ @_ ];
459 }
460  
461 0 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
462 }
463 2 }
464 elsif($interface eq 'get_set_item')
465 {
466 $methods{$name} = sub
467 6 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
468 6 my($self) = shift;
469  
470 6 ▶ Carp::croak "Missing array index" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 6 6
471  
472 6 ▶ if(@_ == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 2 4 6
473 {
474 2 return $self->{$key}[$_[0]] = $_[1];
475 }
476 else
477 {
478 4 return $self->{$key}[$_[0]]
479 }
480 }
481 2 }
482 elsif($interface eq 'unshift')
483 {
484 $methods{$name} = sub
485 6 ▶ {
Subroutine __ANON__: called CC=4 SCAR=13.9
486 6 my($self) = shift;
487 6 ▶ Carp::croak "Missing value(s) to add" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 6 6
488 6 ▶ unshift(@{$self->{$key}}, (@_ == 1 && ref $_[0] eq 'ARRAY') ? @{$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'ARRAY' ? : 2 4 6
Condition100%3/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
222
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
489 }
490 2 }
491 elsif($interface eq 'shift')
492 {
493 $methods{$name} = sub
494 4 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
495 4 my($self) = shift;
496 4 ▶ return splice(@{$self->{$key}}, 0, $_[0]) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 2 4
497 2 return shift(@{$self->{$key}})
498 }
499 2 }
500 elsif($interface eq 'clear')
501 {
502 $methods{$name} = sub
503 2 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
504 2 $_[0]->{$key} = []
505 }
506 2 }
507 elsif($interface eq 'reset')
508 {
509 $methods{$name} = sub
510 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
511 0 $_[0]->{$key} = undef;
512 }
513 0 }
514 elsif($interface =~ /^(?:push|add)$/)
515 {
516 2 ▶ if(my $init_method = $args->{'init_method'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $init_method = $args->{'init_method'}) { } 0 2 2
517 {
518 $methods{$name} = sub
519 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
520 0 my($self) = shift;
521  
522 0 ▶ Carp::croak "Missing value(s) to add" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
523  
524 0 ▶ $self->{$key} = $self->$init_method() unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 0 0 0
525 0 ▶ push(@{$self->{$key}}, (@_ == 1 && ref $_[0] && ref $_[0] eq 'ARRAY') ? @{$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] && ref $_[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] ref $_[0] eq "ARRAY"
Truth table0%0/4
A and B and C
A= @_ == 1B= ref $_[0]C= ref $_[0] eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
526 }
527 0 }
528 else
529 {
530 $methods{$name} = sub
531 6 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.2
532 6 my($self) = shift;
533  
534 6 ▶ Carp::croak "Missing value(s) to add" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 6 6
535  
536 6 ▶ push(@{$self->{$key}}, (@_ == 1 && ref $_[0] && ref $_[0] eq 'ARRAY') ? @{$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] && ref $_[0] eq 'ARRAY' ? : 2 4 6
Condition83%5/6
@_ == 1 and ref $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
402
@_ == 1 and ref $_[0]
!ll&&!rl&&r
222
MC/DC66%2/3
@_ == 1 and ref $_[0] and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] ref $_[0] eq "ARRAY"
Truth table75%3/4
A and B and C
A= @_ == 1B= ref $_[0]C= ref $_[0] eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
537 }
538 2 }
539 }
540 elsif($interface eq 'pop')
541 {
542 $methods{$name} = sub
543 6 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
544 6 my($self) = shift;
545 6 ▶ return splice(@{$self->{$key}}, -$_[0]) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 2 6
546 2 return pop(@{$self->{$key}})
547 }
548 2 }
549 elsif($interface eq 'get_set')
550 {
551 $methods{$name} = sub
552 32 ▶ {
Subroutine __ANON__: called CC=7 SCAR=19.9
553 32 my($self) = shift;
554  
555 # If called with no arguments, return array contents
556 32 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 26 6 32
557 {
558 26 ▶ return wantarray ? (defined $self->{$key} ? @{$self->{$key}} : ()) : $self->{$key}
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 20 6 26
defined $self->{$key} ? : 20 0 20
559 }
560  
561 # If called with a array ref, set new value
562 6 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 4 2 6
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
204
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
563 {
564 4 $self->{$key} = $_[0];
565 }
566 else
567 {
568 2 $self->{$key} = [ @_ ];
569 }
570  
571 0 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
572 }
573 2 }
574 0 else { Carp::croak "Unknown interface: $interface" }
575  
576 18 return \%methods;
577 }
578  
579 4 1;
580  
581 __END__
« Object/MakeMethods.pm ↑ Summary Object.pm »