| 1 | # Class::EHierarchy -- Base class for hierarchally ordered objects | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # (c) 2017, Arthur Corliss <corliss@digitalmages.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # $Id: lib/Class/EHierarchy.pm, 2.01 2019/05/23 07:29:49 acorliss Exp $ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # This software is licensed under the same terms as Perl, itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # Please see http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Environment definitions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | package Class::EHierarchy; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | ▶ | use 5.008003; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 8 | ($VERSION) = ( q$Revision: 2.01 $ =~ /(\d+(?:\.(\d+))+)/sm ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Ordinal indexes for the @objects element records | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 8 | ▶ | use constant CEH_OREF => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 8 | ▶ | use constant CEH_PID => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 8 | ▶ | use constant CEH_PKG => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | ▶ | use constant CEH_CLASSES => 3; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ▶ | use constant CEH_CREF => 4; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Ordinal indexes for the @properties element records | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | use constant CEH_PATTR => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ▶ | use constant CEH_PNAME => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | use constant CEH_PPKG => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | use constant CEH_PVAL => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # Property attribute masks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | use constant CEH_PATTR_SCOPE => 7; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | ▶ | use constant CEH_PATTR_TYPE => 504; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Property attribute scopes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | ▶ | use constant CEH_PUB => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | ▶ | use constant CEH_RESTR => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | ▶ | use constant CEH_PRIV => 4; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Property attribute types | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | ▶ | use constant CEH_SCALAR => 8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | use constant CEH_ARRAY => 16; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | ▶ | use constant CEH_HASH => 32; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | use constant CEH_CODE => 64; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 8 | ▶ | use constant CEH_REF => 128; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | ▶ | use constant CEH_GLOB => 256; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Property flags | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 8 | ▶ | use constant CEH_NO_UNDEF => 512; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | @EXPORT_OK = qw(CEH_PUB CEH_RESTR CEH_PRIV CEH_SCALAR CEH_ARRAY | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | CEH_HASH CEH_CODE CEH_REF CEH_GLOB CEH_NO_UNDEF _declProperty | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | _declMethod ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | %EXPORT_TAGS = ( all => [@EXPORT_OK] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Module code follows | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Hierarchal code support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Array of object references and metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | my @objects; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Array of recycled IDs availabe for use | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | my @recoveredIDs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 14 | ▶ | sub _dumpObjects { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dumpObjects: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Purpose: Provides a list of objects | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # Returns: List of refs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Usage: @objects = _dumpObjects(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 14 | return map { $$_[CEH_OREF] } grep {defined} @objects; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | ▶ | sub _getID { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getID: called CC=14 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Purpose: Generates and assigns a unique ID to the passed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # object, and initializes the internal records | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Returns: Integer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Usage: $id = _genID(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 24 | ▶ | my $id = @recoveredIDs ? CORE::shift @recoveredIDs : $#objects + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 24 | $$obj = $id; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 24 | $objects[$id] = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 24 | $objects[$id][CEH_CREF] = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 24 | $objects[$id][CEH_CLASSES] = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 24 | $objects[$id][CEH_OREF] = $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 24 | $objects[$id][CEH_PKG] = ref $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 24 | weaken( $objects[$$obj][CEH_OREF] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 24 | ▶ | $id = '0 but true' if $id == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Build object class list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 24 | my ( $isaref, $tclass, $nclass, @classes, $n, $l ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 24 | my $class = ref $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # Get the first level of classes we're subclassed from | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 24 | $isaref = *{"${class}::ISA"}{ARRAY}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 24 | ▶ | $isaref = [] unless defined $isaref; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 24 | foreach $tclass (@$isaref) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 24 | ▶ | CORE::push @classes, $tclass | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tclass ne __PACKAGE__ and "$tclass"->isa(__PACKAGE__)
MC/DC100%2/2
$tclass ne __PACKAGE__ and "$tclass"->isa(__PACKAGE__)
$tclass ne __PACKAGE__
"$tclass"->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= $tclass ne __PACKAGE__B= "$tclass"->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | if $tclass ne __PACKAGE__ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | and "$tclass"->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Now, recurse into parent classes. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 24 | $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 24 | $l = scalar @classes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 24 | ▶ | while ( $n < $l ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | foreach $tclass ( @classes[ $n .. ( $l - 1 ) ] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | $isaref = *{"${tclass}::ISA"}{ARRAY}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | ▶ | $isaref = [] unless defined $isaref; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | foreach $nclass (@$isaref) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | ▶ | CORE::push @classes, $nclass | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$nclass ne __PACKAGE__ and "$nclass"->isa(__PACKAGE__)
MC/DC0%0/2
$nclass ne __PACKAGE__ and "$nclass"->isa(__PACKAGE__)
$nclass ne __PACKAGE__
"$nclass"->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= $nclass ne __PACKAGE__B= "$nclass"->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | if $nclass ne __PACKAGE__ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | and "$nclass"->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | $n = scalar @classes - $l + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | $l = scalar @classes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # Add our current class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 24 | CORE::push @classes, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # Save the list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 24 | foreach (@classes) { _addClass( $obj, $_ ) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 24 | return $id; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 24 | ▶ | sub _delID { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delID: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Purpose: Recovers the ID for re-use while deleting the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # old data structures | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # Usage: _recoverID($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 24 | my $pid = $objects[$$obj][CEH_PID]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 24 | my @children = @{ $objects[$$obj][CEH_CREF] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # Have the parent disown this child | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 24 | ▶ | _disown( $objects[$pid][CEH_OREF], $obj ) if defined $pid; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 24 | ▶ | _disown( $obj, $objects[$_][CEH_OREF] ) if @children; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # Clean up internal data structures | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 24 | $objects[$$obj] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 24 | CORE::push @recoveredIDs, $$obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 397 | ▶ | sub isStale { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isStale: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # Purpose: Checks to see if the object reference is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # stale | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Usage: $rv = $obj->isStale; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 397 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 397 | ▶ | return not( defined $obj | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
defined $obj && defined $objects[$$obj] && defined $objects[$$obj][0] && $obj eq $objects[$$obj][0]
defined $obj and defined $objects[$$obj] and defined $objects[$$obj][0]
defined $obj and defined $objects[$$obj]
MC/DC75%3/4
defined $obj && defined $objects[$$obj] && defined $objects[$$obj][0] && $obj eq $objects[$$obj][0]
defined $obj
defined $objects[$$obj]
defined $objects[$$obj][0]
$obj eq $objects[$$obj][0]
Truth table80%4/5
A and B and C && D
A= defined $objB= defined $objects[$$obj]C= defined $objects[$$obj][0]D= $obj eq $objects[$$obj][0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | and defined $objects[$$obj] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | and defined $objects[$$obj][CEH_OREF] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | and $obj eq $objects[$$obj][CEH_OREF] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 31 | ▶ | sub _addClass { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_addClass: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Purpose: Records a super class for the object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # Usage: $rv = _addClass($obj, $class); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 31 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 31 | my $class = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 31 | CORE::push @{ $objects[$$obj][CEH_CLASSES] }, $class | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | if defined $class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 31 | ▶ | and not grep /^$class$/s, @{ $objects[$$obj][CEH_CLASSES] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and not grep(/^$class$/s, @{$objects[$$obj][3];})
MC/DC0%0/2
defined $class and not grep(/^$class$/s, @{$objects[$$obj][3];})
defined $class
not grep(/^$class$/s, @{$objects[$$obj][3];})
Truth table33%1/3
A and not(B)
A= defined $classB= not grep(/^$class$/s, @{$objects[$$obj][3];})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 31 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 96 | ▶ | sub _getClasses { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getClasses: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Purpose: Returns a list of classes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # Returns: Array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Usage: @classes = _getClasses($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 96 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 96 | return @{ $objects[$$obj][CEH_CLASSES] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 8 | ▶ | sub _adopt { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_adopt: called CC=5 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Purpose: Updates the object records to establish the relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # Usage: $rv = _adopt($parent, @children); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | my @orphans = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 8 | my $child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | foreach $child (@orphans) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 9 | ▶ | next if $child->isStale; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | ▶ | if ( !defined $objects[$$child][CEH_PID] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # Eligible for adoption, record the relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 9 | $objects[$$child][CEH_PID] = $$obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 9 | CORE::push @{ $objects[$$obj][CEH_CREF] }, $child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # Already adopted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if ( $objects[$$child][CEH_PID] != $$obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $@ = "object $$child already adopted by another parent"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # Merge aliases | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 8 | $obj->_mergeAliases; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 8 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 9 | ▶ | sub _disown { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_disown: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Purpose: Severs the relationship between the parent and children | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Usage: $rv = _disown($parent, @children); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 9 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 9 | my @orphans = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 9 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 9 | my ($child); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 9 | foreach $child (@orphans) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 9 | ▶ | if ( defined $objects[$$child][CEH_PID] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $objects[$$child][1] and $objects[$$child][1] == $$obj
MC/DC0%0/2
defined $objects[$$child][1] and $objects[$$child][1] == $$obj
defined $objects[$$child][1]
$objects[$$child][1] == $$obj
Truth table33%1/3
A and B
A= defined $objects[$$child][1]B= $objects[$$child][1] == $$obj
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | and $objects[$$child][CEH_PID] == $$obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # A little alias glue code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 9 | $child->_pruneAliases(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # Emancipate the child | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 9 | $objects[$$child][CEH_PID] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | $objects[$$obj][CEH_CREF] = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 9 | [ grep { $_ != $child } @{ $objects[$$obj][CEH_CREF] } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # More alias glue code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 9 | $child->_mergeAliases(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 9 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | ▶ | sub parent { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # Purpose: Returns a reference to the parent object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # Returns: Object reference/undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # Usage: $ref = $obj->parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | my $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | $@ = 'parent method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | $parent = $objects[$$obj][CEH_PID]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | $parent = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | defined $parent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ? $objects[$parent][CEH_OREF] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 4 | return $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 81 | ▶ | sub children { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # Purpose: Returns a list of child objects | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # Returns: List of object references | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # Usage: @children = $obj->children; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 81 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 81 | my @children; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 81 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | $@ = 'children method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 80 | @children = @{ $objects[$$obj][CEH_CREF] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 81 | return @children; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | ▶ | sub siblings { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
siblings: called CC=4 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # Purpose: Returns a list of siblings | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # Returns: List of object references | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # Usage: @sibling = $obj->siblings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | my $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | $@ = 'siblings method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $parent = $objects[$$obj][CEH_PID]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | $parent = $objects[$parent][CEH_OREF] if defined $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | ▶ | return defined $parent ? $parent->children : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 99 | ▶ | sub root { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # Purpose: Returns the root object of the tree | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # Returns: Object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Usage: $root = $obj->root; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 99 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 99 | my $pid = $objects[$$obj][CEH_PID]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 99 | my $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 99 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | $@ = 'root method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # Walk up the tree until we find an undefined PID | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 98 | $pid = $objects[$$obj][CEH_PID]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 98 | ▶ | while ( defined $pid ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 52 | $parent = $objects[$pid][CEH_OREF]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 52 | $pid = $objects[$$parent][CEH_PID]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # The object is the root if no parent was ever found | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 98 | ▶ | $parent = $obj unless defined $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 99 | return $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 25 | ▶ | sub _getRefById { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getRefById: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # Purpose: Returns an object reference by id from the objects array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # Returns: Reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # Usage: $obj = _getRefById($index); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 25 | my $id = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 25 | ▶ | return defined $id ? $objects[$id][CEH_OREF] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 8 | ▶ | sub adopt { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
adopt: called CC=6 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # Purpose: Formally adopts the children | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # Usage: $rv = $obj->adopt(@children); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 10 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 10 | my @children = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 10 | my $root = $obj->root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 10 | my $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 10 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $@ = 'adopt method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 10 | ▶ | if ( grep { $$obj == $$_ } @children ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | $@ = 'object attempted to adopt itself'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } elsif ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 10 | $root eq $_ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } @children | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 2 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | $@ = 'object attempted to adopt the root'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 2 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } elsif ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 8 | ▶ | !defined or !$_->isa(__PACKAGE__) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && $_->isa(__PACKAGE__)
MC/DC0%0/2
defined $_ && $_->isa(__PACKAGE__)
defined $_
$_->isa(__PACKAGE__)
Truth table33%1/3
A && B
A= defined $_B= $_->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } @children | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $@ = 'non-eligible values passed as children for adoption'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 7 | $rv = _adopt( $obj, @children ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 10 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 4 | ▶ | sub disown { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disown: called CC=4 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # Purpose: Formally adopts the children | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # Usage: $rv = $obj->adopt(@children); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 4 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 4 | my @children = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 4 | my $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 4 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $@ = 'disown method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 4 | ▶ | if ( grep { !defined or !$_->isa(__PACKAGE__) } @children ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_ && $_->isa(__PACKAGE__)
MC/DC0%0/2
defined $_ && $_->isa(__PACKAGE__)
defined $_
$_->isa(__PACKAGE__)
Truth table33%1/3
A && B
A= defined $_B= $_->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $@ = 'non-eligible values passed as children for disowning'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 4 | $rv = _disown( $obj, @children ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 29 | ▶ | sub descendents { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
descendents: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # Purpose: Returns all descendents of the object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # Returns: List of object references | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # Usage: @descendents = $obj->descendents; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 29 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 29 | my ( @children, @descendents, $child ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 29 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | $@ = 'descendents method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 28 | @children = $obj->children; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 28 | ▶ | while (@children) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 22 | $child = CORE::shift @children; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 22 | CORE::push @descendents, $child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 22 | CORE::push @children, $child->children; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 29 | return @descendents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 24 | ▶ | sub _initHierarchy { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initHierarchy: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # Purpose: Initializes the object & class hierarchal data for an object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # Usage: $rv = _initHierarchy($obj, $class, @args); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 24 | my $class = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 24 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 24 | my @classes = _getClasses($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 24 | my ( $rv, $tclass, %classes ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # uniq the class list and save it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 24 | %classes = map { $_ => 0 } @classes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # Begin initialization from the top down | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 24 | foreach $tclass ( reverse @classes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 31 | ▶ | unless ( $classes{$tclass} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # call class _initialize() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | $rv = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 31 | defined *{"${tclass}::_initialize"} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 31 | ▶ | ? &{"${tclass}::_initialize"}( $obj, @args ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # Track each class initialization so we only do | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | # it once | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 31 | $classes{$tclass}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 31 | ▶ | last unless $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 24 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 24 | ▶ | sub _destrHierarchy { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_destrHierarchy: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | # Purpose: Destroys hierarchal data for an object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | # Usage: $rv = _destrHierarchy($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 24 | my @classes = _getClasses($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 24 | my $tclass; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # Attempt to run all the _deconstruct methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 24 | foreach $tclass ( reverse @classes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 8 | &{"${tclass}::_deconstruct"}($obj) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 31 | ▶ | if defined *{"${tclass}::_deconstruct"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # Alias support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # Array of object aliases | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 8 | my @aliases; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # Array of alias maps | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 8 | my @amaps; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 23 | ▶ | sub _initAlias { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initAlias: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # Purpose: Initializes alias data for an object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # Usage: $rv = _initAlias($obj, $alias); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 23 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 23 | my $alias = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # Store the object aliases and initialize a private map | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 23 | $aliases[$$obj] = $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 23 | ▶ | $amaps[$$obj] = defined $alias ? { $alias => $$obj } : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 23 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 24 | ▶ | sub _destrAlias { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_destrAlias: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # Purpose: Destroys alias data for an object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # Usage: $rv = _destrAlias($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 24 | my $alias = $aliases[$$obj]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 24 | my $root = $obj->root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # Remove aliases from root alias map | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | delete $amaps[$$root]{$alias} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 24 | ▶ | if defined $alias and $amaps[$$root]{$alias} == $$obj; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $alias and $amaps[$$root]{$alias} == $$obj
MC/DC50%1/2
defined $alias and $amaps[$$root]{$alias} == $$obj
defined $alias
$amaps[$$root]{$alias} == $$obj
Truth table66%2/3
A and B
A= defined $aliasB= $amaps[$$root]{$alias} == $$obj
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # Clean up object data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 24 | $aliases[$$obj] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 24 | $amaps[$$obj] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 17 | ▶ | sub _mergeAliases { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mergeAliases: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # Purpose: Merges an alias with the family tree alias index | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # Usage: $rv = _mergeAliases($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 17 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 17 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 17 | my ( $child, $alias, $root ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # The alias index is associated with the root of the tree | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 17 | $root = $obj->root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 17 | foreach $child ( $root->descendents ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | # Skip objects without an alias | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 16 | ▶ | next unless defined $aliases[$$child]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # Get the child's private alias index | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 4 | $alias = $aliases[$$child]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # Update the index if the alias is unclaimed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 4 | ▶ | if ( CORE::exists $amaps[$$root]{$alias} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $amaps[$$root]{$alias} and $amaps[$$root]{$alias} != $$child
MC/DC0%0/2
exists $amaps[$$root]{$alias} and $amaps[$$root]{$alias} != $$child
exists $amaps[$$root]{$alias}
$amaps[$$root]{$alias} != $$child
Truth table33%1/3
A and B
A= exists $amaps[$$root]{$alias}B= $amaps[$$root]{$alias} != $$child
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | and $amaps[$$root]{$alias} != $$child ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $@ = "alias name collision: $alias"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 4 | $amaps[$$root]{$alias} = $$child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # Store the child's prefered alias in its private index, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # regardless | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 4 | $amaps[$$child] = { $alias => $$child }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 17 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 9 | ▶ | sub _pruneAliases { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pruneAliases: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # Purpose: Removes all aliases from this object and its descendents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # Usage: $rv = _prunAliases($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 9 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 9 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 9 | my ( $root, $child, $alias ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 9 | $root = $obj->root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 9 | foreach $child ( $obj, $obj->descendents ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | # We never prune aliases from an object's own index for itself | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 11 | ▶ | next if $$child == $$root; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | # Get the alias and remove it from the root's index if the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | # alias if valid and pointing to the child in question | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 11 | $alias = $aliases[$$child]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 11 | ▶ | if ( defined $alias ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | delete $amaps[$$root]{$alias} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | if defined $alias | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 3 | ▶ | and $amaps[$$root]{$alias} == $$child; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $alias and $amaps[$$root]{$alias} == $$child
MC/DC0%0/2
defined $alias and $amaps[$$root]{$alias} == $$child
defined $alias
$amaps[$$root]{$alias} == $$child
Truth table33%1/3
A and B
A= defined $aliasB= $amaps[$$root]{$alias} == $$child
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 9 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 6 | ▶ | sub alias { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alias: called CC=9 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # Purpose: Assigns an alias to an object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # Usage: $rv = $obj->alias($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 6 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 6 | my $alias = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 6 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 6 | my $root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 6 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | $@ = 'alias method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 6 | ▶ | if ( defined $aliases[$$obj] and length $aliases[$$obj] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $aliases[$$obj] and length $aliases[$$obj]
MC/DC50%1/2
defined $aliases[$$obj] and length $aliases[$$obj]
defined $aliases[$$obj]
length $aliases[$$obj]
Truth table66%2/3
A and B
A= defined $aliases[$$obj]B= length $aliases[$$obj]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 2 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 2 | $@ = "object already has an alias: $aliases[$$obj]"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 2 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | ▶ | } elsif ( !defined $alias or !length $alias ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $alias && length $alias
MC/DC0%0/2
defined $alias && length $alias
defined $alias
length $alias
Truth table33%1/3
A && B
A= defined $aliasB= length $alias
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | $@ = 'attempt to assign an invalid alias'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # Get the root and record the alias in the object's private | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # map | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 4 | $root = $obj->root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 4 | $aliases[$$obj] = $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 4 | $amaps[$$obj]{$alias} = $$obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 4 | ▶ | if ( $$root != $$obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # Update the root index | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # Make sure no name collisions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 1 | ▶ | if ( CORE::exists $amaps[$$root]{$alias} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $amaps[$$root]{$alias} and $amaps[$$root]{$alias} != $$obj
MC/DC0%0/2
exists $amaps[$$root]{$alias} and $amaps[$$root]{$alias} != $$obj
exists $amaps[$$root]{$alias}
$amaps[$$root]{$alias} != $$obj
Truth table33%1/3
A and B
A= exists $amaps[$$root]{$alias}B= $amaps[$$root]{$alias} != $$obj
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | and $amaps[$$root]{$alias} != $$obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $@ = "alias name collision: $alias"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 1 | $root = $obj->root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 1 | $amaps[$$root]{$alias} = $$obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 6 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 32 | ▶ | sub getByAlias { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getByAlias: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | # Purpose: Returns an object reference associated with a given name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | # Returns: Reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # Usage: $oref = $obj->getByAlias($alias); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 32 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 32 | my $alias = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 32 | my ( $root, $rv ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 32 | ▶ | if ( $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | $@ = 'getByAlias method called on stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } elsif ( defined $alias ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 31 | $root = $obj->root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | $rv = $amaps[$$root]{$alias} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 31 | ▶ | if CORE::exists $amaps[$$root]{$alias}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 31 | ▶ | $rv = _getRefById($rv) if defined $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 32 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | # Property/Method support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | # Property storage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 8 | my @properties; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 20 | ▶ | sub __declProperty { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__declProperty: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | # Purpose: Creates a named property record with associated meta data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | # Usage: $rv = __declProperty($caller, $obj, $name, $attr); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 20 | my $caller = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 20 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 20 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 20 | my $attr = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | # Prepend package scoping in front of private properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 20 | ▶ | $name = "$caller*$name" if $attr & CEH_PRIV; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # Apply default attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 20 | ▶ | $attr |= CEH_SCALAR | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | unless ( $attr ^ CEH_PATTR_TYPE ) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 20 | ▶ | $attr |= CEH_PUB | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | unless ( $attr ^ CEH_PATTR_SCOPE ) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | # Save the properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 20 | ${ $properties[$$obj] }{$name} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 20 | ${ $properties[$$obj] }{$name}[CEH_PATTR] = $attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 20 | ${ $properties[$$obj] }{$name}[CEH_PPKG] = $caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 20 | ▶ | ${ $properties[$$obj] }{$name}[CEH_PVAL] = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | $attr & CEH_ARRAY ? [] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | : $attr & CEH_HASH ? {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 1 | ▶ | sub _declProperty { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_declProperty: called CC=4 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # Purpose: Creates a named property record with associated meta data. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # This is the public function available for use by | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | # subclasses | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | # Usage: $rv = _declProperty($obj, $name, $attr); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 1 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 1 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 1 | my $attr = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 1 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 1 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 1 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 1 | ▶ | if ( defined $name and length $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 1 | $rv = __declProperty( $caller, $obj, $name, $attr ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | $@ = '_declProperty function called with an invalid property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | $@ = '_declProperty function called with a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 1 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 90 | ▶ | sub _gatekeeper { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gatekeeper: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # Purpose: Checks for a valid property name, and checks ACLs for the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # caller | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | # Returns: Property name if allowed, undef otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # Usage: $name = $obj->gatekeeper($caller, $name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 90 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 90 | my $caller = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 90 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 90 | my ( $rv, $class, $cscope, $pscope ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 90 | ▶ | if ( defined $name and length $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | # Check scope and adjust for privately scoped properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | $name = "$caller*$name" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 90 | ▶ | if CORE::exists $properties[$$obj]{"$caller*$name"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 90 | ▶ | if ( CORE::exists $properties[$$obj]{$name} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # Get the property's class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 85 | $class = $properties[$$obj]{$name}[CEH_PPKG]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | # Get the property's scope | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | $pscope = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 85 | $properties[$$obj]{$name}[CEH_PATTR] & CEH_PATTR_SCOPE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | # Get the caller's scope | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 85 | ▶ | $cscope = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | $caller eq $class ? CEH_PRIV | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | : "$caller"->isa($class) ? CEH_RESTR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | : CEH_PUB; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # Set the values if allowed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 85 | ▶ | if ( $cscope >= $pscope ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 81 | $rv = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 4 | $@ = 'property access violation'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 4 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 5 | $@ = 'method called with an nonexistent property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 5 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | $@ = 'method called with an invalid property name'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 90 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 31 | ▶ | sub _setProperty { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setProperty: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | # Purpose: Sets the named property to the passed values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | # Usage: $rv = $obj->_setProperty($name, @values); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 31 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 31 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 31 | my @val = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 31 | my ( $rv, $ptype, $pundef, $pref ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | # Get some meta data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 31 | $ptype = ${ $properties[$$obj] }{$name}[CEH_PATTR] & CEH_PATTR_TYPE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 31 | $pundef = ${ $properties[$$obj] }{$name}[CEH_PATTR] & CEH_NO_UNDEF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 31 | ▶ | if ( $ptype != CEH_ARRAY and $ptype != CEH_HASH ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ptype != 16 and $ptype != 32
MC/DC100%2/2
$ptype != 16 and $ptype != 32
$ptype != 16
$ptype != 32
Truth table100%3/3
A and B
A= $ptype != 16B= $ptype != 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 25 | $pref = ref $val[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | # Check for undef restrictions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 25 | ▶ | $rv = 1 if !$pundef or defined $val[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $pundef or defined $val[0]
MC/DC100%2/2
not $pundef or defined $val[0]
not $pundef
defined $val[0]
Truth table100%3/3
not(A) or B
A= not $pundefB= defined $val[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 25 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # Check types for correctness | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 24 | ▶ | $rv = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | ( !defined $val[0] ) ? 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | : $ptype == CEH_SCALAR ? ( $pref eq '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | : $ptype == CEH_CODE ? ( $pref eq 'CODE' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | : $ptype == CEH_GLOB ? ( $pref eq 'GLOB' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | : $ptype == CEH_REF ? ( length $pref ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 24 | $@ = "data type mismatch for $name"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 24 | ▶ | carp $@ unless $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | # No validation for array/hash types | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 6 | $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | # Assign the value(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 31 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 26 | ▶ | if ( $ptype == CEH_ARRAY ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 3 | ${ $properties[$$obj] }{$name}[CEH_PVAL] = [@val]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | } elsif ( $ptype == CEH_HASH ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 3 | ${ $properties[$$obj] }{$name}[CEH_PVAL] = {@val}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 20 | ${ $properties[$$obj] }{$name}[CEH_PVAL] = $val[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 31 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 24 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | # Purpose: Sets the named properties to the passed value(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | # Usage: $rv = $obj->set($name, @values); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 24 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 24 | my @val = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 24 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 24 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 24 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 24 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 24 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 24 | $rv = $obj->_setProperty( $name, @val ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | $@ = 'set method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 24 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 38 | ▶ | sub _getProperty { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getProperty: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | # Purpose: Gets the named property's value(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | # Returns: Scalar, Array, Hash, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | # Usage: @rv = $obj->getProperty($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 38 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 38 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 38 | my ( @rv, $ptype ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | # Get some meta data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 38 | $ptype = $properties[$$obj]{$name}[CEH_PATTR] & CEH_PATTR_TYPE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | # Retrieve the content | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | @rv = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 6 | ▶ | $ptype == CEH_HASH ? %{ $properties[$$obj]{$name}[CEH_PVAL] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 6 | : $ptype == CEH_ARRAY ? @{ $properties[$$obj]{$name}[CEH_PVAL] } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 38 | ▶ | : ( $properties[$$obj]{$name}[CEH_PVAL] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 38 | ▶ | $ptype == CEH_HASH ? @rv | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | : $ptype == CEH_ARRAY ? @rv | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | : $rv[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 47 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | # Purpose: Gets the named property's value(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | # Returns: Scalar, Array, Hash, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | # Usage: @rv = $obj->get($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 47 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 47 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 47 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 47 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 47 | ▶ | if ( !$obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 47 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 47 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 38 | @rv = $obj->_getProperty($name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | $@ = 'set method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 47 | ▶ | return wantarray ? @rv : $rv[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 3 | ▶ | sub push { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | # Purpose: Performs a push operation on an array property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | # Returns: RV of CORE::push or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | # Usage: $rv = $obj->push($name, @values); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 3 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 3 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 3 | my @val = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 3 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 3 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 3 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 3 | $rv = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 3 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 3 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 3 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 3 | $rv = CORE::push @{ $properties[$$obj]{$name}[CEH_PVAL] }, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | @val; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | $@ = 'push attempted on a non-array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 0 | $@ = 'push method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 3 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 1 | ▶ | sub pop { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pop: called CC=4 SCAR=15.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | # Purpose: Performs a pop operation on an array property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | # Returns: RV of CORE::pop or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | # Usage: $rv = $obj->pop($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 1 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 1 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 1 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 1 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 1 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 1 | $rv = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 1 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 1 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 1 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1 | $rv = CORE::pop @{ $properties[$$obj]{$name}[CEH_PVAL] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | $@ = 'pop attempted on a non-array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | $@ = 'pop method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 1 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 3 | ▶ | sub unshift { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unshift: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | # Purpose: Performs an unshift operation on an array property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | # Returns: RV of CORE::unshift or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | # Usage: $rv = $obj->unshift($name, @values); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 3 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 3 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 3 | my @val = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 3 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 3 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 3 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 3 | $rv = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 3 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 3 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 3 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | $rv = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 3 | CORE::unshift @{ $properties[$$obj]{$name}[CEH_PVAL] | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | @val; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | $@ = 'unshift attempted on a non-array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 0 | $@ = 'unshift method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 3 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 1 | ▶ | sub shift { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shift: called CC=4 SCAR=15.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | # Purpose: Performs a shift operation on an array property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | # Returns: RV of CORE::shift or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | # Usage: $rv = $obj->shift($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 1 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 1 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 1 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 1 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 1 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 1 | $rv = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 1 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 1 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 1 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | $rv = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 1 | CORE::shift @{ $properties[$$obj]{$name}[CEH_PVAL] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | $@ = 'shift attempted on a non-array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | $@ = 'shift method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 1 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 2 | ▶ | sub exists { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=4 SCAR=15.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | # Purpose: Performs an exists operation on a hash property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | # Returns: RV of CORE::exists or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | # Usage: $rv = $obj->exists($name, $key); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 2 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | 2 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 2 | my $key = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 2 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 2 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 2 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 2 | $rv = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 2 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 2 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 2 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | $rv = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | CORE::exists $properties[$$obj]{$name}[CEH_PVAL] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 2 | {$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 0 | $@ = 'exists attempted on a non-hash property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 0 | $@ = 'exists method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 2 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 1 | ▶ | sub keys { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | # Purpose: Performs a keys operation on a hash property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | # Returns: RV of CORE::keys or empty array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | # Usage: $rv = $obj->keys($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 1 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 1 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 1 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 1 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 1 | ▶ | if ( !$obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 1 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 1 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 1 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 1 | @rv = CORE::keys %{ $properties[$$obj]{$name}[CEH_PVAL] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 0 | $@ = 'keys attempted on a non-hash property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | $@ = 'keys method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 1 | return @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 2 | ▶ | sub merge { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | # Purpose: Merges the specified ordinal or associated records into | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | # the named property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | # Usage: $rv = $obj->merge($name, 'foo' => 'bar'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | # Usage: $rv = $obj->merge($name, 1 => 'bar'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 2 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 2 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 2 | my %updates = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 2 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 2 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 2 | my ( $k, $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 2 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 2 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 2 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 2 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 1 | ▶ | while ( ( $k, $v ) = each %updates ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 3 | $properties[$$obj]{$name}[CEH_PVAL][$k] = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | } elsif ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 1 | ▶ | while ( ( $k, $v ) = each %updates ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 2 | $properties[$$obj]{$name}[CEH_PVAL]{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | $@ = 'merge attempted on a non-hash/array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 0 | $@ = 'merge method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 2 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 2 | ▶ | sub subset { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subset: called CC=9 SCAR=23.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | # Purpose: Returns the associated or ordinal values from the named | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | # property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | # Returns: Array of values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | # Usage: @values = $obj->subset($name, qw(foo bar)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | # Usage: @values = $obj->subset($name, 1, 7); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 2 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 2 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 2 | my @keys = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 2 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 2 | my ( @rv, $k, $l ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 2 | ▶ | if ( !$obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 2 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 2 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 2 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 1 | $l = $#{ $properties[$$obj]{$name}[CEH_PVAL] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 1 | foreach $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | CORE::push @rv, ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | $k <= $l | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | 4 | ▶ | ? $properties[$$obj]{$name}[CEH_PVAL][$k] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | : undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | } elsif ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 1 | foreach $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | CORE::push @rv, ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | CORE::exists $properties[$$obj]{$name}[CEH_PVAL] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | {$k} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 2 | ▶ | ? $properties[$$obj]{$name}[CEH_PVAL]{$k} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | : undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | $@ = 'subset attempted on a non-hash/array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 0 | $@ = 'subset method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 2 | return @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 2 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=8 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | # Purpose: Removes the ordinal or associated values from the named | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | # property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | # Usage: $rv = $obj->remove($name, qw(foo bar)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | # Usage: $rv = $obj->remove($name, 5, 8); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 2 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 2 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 2 | my @keys = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 2 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 2 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | 2 | my ( $k, $l ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 2 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 2 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 2 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 2 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 1 | $l = $#{ $properties[$$obj]{$name}[CEH_PVAL] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 1 | foreach $k ( sort { $b <=> $a } @keys ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 3 | ▶ | splice @{ $properties[$$obj]{$name}[CEH_PVAL] }, $k, 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | unless $k > $l; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | } elsif ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 1 | foreach $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 2 | delete $properties[$$obj]{$name}[CEH_PVAL]{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 0 | $@ = 'remove attempted on a non-hash/array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 0 | $@ = 'remove method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 2 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 2 | ▶ | sub empty { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
empty: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | # Purpose: Empties the named array or hash property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | # Usage: $rv = $obj->empty($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 2 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 2 | my $name = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | 2 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 2 | my $rv = !$obj->isStale; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 2 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 2 | $name = $obj->_gatekeeper( $caller, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 2 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 2 | ▶ | if ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 1 | @{ $properties[$$obj]{$name}[CEH_PVAL] } = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | } elsif ( ref $properties[$$obj]{$name}[CEH_PVAL] eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 1 | %{ $properties[$$obj]{$name}[CEH_PVAL] } = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | $@ = 'empty attempted on a non-hash/array property'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 0 | $@ = 'empty method called on a stale object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 2 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 3 | ▶ | sub properties { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
properties: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | # Purpose: Returns a list of property names visible to the caller | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | # Returns: Array of scalars | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | # Usage: @names = $obj->properties; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 3 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 3 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 3 | my @pnames = CORE::keys %{ $properties[$$obj] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 3 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | # Populate with all the public properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | @rv = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 3 | grep { $properties[$$obj]{$_}[CEH_PATTR] & CEH_PUB } @pnames; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | # Add restricted properties if the caller is a subclass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 3 | ▶ | if ( $caller eq ref $obj | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$caller eq ref $obj or "$caller"->isa($obj)
MC/DC50%1/2
$caller eq ref $obj or "$caller"->isa($obj)
$caller eq ref $obj
"$caller"->isa($obj)
Truth table66%2/3
A or B
A= $caller eq ref $objB= "$caller"->isa($obj)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | or "$caller"->isa($obj) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | CORE::push @rv, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 2 | grep { $properties[$$obj]{$_}[CEH_PATTR] & CEH_RESTR } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | @pnames; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | # Add private properties if the caller is the same class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 3 | ▶ | if ( $caller eq ref $obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | 2 | foreach ( grep /^\Q$caller*\E/s, @pnames ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | 2 | CORE::push @rv, $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | 2 | $rv[$#rv] =~ s/^\Q$caller*\E//s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 3 | return @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 24 | ▶ | sub _initProperties { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initProperties: called CC=12 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | # Purpose: Initializes the property data for the object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | # Usage: $rv = _initProperties($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 24 | my @classes = _getClasses($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 24 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 24 | my ( $class, @_properties, $prop, $pattr, $pscope, $pname ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | # Initialize storage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 24 | $properties[$$obj] = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | # Load properties from top of class hierarchy down | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 24 | foreach $class (@classes) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | # Get the contents of the class array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | @_properties = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 31 | defined *{"${class}::_properties"} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 31 | ▶ | ? @{ *{"${class}::_properties"}{ARRAY} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | # Process the list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | 31 | foreach $prop (@_properties) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | 19 | ▶ | next unless defined $prop; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | 19 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | __declProperty( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | $class, $obj, @$prop[ CEH_PNAME, CEH_PATTR ] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | # Set the default values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 19 | ▶ | if ( $rv and defined $$prop[CEH_PVAL] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rv and defined $prop->[2]
MC/DC50%1/2
$rv and defined $prop->[2]
$rv
defined $prop->[2]
Truth table66%2/3
A and B
A= $rvB= defined $prop->[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | # Get the attribute type, scope, and internal prop name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 7 | $pattr = $$prop[CEH_PATTR] & CEH_PATTR_TYPE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | 7 | $pscope = $$prop[CEH_PATTR] & CEH_PATTR_SCOPE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 7 | ▶ | $pname = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | $pscope == CEH_PRIV | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | ? "${class}::$$prop[CEH_PNAME]" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | : $$prop[CEH_PNAME]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | # Store the default values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | $rv = $obj->_setProperty( $pname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 1 | ▶ | $pattr == CEH_ARRAY ? @{ $$prop[CEH_PVAL] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 7 | ▶ | : $pattr == CEH_HASH ? %{ $$prop[CEH_PVAL] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | : $$prop[CEH_PVAL] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 19 | ▶ | last unless $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 24 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 24 | ▶ | sub _destrProperties { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_destrProperties: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | # Purpose: Destroys the object's property data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | # Usage: $rv = _destrProperties($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 24 | $properties[$$obj] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 8 | my %classes; # Class => 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | 8 | my %methods; # Class::Method => 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 9 | ▶ | sub __declMethod { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__declMethod: called CC=10 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | # Purpose: Registers a list of methods as scoped | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | # Usage: $rv = __declMethod($class, $attr, $methods); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 9 | my $pkg = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | 9 | my $attr = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 9 | my $method = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 9 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | 9 | my ( $code, $mfqn ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | 9 | ▶ | if ( defined $attr and defined $method and length $method ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $attr and defined $method and length $method
defined $attr and defined $method
MC/DC0%0/3
defined $attr and defined $method and length $method
defined $attr
defined $method
length $method
Truth table25%1/4
A and B and C
A= defined $attrB= defined $methodC= length $method
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | # Quiet some warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 8 | ▶ | no warnings qw(redefine prototype); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | # Get the fully qualified method name and associated code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | # block | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | 9 | $mfqn = "${pkg}::${method}"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | 9 | $code = *{$mfqn}{CODE}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | # Quick check to see if we've done this already -- if so | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | # we skip to the next | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | 9 | ▶ | return 1 if CORE::exists $methods{$mfqn}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | 6 | ▶ | if ( defined $code ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | # Repackage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | 6 | ▶ | if ( $attr == CEH_PRIV ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | # Private methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | 2 | ▶ | *{$mfqn} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 5 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 5 | ▶ | goto &{$code} if $caller eq $pkg; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | 3 | $@ = 'Attempted to call private method ' | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | . "$method from $caller"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | 3 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | } elsif ( $attr == CEH_RESTR ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | # Restricted methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | 2 | ▶ | *{$mfqn} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | 5 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | 5 | ▶ | goto &{$code} if "$caller"->isa($pkg); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 2 | $@ = 'Attempted to call restricted method ' | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | . "$method from $caller"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 2 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | } elsif ( $attr == CEH_PUB ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | # Do nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 0 | $@ = 'invalid method declaration'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | # Record our handling of this method | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | 6 | ▶ | $methods{$mfqn} = 1 if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | 0 | $@ = 'invalid method declaration'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | 6 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | 6 | ▶ | sub _declMethod { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_declMethod: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | # Purpose: Wrapper for __declMethod, this is the public interface | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | # Returns: RV of __declMethod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | # Usage: $rv = _declMethod($attr, @propNames); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | 6 | my $attr = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | 6 | my $method = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | 6 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | 6 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | 6 | ▶ | if ( defined $method and length $method ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $method and length $method
MC/DC0%0/2
defined $method and length $method
defined $method
length $method
Truth table33%1/3
A and B
A= defined $methodB= length $method
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | 6 | $rv = __declMethod( $caller, $attr, $method ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | 0 | $@ = '_declMethod function called with an invalid method'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | 0 | carp $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | 6 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 24 | ▶ | sub _initMethods { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initMethods: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | # Purpose: Loads methods from @_methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | # Usage: $rv = _loadMethods(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | 24 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | 24 | my @classes = _getClasses($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | 24 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | 24 | my ( $class, @_methods, $method ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | # Load methods from the top of the class hierarchy down | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | 24 | foreach $class (@classes) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | # Skip if the class has already been processed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | 31 | ▶ | next if CORE::exists $classes{$class}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | # Get the contents of the class array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | 1 | @_methods = @{ *{"${class}::_methods"}{ARRAY} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | 11 | ▶ | if defined *{"${class}::_methods"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | # Process the list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 11 | foreach $method (@_methods) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | 3 | ▶ | next unless defined $method; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | 3 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | __declMethod( $class, @$method[ CEH_PATTR, CEH_PPKG ] ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | 0 | $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | # Mark the class as processed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | 11 | $classes{$class} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | 24 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | # Class Constructors/Destructors | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | 8 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | # Purpose: Class constructor for all (sub)classes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | # Returns: Reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | # Usage: $obj = new SUBCLASS; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | 23 | my $class = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | 23 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | 23 | my $obj = bless \do { my $anon_scalar }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 23 | my $rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | # Get the next available ID | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | 23 | $rv = _getID($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | # Initialize alias support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | 23 | ▶ | $rv = _initAlias($obj) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | # Initialize property scope support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | 23 | ▶ | $rv = _initProperties($obj) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | # Initialize method scope support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | 23 | ▶ | $rv = _initMethods($obj) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | # Initialize the hierarchal code support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | 23 | ▶ | $rv = _initHierarchy( $obj, $class, @args ) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | 23 | ▶ | return $rv ? $obj : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | 1 | ▶ | sub conceive { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
conceive: called CC=8 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | # Purpose: Same as new() but with hierarchal relationships pre-installed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | # Returns: Reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | # Usage: SubClass->conceive($parent, @args); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | 1 | my $class = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | 1 | my $pobj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | 1 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | 1 | my $obj = bless \do { my $anon_scalar }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | 1 | my $rv = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | # Get the next available ID | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | 1 | ▶ | $rv = _getID($obj) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | # Adopt the object before we do anything else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | 1 | ▶ | $rv = $pobj->_adopt($obj) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | # Initialize property scope support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | 1 | ▶ | $rv = _initProperties($obj) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | # Initialize method scope support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | 1 | ▶ | $rv = _initMethods($obj) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | # Initialize the hierarchal code support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | 1 | ▶ | $rv = _initHierarchy( $obj, $class, @args ) if $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | # Disown the object if we've failed initialization | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | 1 | ▶ | $pobj->_disown($obj) unless $rv; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | 1 | ▶ | return $rv ? $obj : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | 30 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | # Purpose: Garbage collection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | # Returns: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | # Usage: $obj->DESTROY(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | 30 | my $obj = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | 30 | my ( $class, @classes ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | # Test to see if this is a stale reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | 30 | ▶ | unless ( !defined $$obj or $obj->isStale ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $$obj or $obj->isStale
MC/DC50%1/2
not defined $$obj or $obj->isStale
not defined $$obj
$obj->isStale
Truth table66%2/3
not(A) or B
A= not defined $$objB= $obj->isStale
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | # Destroy from the top of the tree down | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | 24 | ▶ | foreach ( $obj->children ) { $_->DESTROY if defined } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | # Execute hierarchal destructors | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | 24 | _destrHierarchy($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | # Destroy aliases | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | 24 | _destrAlias($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | # Destroy properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | 24 | _destrProperties($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | # Recover the ID | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 24 | _delID($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | 30 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | 6 | ▶ | END { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=3 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | 0 | ▶ | foreach ( _dumpObjects() ) { $_->DESTROY if defined } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||