Node.pm

filter: Statementstmt 56.6% 77 / 136 Branchbran 21.7% 10 / 46 Conditioncond 41.6% 5 / 12 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 69.2% 18 / 26 Podpod 100% 21 / 21 totaltotal 53.4% 133 / 249 CC 39 SCAR 39.3
CC
39
Cov
47%
pathsToAncestor
210.0
lengthOfShortestPathToRoot
20.0
lengthOfLongestPathToRoot
12.0
CRAP 50.7
« TermFinderReport/Html.pm ↑ Summary AnnotationProvider/AnnotationParser.pm »
1 package GO::Node;
2  
3 # File : Node.pm
4 # Author : Gavin Sherlock
5 # Date Begun : December 23rd 2002
6  
7 # $Id: Node.pm,v 1.11 2007/03/18 02:54:46 sherlock Exp $
8  
9 # License information (the MIT license)
10  
11 # Copyright (c) 2003 Gavin Sherlock; Stanford University
12  
13 # Permission is hereby granted, free of charge, to any person
14 # obtaining a copy of this software and associated documentation files
15 # (the "Software"), to deal in the Software without restriction,
16 # including without limitation the rights to use, copy, modify, merge,
17 # publish, distribute, sublicense, and/or sell copies of the Software,
18 # and to permit persons to whom the Software is furnished to do so,
19 # subject to the following conditions:
20  
21 # The above copyright notice and this permission notice shall be
22 # included in all copies or substantial portions of the Software.
23  
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 # SOFTWARE.
32  
33 =pod
34  
35 =head1 NAME
36  
37 GO::Node - provides information about a node in the Gene Ontology
38  
39 =head1 DESCRIPTION
40  
41 The GO::Node package is intended to be used as a container for
42 information about a node in one of the three Gene Ontologies. It
43 allows the storage of the goid, and immediate parents and children, as
44 well as paths to the top of the ontology. This package provides
45 methods to both store and retrieve that information.
46  
47 It should be strongly noted that clients are not expected to create
48 individual Node objects themselves, but instead should rely in a Node
49 Factory to create nodes and return them. Such a factory would be a
50 concrete subclass of the abstract GO::OntologyProvider package.
51  
52 =head1 TODO
53  
54 The following items needs to be done at some point to make the Node
55 class more flexible, and for it to better model the data.
56  
57 Add in methods to deal with secondary GOIDs
58  
59 Add in methods to allow definitions to be associated with, and
60 retrieved from Nodes.
61  
62 Add in methods to allow dbxrefs to be included.
63  
64 Not require Factories to add the paths to the root, but instead
65 have this class generate those paths from the inherent structure
66 of the graph in which the Nodes sit. This will also be useful to
67 generate paths to leaves/descendants.
68  
69 =cut
70  
71 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 3 ▶use diagnostics;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 3 ▶use vars qw ($PACKAGE $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 3 $VERSION = 0.16;
78 3 $PACKAGE = "GO::Node";
79  
80 # CLASS CONSTANTS
81  
82 3 my $kGoid = $PACKAGE.'::__goid';
83 3 my $kTerm = $PACKAGE.'::__term';
84  
85 3 my $kParents = $PACKAGE.'::__parents';
86 3 my $kChildren = $PACKAGE.'::__children';
87 3 my $kPaths = $PACKAGE.'::__paths';
88 3 my $kAncestors = $PACKAGE.'::__ancestors';
89  
90  
91 ##################################################################
92  
93 # The constructor, and associated initialization methods
94  
95 ##################################################################
96 25116 ▶sub new{
Subroutine new: called CC=5 SCAR=16.1
Pod documented
97 ##################################################################
98 # This is the constructor for the Node object
99 #
100 # At a minimum, the constructor expects, as named arguments, a GOID
101 # and a GO term, with which to create the node object.
102 #
103 # Usage:
104 #
105 # my $node = GO::Node->new(goid => $goid,
106 # term => $term);
107  
108 25116 my ($class, %args) = @_;
109  
110 25116 my $self = {};
111  
112 25116 bless $self, $class;
113  
114 25116 ▶ if (!exists ($args{'goid'}) || !defined ($args{'goid'})){
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $args{'goid'} && defined $args{'goid'}) { } 1 25115 25116
elsif (not exists $args{'term'} && defined $args{'term'}) { } 1 25114 25115
Condition66%2/3
exists $args{'goid'} && defined $args{'goid'}
!ll&&!rl&&r
1025115
MC/DC50%1/2
exists $args{'goid'} && defined $args{'goid'}
exists $args{'goid'} defined $args{'goid'}
Truth table66%2/3
A && B
A= exists $args{'goid'}B= defined $args{'goid'}
ABresult
0X0
100
111
115  
116 1 $self->_handleMissingArgument(argument=>'goid');
117  
118 ▶ }elsif (!exists ($args{'term'}) || !defined ($args{'term'})){
Condition66%2/3
exists $args{'term'} && defined $args{'term'}
!ll&&!rl&&r
1025114
MC/DC50%1/2
exists $args{'term'} && defined $args{'term'}
exists $args{'term'} defined $args{'term'}
Truth table66%2/3
A && B
A= exists $args{'term'}B= defined $args{'term'}
ABresult
0X0
100
111
119  
120 1 $self->_handleMissingArgument(argument=>'term');
121  
122 }
123  
124 25114 $self->{$kGoid} = $args{'goid'};
125 25114 $self->{$kTerm} = $args{'term'};
126  
127 25114 $self->{$kPaths} = [];
128  
129 25114 return $self;
130  
131 }
132  
133 ##################################################################
134 #
135 # PUBLIC SETTER METHODS
136 #
137 ##################################################################
138  
139 ##################################################################
140 43286 ▶sub addChildNodes{
Subroutine addChildNodes: called CC=2 SCAR=6.9
Pod documented
141 ##################################################################
142 # The public setter method allows a client to indicate that an array
143 # of nodes are children of the 'self' node. Only one node per child
144 # goid will get stored.
145 #
146 # Usage:
147 #
148 # $node->addChildNodes(@childNodes);
149  
150 43286 my $self = shift;
151  
152 43286 foreach my $node (@_){
153  
154 # store children as a hash, with the goid as the key and the
155 # node itself as the value
156  
157 43286 $self->{$kChildren}{$node->goid} = $node;
158  
159 }
160  
161 }
162  
163 ##################################################################
164 43286 ▶sub addParentNodes{
Subroutine addParentNodes: called CC=2 SCAR=6.9
Pod documented
165 ##################################################################
166 # The public setter method allows a client to indicate that an array
167 # of nodes are parents of the 'self' node. Only one node per parent
168 # goid will get stored.
169 #
170 # Usage:
171 #
172 # $node->addParentNodes(@parentNodes);
173  
174 43286 my $self = shift;
175  
176 43286 foreach my $node (@_){
177  
178 # store parents as a hash, with the goid as the key and the
179 # node itself as the value
180  
181 43286 $self->{$kParents}{$node->goid} = $node;
182  
183 }
184  
185 }
186  
187 ##################################################################
188 624132 ▶sub addPathToRoot{
Subroutine addPathToRoot: called CC=1 SCAR=0.0
Pod documented
189 ##################################################################
190  
191 # This public setter method expects an array of nodes, that indicates
192 # a direct path to the root of the ontology. The array should not
193 # contain the self node, but should contain the root node. The last
194 # entry in the array is expected to be an immediate parent of the self
195 # node, while the first entry is expected to be the root node itself.
196 # This method will NOT check to see if the supplied path has not
197 # already been added. It is the Node Factory's responsibility to only
198 # add a unique path once. Furthermore, it will not check whether
199 # there is consistency between addedPaths and addedParents (this can
200 # be done using the isValid method though).
201  
202 #
203 # Usage:
204 #
205 # $node->addPathToRoot(@nodes);
206 #
207  
208 624132 my ($self, @nodes) = @_;
209  
210 624132 push (@{$self->{$kPaths}}, \@nodes);
211  
212 }
213  
214 ##################################################################
215 #
216 # PUBLIC ACCESSSOR METHODS
217 #
218 ##################################################################
219  
220 ##################################################################
221 1701178 ▶sub goid{
Subroutine goid: called CC=1 SCAR=0.0
Pod documented
222 ##################################################################
223 # This public method returns the goid associated with the node.
224 #
225 # Usage:
226 #
227 # my $goid = $node->goid;
228  
229 1701178 return $_[0]->{$kGoid};
230  
231 }
232  
233 ##################################################################
234 524 ▶sub term{
Subroutine term: called CC=1 SCAR=0.0
Pod documented
235 ##################################################################
236 # This public method returns the term associated with the node.
237 #
238 # Usage:
239 #
240 # my $goid = $node->term;
241  
242 524 return $_[0]->{$kTerm};
243  
244 }
245  
246 ##################################################################
247 127354 ▶sub childNodes{
Subroutine childNodes: called CC=1 SCAR=0.0
Pod documented
248 ##################################################################
249 # This public method returns an array of child nodes for the self
250 # node.
251 #
252 # Usage:
253 #
254 # my @childNodes = $node->childNodes;
255  
256 127354 return (values %{$_[0]->{$kChildren}});
257  
258 }
259  
260 ##################################################################
261 12558 ▶sub parentNodes{
Subroutine parentNodes: called CC=1 SCAR=0.0
Pod documented
262 ##################################################################
263 # This public method returns an array of parent nodes for the self
264 # node.
265 #
266 # Usage:
267 #
268 # my @parentNodes = $node->parentNodes;
269  
270 12558 return (values %{$_[0]->{$kParents}});
271  
272 }
273  
274 ##################################################################
275 13761 ▶sub pathsToRoot{
Subroutine pathsToRoot: called CC=1 SCAR=0.0
Pod documented
276 ##################################################################
277 # This public method returns an array of references to arrays, each of
278 # which contains the nodes in a path between the self node and the
279 # root. The self node is not included in the paths, but the root node
280 # is. The first node in each array is the most distant ancestor (the
281 # root), the last node is an immediate parent. If there are no paths
282 # to the root (i.e. it is the root node) then an empty array will be
283 # returned.
284 #
285 # Usage:
286 #
287 # my @pathsToRoot = $node->pathsToRoot;
288  
289 13761 return (@{$_[0]->{$kPaths}});
290  
291 }
292  
293 ##################################################################
294 0 ▶sub pathsToAncestor{
Subroutine pathsToAncestor: not called CC=14 SCAR=53.5
Pod documented
295 ##################################################################
296 # This public method returns an array of references to arrays, each of
297 # which contains the nodes in a path between the self node and the
298 # specified ancestor. The self node is not included paths, but the
299 # specified ancestor node is. The first node in each array is the
300 # specified ancestor, the last node is an immediate parent. If there
301 # are no paths to the ancestor then an empty array will be returned.
302 #
303 # Usage:
304 #
305 # my @pathsToAncestor = $node->pathsToAncestor($ancestorNode);
306  
307 0 my ($self, $ancestor) = @_;
308  
309 0 ▶ return () if (!$self->isADescendantOf($ancestor)); # NOTE early return
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isADescendantOf($ancestor) 0 0 0
310  
311 0 my @paths;
312
313 0 foreach my $path ($self->pathsToRoot){ # examine paths to root
314  
315 0 ▶ foreach (my $j = 0; $j< @{$path}; $j++){
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$path;}) 0 0 0
316  
317 0 ▶ if ($path->[$j] == $ancestor){ # if it's the node we want
Branch: 1 branch
BranchTrueFalseTotal
if ($path->[$j] == $ancestor) 0 0 0
318  
319 # we want the array from this point to the end
320
321 0 push (@paths, [@{$path}[$j..@{$path}-1]]); # array slice
322
323 0 last; # no need to look further
324  
325 }
326  
327 }
328  
329 }
330  
331 # now we have to unique the paths, as there may be some redundancy
332 # should check cookbook to see if there's a better way to do this
333  
334 0 my (%duplicates, @uniquePaths);
335  
336 0 ▶ foreach (my $i = 0; $i < @paths - 1 ; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @paths - 1) 0 0 0
337  
338 0 ▶ next if exists $duplicates{$i};
Branch: 1 branch
BranchTrueFalseTotal
if exists $duplicates{$i} 0 0 0
339  
340 INNER:
341  
342 0 ▶ foreach (my $j = $i+1; $j < @paths; $j++){
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @paths) 0 0 0
343  
344 0 ▶ next if exists $duplicates{$j};
Branch: 1 branch
BranchTrueFalseTotal
if exists $duplicates{$j} 0 0 0
345  
346 # can't be the same if different sizes
347  
348 0 ▶ next INNER if scalar @{$paths[$i]} != scalar @{$paths[$j]};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$paths[$i];} != scalar @{$paths[$j];} 0 0 0
349  
350 # now compare each member of the arrays
351  
352 0 ▶ for (my $k = 0; $k < @{$paths[$i]}; $k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < @{$paths[$i];}) 0 0 0
353  
354 # can't be the same if any two members are different
355  
356 0 ▶ next INNER if $paths[$i][$k] != $paths[$j][$k];
Branch: 1 branch
BranchTrueFalseTotal
if $paths[$i][$k] != $paths[$j][$k] 0 0 0
357  
358 }
359  
360 # if we get here, path j must be the same as i
361  
362 0 $duplicates{$j} = undef; # so we'll eliminate it from future consideration
363  
364 }
365  
366 }
367  
368 0 ▶ for (my $i = 0; $i < @paths; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @paths) 0 0 0
369  
370 0 ▶ next if exists $duplicates{$i};
Branch: 1 branch
BranchTrueFalseTotal
if exists $duplicates{$i} 0 0 0
371  
372 0 push (@uniquePaths, $paths[$i]);
373  
374 }
375  
376 0 return @uniquePaths;
377  
378 }
379  
380 ##################################################################
381 32710 ▶sub ancestors{
Subroutine ancestors: called CC=4 SCAR=13.9
Pod documented
382 ##################################################################
383 # This public method returns an array of unique GO::Nodes which
384 # are the unique ancestors that a node has. These ancestors will be
385 # derived from the paths to the root node that have been added to the
386 # node.
387  
388 32710 my $self = shift;
389  
390 32710 ▶ if (!exists $self->{$kAncestors}){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$kAncestors}) 1205 31505 32710
391  
392 1205 my %ancestors;
393
394 1205 foreach my $path ($self->pathsToRoot){
395
396 23421 foreach my $node (@{$path}){
397
398 220728 $ancestors{$node->goid} = $node;
399
400 }
401
402 }
403  
404 1205 $self->{$kAncestors} = \%ancestors;
405  
406 }
407  
408 32710 return (values %{$self->{$kAncestors}});
409  
410 }
411  
412 ##################################################################
413 0 ▶sub lengthOfLongestPathToRoot{
Subroutine lengthOfLongestPathToRoot: not called CC=3 SCAR=24.8
Pod documented
414 ##################################################################
415 # This public method returns the length of the longest path to the
416 # root of the ontology from the node. If the node is in fact the root,
417 # then a value of zero will be returned.
418 #
419 # Usage:
420 #
421 # my $length = $node->lengthOfLongestPathToRoot;
422  
423 0 my $self = shift;
424  
425 0 my $maxLength = 0;
426  
427 0 foreach my $path ($self->pathsToRoot){
428  
429 0 ▶ $maxLength = scalar (@{$path}) if (scalar (@{$path}) > $maxLength);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$path;} > $maxLength 0 0 0
430  
431 }
432  
433 0 return $maxLength;
434  
435 }
436  
437 ##################################################################
438 0 ▶sub lengthOfShortestPathToRoot{
Subroutine lengthOfShortestPathToRoot: not called CC=4 SCAR=30.0
Pod documented
439 ##################################################################
440 # This public method returns the length of the shortest path to the
441 # root of the ontology from the node. If the node is in fact the root,
442 # then a value of zero will be returned.
443 #
444 # Usage:
445 #
446 # my $length = $node->lengthOfShortestPathToRoot;
447  
448 0 my $self = shift;
449  
450 0 my $minLength;
451  
452 0 foreach my $path ($self->pathsToRoot){
453  
454 0 ▶ $minLength = scalar (@{$path}) if (!defined $minLength || scalar (@{$path}) < $minLength);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $minLength or scalar @{$path;} < $minLength 0 0 0
Condition0%0/3
not defined $minLength or scalar @{$path;} < $minLength
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $minLength or scalar @{$path;} < $minLength
not defined $minLength scalar @{$path;} < $minLength
Truth table0%0/3
not(A) or B
A= not defined $minLengthB= scalar @{$path;} < $minLength
ABresult
1X1
011
000
455  
456 }
457  
458 0 return $minLength;
459  
460 }
461  
462 ##################################################################
463 0 ▶sub meanLengthOfPathsToRoot{
Subroutine meanLengthOfPathsToRoot: not called CC=3 SCAR=24.8
Pod documented
464 ##################################################################
465 # This public method returns the mean length of all paths to the
466 # root node. If the node is in fact the root, then a value of zero
467 # will be returned.
468 #
469 # Usage:
470 #
471 # my $length = $node->meanLengthOfPathsToRoot;
472  
473 0 my $self = shift;
474  
475 0 my $total = 0;
476 0 my $num = 0;
477  
478 0 foreach my $path ($self->pathsToRoot){
479  
480 0 $total += scalar (@{$path});
481 0 $num++;
482  
483 }
484  
485 0 my $average = 0;
486  
487 0 ▶ if ($num){
Branch: 1 branch
BranchTrueFalseTotal
if ($num) 0 0 0
488  
489 0 $average = $total/$num;
490  
491 }
492  
493 0 return $average;
494  
495 }
496
497  
498 # Methods returning a boolean
499  
500 ##################################################################
501 12556 ▶sub isValid{
Subroutine isValid: called CC=8 SCAR=21.6
Pod documented
502 ##################################################################
503 # This method can be used to check that a node has been constructed
504 # correctly. It checks that it is a child of all its parents, and a parent
505 # of all of it's children. In addition, it checks that parents exist as
506 # the most recent ancestors of the node in its paths to the root node,
507 # and vice versa.
508  
509 12556 my $self = shift;
510  
511 12556 my $isValid = 1; # assume there'll be no problems
512  
513 # check we're a child of each parent
514  
515 12556 foreach my $parent ($self->parentNodes){
516  
517 21643 ▶ $isValid = 0 unless $parent->isAParentOf($self);
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->isAParentOf($self) 0 21643 21643
518  
519 }
520  
521 # check we're a parent of each child
522  
523 12556 foreach my $child ($self->childNodes){
524  
525 21643 ▶ $isValid = 0 unless $child->isAChildOf($self);
Branch: 1 branch
BranchTrueFalseTotal
unless $child->isAChildOf($self) 0 21643 21643
526  
527 }
528  
529 # check that the most recent ancestor in each path is a parent
530  
531 12556 foreach my $path ($self->pathsToRoot){
532  
533 312066 ▶ $isValid = 0 unless $path->[-1]->isAParentOf($self);
Branch: 1 branch
BranchTrueFalseTotal
unless $path->[-1]->isAParentOf($self) 0 312066 312066
534 312066 ▶ $isValid = 0 unless $self->isAChildOf($path->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isAChildOf($path->[-1]) 0 312066 312066
535  
536 }
537  
538 12556 return $isValid;
539  
540 }
541  
542 ##################################################################
543 333709 ▶sub isAParentOf{
Subroutine isAParentOf: called CC=1 SCAR=0.0
Pod documented
544 ##################################################################
545 # This public method returns a boolean to indicate whether a node
546 # has the supplied node as a child.
547 #
548 # Usage :
549 #
550 # if ($node->isAParentOf($anotherNode)){
551 #
552 # # blah
553 #
554 # }
555  
556 333709 my ($self, $child) = @_;
557  
558 333709 return exists $self->{$kChildren}{$child->goid};
559  
560 }
561  
562 ##################################################################
563 333709 ▶sub isAChildOf{
Subroutine isAChildOf: called CC=1 SCAR=0.0
Pod documented
564 ##################################################################
565 # This public method returns a boolean to indicate whether a node
566 # has the supplied node as a parent.
567 #
568 # Usage :
569 #
570 # if ($node->isAChildOf($anotherNode)){
571 #
572 # # blah
573 #
574 # }
575  
576 333709 my ($self, $parent) = @_;
577  
578 333709 return exists $self->{$kParents}{$parent->goid};
579  
580 }
581  
582 ##################################################################
583 0 ▶sub isAnAncestorOf{
Subroutine isAnAncestorOf: not called CC=1 SCAR=6.9
Pod documented
584 ##################################################################
585 # This method returns a boolean to indicate whether a node is an
586 # ancestor of another.
587 #
588 # Usage:
589 #
590 # if ($node->isAnAncestorOf($anotherNode)){
591 #
592 # # blah
593 #
594 # }
595  
596 0 my ($self, $descendant) = @_;
597  
598 0 return $descendant->isADescendantOf($self);
599  
600 }
601  
602 ##################################################################
603 0 ▶sub isADescendantOf{
Subroutine isADescendantOf: not called CC=2 SCAR=17.9
Pod documented
604 ##################################################################
605 # This method returns a boolean to indicate whether a node is a
606 # descendant of another.
607 #
608 # Usage:
609 #
610 # if ($node->isADescendantOf($anotherNode)){
611 #
612 # # blah
613 #
614 # }
615  
616 0 my ($self, $ancestor) = @_;
617  
618 # make sure ancestors get stored in ourself, if not already
619  
620 0 ▶ $self->ancestors if (!exists $self->{$kAncestors});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$kAncestors} 0 0 0
621  
622 # then check if the possible ancestor is in there
623  
624 0 return (exists $self->{$kAncestors}{$ancestor->goid});
625  
626 }
627  
628 ##################################################################
629 0 ▶sub isLeaf{
Subroutine isLeaf: not called CC=1 SCAR=6.9
Pod documented
630 ##################################################################
631 # This method returns a boolean to indicate whether a node is a leaf
632 # in the ontology (i.e. it has no children).
633 #
634 # Usage:
635 #
636 # if ($node->isLeaf){
637 #
638 # # blah
639 #
640 # }
641  
642 0 return (!exists $_[0]->{$kChildren});
643  
644 }
645  
646 ##################################################################
647 0 ▶sub isRoot{
Subroutine isRoot: not called CC=1 SCAR=6.9
Pod documented
648 #####################################################################
649 # This method returns a boolean to indicate whether a node is the root
650 # in the ontology (i.e. it has no parents).
651 #
652 # Usage:
653 #
654 # if ($node->isRoot){
655 #
656 # # blah
657 #
658 # }
659  
660 0 return (!exists $_[0]->{$kParents});
661  
662 }
663  
664 =pod
665  
666 =head1 Protected Methods
667  
668 =cut
669  
670 # need to make this code common to all objects, or to
671 # start using something like Params-Validate
672  
673 ############################################################################
674 2 ▶sub _handleMissingArgument{
Subroutine _handleMissingArgument: called CC=2 SCAR=7.2
675 ############################################################################
676 =pod
677  
678 =head2 _handleMissingArgument
679  
680 This protected method simply provides a simple way for concrete
681 subclasses to deal with missing arguments from method calls. It will
682 die with an appropriate error message.
683  
684 Usage:
685  
686 $self->_handleMissingArgument(argument=>'blah');
687  
688 =cut
689 ##############################################################################
690  
691 2 my ($self, %args) = @_;
692  
693 2 ▶ my $arg = $args{'argument'} || $self->_handleMissingArgument(argument=>'argument');
Condition33%1/3
$args{'argument'} || $self->_handleMissingArgument('argument', 'argument')
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{'argument'} || $self->_handleMissingArgument('argument', 'argument')
$args{'argument'} $self->_handleMissingArgument('argument', 'argument')
Truth table33%1/3
A || B
A= $args{'argument'}B= $self->_handleMissingArgument('argument', 'argument')
ABresult
1X1
011
000
694  
695 2 my $receiver = (caller(1))[3];
696 2 my $caller = (caller(2))[3];
697  
698 2 die "The method $caller did not provide a value for the '$arg' argument for the $receiver method";
699  
700 }
701  
702 3 1; # To keep Perl happy
703  
704  
705 __END__
« TermFinderReport/Html.pm ↑ Summary AnnotationProvider/AnnotationParser.pm »