Family/Person.pm

filter: Statementstmt 83.6% 158 / 189 Branchbran 66.9% 71 / 106 Conditioncond 57.4% 27 / 47 MC/DCmcdc 40.0% 10 / 25 Subroutinesub 90.6% 29 / 32 Podpod 100% 19 / 19 totaltotal 75.1% 314 / 418 CC 82 SCAR 34.2
CC
82
Cov
75%
Toast
210.0
_delete_partner
12.0
Freeze
9.3
CRAP 30.6
↑ Summary Family.pm »
1 package Tree::Family::Person;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Sub::Installer;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Tree::Family::Person
10  
11 =head1 SYNOPSIS
12  
13 my $p = Tree::Family::Person->new(
14 first_name => 'Fred',
15 last_name => 'Flintstone',
16 birth_date => '1901-09-01',
17 death_date => undef,
18 gender => 'male',
19 birth_place => 'Bedrock');
20  
21 $p->spouse($wilma);
22  
23 $p->dad($papa);
24  
25 $p->mom($mama);
26  
27 for ($p->kids) {
28 print $_->first_name;
29 }
30
31 $p->set(last_name => 'Smith');
32  
33 =cut
34  
35 13 our %globalHash; # a hash from IDs to hashes of info
36 13 our @Fields = qw(first_name middle_name last_name birth_date death_date birth_place gender id generation);
37 13 our @RelationFields = qw(spouse mom dad kids partners);
38 13 our $keyMethod = 'first_name'; # Change during testing (see below)
39  
40 =head2 new
41  
42 Create a new person
43  
44 =cut
45  
46 761 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
47 761 my ($class, %args) = @_;
48 my $new_hash = {
49 761 map { ($_ => $args{$_}) } @Fields
50 };
51 761 ▶ my $new_id = _new_id($new_hash) or die "couldn't make id for new object".Dumper($new_hash);
Branch: 1 branch
BranchTrueFalseTotal
my $new_id = _new_id($new_hash) or die q[couldn't make id for new object] . Dumper($new_hash) 761 0 761
52 761 my $id_copy = $new_id;
53 761 $globalHash{$id_copy} = $new_hash;
54 761 my $new_object = bless \$new_id, $class;
55 761 $new_object->set(id => $id_copy);
56 761 return $new_object;
57 }
58  
59 #
60 # _delete_self
61 #
62 # remove a person
63 #
64 1 ▶sub _delete_self {
Subroutine _delete_self: called CC=1 SCAR=0.0
65 1 my $self = shift;
66 1 delete $globalHash{$$self};
67 }
68  
69 761 ▶sub _new_id {
Subroutine _new_id: called CC=4 SCAR=14.1
70 761 ▶ return time.$$.( int ((rand 1) * 10000000)) if $keyMethod eq 'time_pid_rand';
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::Family::Person::keyMethod eq "time_pid_rand" 0 761 761
71 761 my $h = shift;
72 761 ▶ my $val = ($h->{$keyMethod} || (int ((rand 1) * 10000).$$));
Condition33%1/3
$h->{$Tree::Family::Person::keyMethod} || int(rand(1) * 10000) . $$
l!l&&r!l&&!r
76100
MC/DC0%0/2
$h->{$Tree::Family::Person::keyMethod} || int(rand(1) * 10000) . $$
$h->{$Tree::Family::Person::keyMethod} int(rand(1) * 10000) . $$
Truth table33%1/3
A || B
A= $h->{$Tree::Family::Person::keyMethod}B= int(rand(1) * 10000) . $$
ABresult
1X1
011
000
73 761 $val =~ tr/a-zA-Z0-9//cd;
74 761 my $i = 1;
75 761 my $base = $val;
76 761 ▶ while (exists($globalHash{$val})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Tree::Family::Person::globalHash{$val}) 3 761 764
77 3 $val = $base.$i;
78 3 $i++;
79 }
80 761 return $val;
81 }
82  
83 =head2 first_name,middle_name,last_name,birth_date,death_date,birth_place,gender,id,generation
84  
85 Accessors, mutators
86  
87 =cut
88  
89 13 for my $field (@Fields) {
90 __PACKAGE__->install_sub({
91 18077 ▶ $field => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
92 18077 my $self = shift;
93 18077 ▶ $self->set($field => $_[0]) if @_==1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 18077 18077
94 18077 $self->get($field);
95 },
96 117 });
97 }
98  
99 =head2 full_name
100  
101 first + middle + last
102  
103 =cut
104  
105 0 ▶sub full_name {
Subroutine full_name: not called CC=1 SCAR=6.9
Pod documented
106 0 my $self = shift;
107 0 return join ' ', grep defined, ($self->first_name,$self->middle_name, $self->last_name);
108 }
109  
110 =head2 set
111  
112 Set an attribute for a person (same as using mutators above)
113  
114 $person->set(first_name => 'Joe');
115  
116 =cut
117  
118 3696 ▶sub set {
Subroutine set: called CC=3 SCAR=11.0
Pod documented
119 3696 my ($self,$key,$value) = @_;
120 3696 local $@;
121 3696 ▶ die "bad key $key" unless grep /^$key$/, @Fields, @RelationFields;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$key$/, @Tree::Family::Person::Fields, @Tree::Family::Person::RelationFields 0 3696 3696
122 3696 $globalHash{$$self}{$key} = $value;
123 3696 ▶ delete $globalHash{$$self}{$key} if !defined($value);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value 6 3690 3696
124 }
125  
126 =head2 get
127  
128 Get an attribute
129  
130 Same as using accessors above.
131  
132 $person->get('first_name');
133  
134 =cut
135  
136 88427 ▶sub get {
Subroutine get: called CC=3 SCAR=11.4
Pod documented
137 88427 my ($self,$key) = @_;
138 88427 ▶ die "bad key $key" unless grep /^$key$/, @Fields, @RelationFields;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$key$/, @Tree::Family::Person::Fields, @Tree::Family::Person::RelationFields 0 88427 88427
139 88427 ▶ die "no key to get" unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 88427 88427
140 88427 $globalHash{$$self}{$key};
141 }
142  
143 =head2 spouse
144  
145 Get/set spouse
146  
147 $fred->spouse($wilma)
148  
149 =cut
150  
151 11893 ▶sub spouse {
Subroutine spouse: called CC=5 SCAR=16.2
Pod documented
152 11893 my ($self,$spouse) = @_;
153 11893 ▶ return $self->get('spouse') unless @_==2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 11530 363 11893
154 363 ▶ if ($spouse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spouse) 361 2 363
155 361 ▶ die "spouse is not a person" unless ref($spouse) eq 'Tree::Family::Person';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spouse eq "Tree::Family::Person" 0 361 361
156 361 $self->set('spouse' => $spouse);
157 361 $spouse->set('spouse' => $self);
158 361 return;
159 }
160 2 ▶ return unless $self->get('spouse');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get("spouse") 0 2 2
161 2 $self->get("spouse")->set('spouse' => undef);
162 2 $self->set('spouse' => undef);
163 }
164  
165 =head2 dad
166  
167 Get/set dad
168  
169 $luke->dad($darth)
170  
171 =cut
172  
173 6489 ▶sub dad {
Subroutine dad: called CC=5 SCAR=16.1
Pod documented
174 6489 my ($self,$dad) = @_;
175 6489 ▶ return $self->get('dad') unless @_==2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 6117 372 6489
176 372 ▶ if ($dad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dad) 370 2 372
177 370 ▶ die "dad is not a person" unless ref($dad) eq 'Tree::Family::Person';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dad eq "Tree::Family::Person" 0 370 370
178 370 $self->set(dad => $dad);
179 370 $dad->add_kid($self);
180 370 return;
181 }
182 2 my $old_dad = $self->get('dad');
183 2 ▶ return unless $old_dad;
Branch: 1 branch
BranchTrueFalseTotal
unless $old_dad 1 1 2
184 1 $self->set('dad' => undef);
185 1 $old_dad->delete_kid($self);
186 }
187  
188 =head2 mom
189  
190 Get/set mom
191  
192 $pebbles->mom($wilma)
193  
194 =cut
195  
196 7495 ▶sub mom {
Subroutine mom: called CC=5 SCAR=16.1
Pod documented
197 7495 my ($self,$mom) = @_;
198 7495 ▶ return $self->get('mom') unless @_==2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 7120 375 7495
199 375 ▶ if ($mom) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mom) 373 2 375
200 373 ▶ die "mom is not a person" unless ref($mom) eq 'Tree::Family::Person';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mom eq "Tree::Family::Person" 0 373 373
201 373 $self->set(mom => $mom);
202 373 $mom->add_kid($self);
203 373 return;
204 }
205 2 my $old_mom = $self->get('mom');
206 2 ▶ return unless $old_mom;
Branch: 1 branch
BranchTrueFalseTotal
unless $old_mom 1 1 2
207 1 $self->set('mom' => undef);
208 1 $old_mom->delete_kid($self);
209 }
210  
211 =head2 add_kid
212  
213 Add a kid to a person
214  
215 $carol->add_kid($jan);
216 $carol->add_kid($marsha);
217 $carol->add_kid($cindy);
218  
219 =cut
220  
221 743 ▶sub add_kid {
Subroutine add_kid: called CC=4 SCAR=13.9
Pod documented
222 743 my ($self,$kid) = @_;
223 743 ▶ die "not adding undef kid" unless defined $kid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kid 0 743 743
224 743 ▶ return if grep { $_->id eq $kid->id } $self->kids;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->id eq $kid->id;} $self->kids 4 739 743
225 739 ▶ $self->set(kids => []) unless $self->get('kids');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get("kids") 689 50 739
226 739 push @{ $self->get('kids') }, $kid;
227 }
228  
229 =head2 delete_kid
230  
231 Remove a kid from a person
232  
233 $someone->remove_kid($annie)
234  
235 =cut
236  
237 3 ▶sub delete_kid {
Subroutine delete_kid: called CC=8 SCAR=22.0
Pod documented
238 3 my ($self, $which) = @_;
239 3 ▶ die "no kids to delete" unless $self->get('kids');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get("kids") 0 3 3
240 3 $self->set(kids => [ grep $_ ne $which, @{ $self->get('kids') }]);
241 3 ▶ $which->mom(undef) if $self->gender && $self->gender eq 'f' && $which->mom;
Branch: 1 branch
BranchTrueFalseTotal
if $self->gender and $self->gender eq "f" and $which->mom 1 2 3
Condition83%5/6
$self->gender and $self->gender eq "f" and $which->mom
!ll&&!rl&&r
111
$self->gender and $self->gender eq "f"
!ll&&!rl&&r
102
MC/DC66%2/3
$self->gender and $self->gender eq "f" and $which->mom
$self->gender $self->gender eq "f" $which->mom
Truth table75%3/4
A and B and C
A= $self->genderB= $self->gender eq "f"C= $which->mom
ABCresult
0XX0
10X0
1100
1111
242 3 ▶ $which->dad(undef) if $self->gender && $self->gender eq 'm' && $which->dad;
Branch: 1 branch
BranchTrueFalseTotal
if $self->gender and $self->gender eq "m" and $which->dad 0 3 3
Condition50%3/6
$self->gender and $self->gender eq "m" and $which->dad
!ll&&!rl&&r
300
$self->gender and $self->gender eq "m"
!ll&&!rl&&r
120
MC/DC0%0/3
$self->gender and $self->gender eq "m" and $which->dad
$self->gender $self->gender eq "m" $which->dad
Truth table50%2/4
A and B and C
A= $self->genderB= $self->gender eq "m"C= $which->dad
ABCresult
0XX0
10X0
1100
1111
243 }
244  
245 =head2 kids
246  
247 Return an array of kids
248  
249 print $_->name for $mike->kids
250  
251 =cut
252  
253 3612 ▶sub kids {
Subroutine kids: called CC=2 SCAR=6.9
Pod documented
254 3612 ▶ return @{ shift->get('kids') || [] };
Condition100%2/2
(shift())->get('kids') || []
l!l
2693919
MC/DC100%1/1
(shift())->get('kids') || []
(shift())->get('kids')
Truth table100%2/2
A
A= (shift())->get('kids')
Aresult
11
00
255 }
256  
257 =head2 has_partner
258  
259 Did $a have any kids with $b?
260  
261 print $a->has_partner($b) ? 'you betcha' : 'nope'
262  
263 =cut
264  
265 66 ▶sub has_partner {
Subroutine has_partner: called CC=1 SCAR=0.0
Pod documented
266 66 my ($self,$who) = @_;
267 66 return grep { $_->id eq $who->id } $self->partners;
268 }
269  
270 #
271 # _add_partner, _delete_partner
272 #
273 33 ▶sub _add_partner {
Subroutine _add_partner: called CC=4 SCAR=13.9
274 33 my ($self, $partner) = @_;
275 33 ▶ $self->set(partners => []) unless $self->get('partners');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get("partners") 21 12 33
276 33 ▶ push @{ $self->get('partners') }, $partner unless $self->has_partner($partner);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_partner($partner) 22 11 33
277 33 ▶ $partner->_add_partner($self) unless $partner->has_partner($self);
Branch: 1 branch
BranchTrueFalseTotal
unless $partner->has_partner($self) 11 22 33
278 }
279  
280 0 ▶sub _delete_partner {
Subroutine _delete_partner: not called CC=3 SCAR=24.8
281 0 my ($self, $which) = @_;
282 0 ▶ die "no partners to delete" unless $self->get('partners');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get("partners") 0 0 0
283 0 $self->set(partners => [ grep $_->id ne $which->id, @{ $self->get('partners') }]);
284 0 ▶ $which->_delete_partner($self) if $which->has_partner($self);
Branch: 1 branch
BranchTrueFalseTotal
if $which->has_partner($self) 0 0 0
285 }
286  
287 =head2 partners
288  
289 Get people with whom a person had kids.
290  
291 =cut
292  
293 2196 ▶sub partners {
Subroutine partners: called CC=2 SCAR=6.9
Pod documented
294 # _set_all_partners must have been called
295 2196 ▶ return @{ shift->get('partners') || [] };
Condition100%2/2
(shift())->get('partners') || []
l!l
782118
MC/DC100%1/1
(shift())->get('partners') || []
(shift())->get('partners')
Truth table100%2/2
A
A= (shift())->get('partners')
Aresult
11
00
296 }
297  
298 =head2 find
299  
300 Find a person based on their attributes
301  
302 $class->find(first_name => "Bugs", last_name => "Bunny" );
303  
304 =cut
305  
306 6 ▶sub find {
Subroutine find: called CC=6 SCAR=18.8
Pod documented
307 6 my ($class, %args) = @_;
308 6 my @list = values %globalHash;
309 6 ▶ while (my ($key,$value) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 6 6 12
310 6 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 6 0 6
311 6 ▶ @list = grep defined($_->{$key}) && $_->{$key} eq $value, @list;
Condition66%2/3
defined $_->{$key} && $_->{$key} eq $value
!ll&&!rl&&r
03378714
MC/DC50%1/2
defined $_->{$key} && $_->{$key} eq $value
defined $_->{$key} $_->{$key} eq $value
Truth table66%2/3
A && B
A= defined $_->{$key}B= $_->{$key} eq $value
ABresult
0X0
100
111
312 } else {
313 0 @list = grep !defined($_->{$key}), @list;
314 }
315 }
316 6 ▶ return unless @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 0 6 6
317 714 return wantarray ? map { bless \(my $i = $_->{id}), $class } @list :
318 6 ▶ bless \(my $j = $list[0]->{id}), $class;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 0 6
319 }
320  
321 # _clear_generations
322 # Remove all the generation attributes from the graph
323  
324 12 ▶sub _clear_generations {
Subroutine _clear_generations: called CC=2 SCAR=6.9
325 12 my $self = shift;
326 12 delete $_->{generation} for values %globalHash;
327 }
328  
329 #
330 # _set_all_generations
331 #
332 # Set all the generations recursively based on kids/parents
333 #
334  
335 2192 ▶sub _set_all_generations {
Subroutine _set_all_generations: called CC=7 SCAR=19.5
336 # Sets a generation tag in each person, starting with ourselves.
337 2192 my ($self, $value) = @_;
338 2192 ▶ return if defined($self->get('generation'));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->get("generation") 1441 751 2192
339 751 ▶ Carp::confess("missing generation") unless defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 751 751
340 751 $self->set(generation => $value);
341 751 ▶ $self->dad->_set_all_generations($value - 1) if $self->dad;
Branch: 1 branch
BranchTrueFalseTotal
if $self->dad 367 384 751
342 751 ▶ $self->mom->_set_all_generations($value - 1) if $self->mom;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mom 365 386 751
343 751 $_->_set_all_generations($value + 1) for $self->kids;
344 751 ▶ $self->spouse->_set_all_generations($value) if $self->spouse;
Branch: 1 branch
BranchTrueFalseTotal
if $self->spouse 716 35 751
345 }
346  
347 =head2 all
348  
349 Get all people
350  
351 Tree::Family::Person->all
352  
353 =cut
354  
355 12 ▶sub all {
Subroutine all: called CC=1 SCAR=0.0
Pod documented
356 12 my $class = shift;
357 12 return map { bless \(my $o = $_->{id}), $class } values %globalHash;
358 }
359  
360 =head2 partners_and_spouse
361  
362 Get a list of all people with whom a person had kids, and their spouse (if
363 they have one)
364  
365 =cut
366  
367 684 ▶sub partners_and_spouse {
Subroutine partners_and_spouse: called CC=2 SCAR=6.9
Pod documented
368 684 my $self = shift;
369 684 ▶ return ($self->partners, ($self->spouse() ? $self->spouse() : ()));
Branch: 1 branch
BranchTrueFalseTotal
$self->spouse ? : 682 2 684
370 }
371  
372 12 ▶sub _clear_all_partners {
Subroutine _clear_all_partners: called CC=2 SCAR=6.9
373 12 delete $_->{partners} for values %globalHash;
374 }
375  
376 12 ▶sub _set_all_partners {
Subroutine _set_all_partners: called CC=7 SCAR=19.5
377 12 my $class = shift;
378 # A partner is someone you have had a kid with who is not your spouse.
379 12 for my $person ($class->all) {
380 751 ▶ if ( $person->dad
Branch: 1 branch
BranchTrueFalseTotal
if ($person->dad and $person->mom and !$person->mom->spouse || $person->mom->spouse ne $person->dad and not grep({$_ eq $person->dad;} $person->mom->partners)) 11 740 751
Condition100%12/12
$person->dad and $person->mom and !$person->mom->spouse || $person->mom->spouse ne $person->dad and not grep({$_ eq $person->dad;} $person->mom->partners)
!ll&&!rl&&r
739111
$person->dad and $person->mom and !$person->mom->spouse || $person->mom->spouse ne $person->dad
!ll&&!rl&&r
38935012
$person->dad and $person->mom
!ll&&!rl&&r
3845362
not $person->mom->spouse or $person->mom->spouse ne $person->dad
l!l&&r!l&&!r
102350
MC/DC100%5/5
$person->dad and $person->mom and !$person->mom->spouse || $person->mom->spouse ne $person->dad and not grep({$_ eq $person->dad;} $person->mom->partners)
$person->dad $person->mom not $person->mom->spouse $person->mom->spouse ne $person->dad not grep({$_ eq $person->dad;} $person->mom->partners)
Truth table85%6/7
A and B and not(C) or D and not(E)
A= $person->dadB= $person->momC= not $person->mom->spouseD= $person->mom->spouse ne $person->dadE= not grep({$_ eq $person->dad;} $person->mom->partners)
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
381 && $person->mom
382 && (!$person->mom->spouse() || $person->mom->spouse() ne $person->dad)
383 1 && !grep { $_ eq $person->dad } $person->mom->partners
384 ) {
385 11 $person->mom->_add_partner($person->dad);
386 11 $person->dad->_add_partner($person->mom);
387 }
388 }
389 }
390  
391 =head2 min_generation, max_generation
392  
393 The min/max numeric generation
394  
395 =cut
396  
397 1 ▶sub min_generation {
Subroutine min_generation: called CC=3 SCAR=11.2
Pod documented
398 1 for (values %globalHash) {
399 682 ▶ die "missing generation for $_\n".Dumper(\%globalHash) unless defined($_->{generation});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_->{"generation"} 0 682 682
400 }
401 1 return min map $_->{generation}, values %globalHash;
402 }
403  
404 2 ▶sub max_generation {
Subroutine max_generation: called CC=1 SCAR=0.0
Pod documented
405 2 return max map $_->{generation}, values %globalHash;
406 }
407  
408 =head2 Freeze, Toast
409  
410 Used for storage by Data::Dumper.
411  
412 =cut
413  
414 751 ▶sub Freeze {
Subroutine Freeze: called CC=9 SCAR=22.3
Pod documented
415 751 my $self = shift;
416 #warn "freezing $$self";
417 751 my %i = map { $_ => $self->get($_) } @Fields;
418 751 for (@RelationFields) {
419 3755 ▶ next if /kids|partners/i;
Branch: 1 branch
BranchTrueFalseTotal
if /kids|partners/i 1502 2253 3755
420 2253 ▶ next unless $self->$_;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$_ 805 1448 2253
421 0 ▶ $i{$_} = ( $self->$_->isa('REF') ? ${ $self->$_ }->{id} : ${ $self->$_ } );
Branch: 1 branch
BranchTrueFalseTotal
$self->$_->isa('REF') ? : 0 1448 1448
422 }
423 751 for ($self->kids) {
424 732 ▶ push @{ $i{kids} }, ( $_->isa('REF') ? $$_->{id} : $$_ );
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('REF') ? : 0 732 732
425 }
426 751 for ($self->partners) {
427 22 ▶ push @{ $i{partners} },( $_->isa('REF') ? $$_->{id} : $$_ );
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('REF') ? : 0 22 22
428 }
429 751 return bless \%i, "Tree::Family::Person";
430 # return value is ignored; you can't replace the object.
431 }
432  
433 0 ▶sub Toast {
Subroutine Toast: not called CC=14 SCAR=53.5
Pod documented
434 0 my $self = shift;
435 0 my $class = ref $self;
436 0 my $data = $self;
437 0 my %i = map { $_ => $data->{$_} } @Fields;
438 0 for (@RelationFields) {
439 0 ▶ next if /kids|partners/i;
Branch: 1 branch
BranchTrueFalseTotal
if /kids|partners/i 0 0 0
440 0 ▶ next unless $data->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $data->{$_} 0 0 0
441 0 my $tmp = $data->{$_};
442 0 ▶ $i{$_} = ref $tmp && $tmp->isa('REF') ? bless \(my $id = $tmp->{id}), $class : bless \$tmp, $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $tmp && $tmp->isa('REF') ? : 0 0 0
Condition0%0/3
ref $tmp and $tmp->isa("REF")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $tmp and $tmp->isa("REF")
ref $tmp $tmp->isa("REF")
Truth table0%0/3
A and B
A= ref $tmpB= $tmp->isa("REF")
ABresult
0X0
100
111
443 }
444 0 ▶ for (@{ $data->{kids} || [] } ) {
Condition0%0/2
$data->{'kids'} || []
l!l
00
MC/DC0%0/1
$data->{'kids'} || []
$data->{'kids'}
Truth table0%0/2
A
A= $data->{'kids'}
Aresult
11
00
445 0 ▶ push @{ $i{kids} }, ref $_ && $_->isa('REF') ? bless \(my $c = $_), $class : bless \$_, $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && $_->isa('REF') ? : 0 0 0
Condition0%0/3
ref $_ and $_->isa("REF")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and $_->isa("REF")
ref $_ $_->isa("REF")
Truth table0%0/3
A and B
A= ref $_B= $_->isa("REF")
ABresult
0X0
100
111
446 }
447 0 ▶ for (@{ $data->{partners} || [] } ) {
Condition0%0/2
$data->{'partners'} || []
l!l
00
MC/DC0%0/1
$data->{'partners'} || []
$data->{'partners'}
Truth table0%0/2
A
A= $data->{'partners'}
Aresult
11
00
448 0 ▶ push @{ $i{partners} }, ref $_ && $_->isa('REF') ? bless \(my $c = $_), $class : bless \$_, $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && $_->isa('REF') ? : 0 0 0
Condition0%0/3
ref $_ and $_->isa("REF")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and $_->isa("REF")
ref $_ $_->isa("REF")
Truth table0%0/3
A and B
A= ref $_B= $_->isa("REF")
ABresult
0X0
100
111
449 }
450 0 my $id = $data->{id};
451 0 $globalHash{$id} = \%i;
452 0 $self = \$id;
453 0 return bless $self, $class;
454 }
455  
456 #sub DESTROY {
457 # my $self = shift;
458 # warn "destroying $$self ";
459 #for (values %globalHash) {
460 # next unless $_ && ref($_) eq 'Tree::Family::Person';
461 # $_->set('spouse' => undef);
462 # $_->set('dad' => undef);
463 # $_->set('mom' => undef);
464 #}
465 # delete $globalHash{$$self} if exists($globalHash{$$self});
466 #}
467  
468 13 1;
469  
↑ Summary Family.pm »