| 1 | package Class::Class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | require 5.005; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | require Pragmatic; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | %Class::Class::BUILT_METHODS = ( ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | @Class::Class::EXPORT_OK = qw (package_exists); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | @Class::Class::ISA = qw(Pragmatic); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Bookkeepping; use our own MEMBERS so that objects inherit this, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # instead of it being global: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | %Class::Class::MEMBERS = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | (__inited => '%', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | __tried_polymorph => '%'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | %Class::Class::PRAGMATA = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | (override_inherited => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub { $Class::Class::OVERRIDE_INHERITED = 1; }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # The package version, both in 1.23 style *and* usable by MakeMaker: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | $Class::Class::VERSION = (substr q$Revision: 1.18 $, 10) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | my $rcs = ' $Id: Class.pm,v 1.18 2000/01/05 16:15:48 binkley Exp $ ' ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | use Carp ( ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | use Class::ISA; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | use Symbol ( ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | BEGIN { $Class::Class::OVERRIDE_INHERITED = 0; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Yes, it's true: I provide a default "new" for you. See the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # documentation (below) for an explanation of this so-called feature. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | ▶ | sub new ($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Why is this here?? --bko FIXME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | my ($this, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | my $class = ref ($this) || $this; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | my $self = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | $self->renew (@args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # This is used to reinitialize objects: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | sub renew ($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
renew: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | return $self->_make_methods->_process_args (@args)->_initialize_parents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Copy an object: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub clone ($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return $self->new ($self, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # NOT a method: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 14 | ▶ | sub package_exists ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package_exists: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 5 | ▶ | no strict qw (refs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 14 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 14 | $class =~ s/^:://o; # catch ::TopLevelPackage | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Start at the root stash: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 14 | my $last = '::'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Look in each successive sub-stash: [NB - the RE there just keeps | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # the :: tacked onto the end of the preceding package label: a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # zero-width positive lookbehind assertion :-] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 14 | for (split /(?<=::)/o, "$class\::") { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 20 | ▶ | return undef unless exists ${$last}{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | $last = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # NB -- This is not (presently) a supported method for Class::Class -- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # as a matter of fact, I consider it quite broken. Why is it here? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Since Class::Class has such intimate knowlege of your classes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # inheritance tree, it was easy for me to implement object changing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # into other objects, a feature I use in a seperate dynamic | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # web-content system. If I get request to support this, I may fix | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # "polymorph" properly: until then, caveat emptor. Double extra so | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # for polyvolve! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Turn into a different class: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | ▶ | sub polymorph ($;$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
polymorph: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | my ($self, $class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Catch ::TopLevelModule: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 8 | $class =~ s/^:://o; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Safe to call with no arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 8 | ▶ | return $self unless $class; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # We've already initialized (I think... ? --bko FIXME), so just | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # upcast ourselves: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | ▶ | return bless $self, $class | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->isa($class) or $self->__tried_polymorph($class)
MC/DC50%1/2
$self->isa($class) or $self->__tried_polymorph($class)
$self->isa($class)
$self->__tried_polymorph($class)
Truth table66%2/3
A or B
A= $self->isa($class)B= $self->__tried_polymorph($class)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | if ($self->isa ($class) or $self->__tried_polymorph ($class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # Save time and effort for next time through (note, we cache this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # even for non-existent classes, just to save the work): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 7 | $self->__tried_polymorph ($class, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | (my $file = $class) =~ s,::,/,go; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 7 | $file .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Limit the scope of the __DIE__ handler by using a block: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Watch out that someone else may have installed a handler ahead | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # of us: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | ▶ | local $SIG{__DIE__} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | ▶ | die $_[0] unless $_[0] =~ /^Can't locate $file in \@INC/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # Since use must have a bareword, carry out it's operations | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # explicitly rather than fall back on eval "use $class". This | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # avoids the overhead of recompiling the string each time: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 7 | eval { require $file; }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Try to setup the class anyway, in case it's defined not in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # it's own separate file, but watch out -- it is just fine to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # have no import method defined; need to be very careful not to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # artificially create a stash for the package where none existed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # before: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | ▶ | $class->import | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&package_exists($class) and $class->can("import")
MC/DC50%1/2
&package_exists($class) and $class->can("import")
&package_exists($class)
$class->can("import")
Truth table66%2/3
A and B
A= &package_exists($class)B= $class->can("import")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | if (package_exists ($class) and $class->can ('import')); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | ▶ | return $self unless package_exists ($class); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | return $self->renew (@args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # This is like polymorph, except that I keep trying until it works, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # stripping off the last ::package name from the target class. Again, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # I use this for a dynamic-content web system. It could go there, but | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # this functionality has nothing to do with web pages. An example to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # illustrate: turn a Fred into a Human::Caveman::Flintstone::Barney, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # else a Human::Caveman::Flintstone, else a Human::Caveman, else a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Human, else return the original Fred. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | sub polyvolve ($;$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
polyvolve: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | my ($self, $class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class ne ref $self and $class =~ s/::[^:]+$//o
MC/DC100%2/2
$class ne ref $self and $class =~ s/::[^:]+$//o
$class ne ref $self
$class =~ s/::[^:]+$//o
Truth table100%3/3
A and B
A= $class ne ref $selfB= $class =~ s/::[^:]+$//o
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | $self = $self->polymorph ($class, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } while ($class ne ref $self and $class =~ s/::[^:]+$//o); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # Yes, it's true: I provide a default DESTROY for you. See the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # documentation (below) for an explanation of this so-called feature. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | ▶ | sub DESTROY ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 2 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Give ourselves a chance to call cleanup code: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | my $glob = ${"$class\::"}{uninitialize}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # This is for the object's package itself defining the method: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $self->unitialize if (defined $glob and defined *{$glob}{CODE}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $glob and defined *{$glob;}{"CODE"}
MC/DC0%0/2
defined $glob and defined *{$glob;}{"CODE"}
defined $glob
defined *{$glob;}{"CODE"}
Truth table33%1/3
A and B
A= defined $globB= defined *{$glob;}{"CODE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | for (keys %{"$class\::MEMBERS"}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Use internal knowlege. This needs fixing for array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # representation: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 14 | ▶ | $self->{$_} = undef if exists $self->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | for my $class (@{"$class\::ISA"}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # Explicity run super DESTROYS so we can handle multiple | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # inheritance: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | $self->DESTROY; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # Make us ourselves again so that we don't try to run more super's | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # DESTROYS: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ### Methods below here are for implementation only -- need to look | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | ### into using arrays instead of hashes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 33 | ▶ | sub add_method ($$$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_method: called CC=13 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 33 | my ($this, $name, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Allowed to call as Fred::Barney->add_method (...): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 33 | ▶ | my $class = ref ($this) || $this; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 33 | my $glob = ${"$class\::"}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 33 | ▶ | if ($type eq '$') { # scalar | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 14 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | (scalar @_ == 2) ? ($_[0]->{$name} = $_[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 33 | ▶ | : ($_[0]->{$name}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } elsif ($type eq '\$') { # scalar reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | (scalar @_ == 2) ? \($_[0]->{$name} = $_[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | : \($_[0]->{$name}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } elsif ($type eq '@') { # array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | *{"$class\::$name"} = sub ($;$$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | (scalar @_ == 3) ? ($_[0]->{$name}[$_[1]] = $_[2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | : (scalar @_ == 2) ? ($_[0]->{$name}[$_[1]]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | ▶ | : ($_[0]->{$name} ||= [ ]); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$_[0]{$name} ||= []
MC/DC0%0/1
$_[0]{$name} ||= []
$_[0]{$name}
Truth table0%0/2
A
A= $_[0]{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } elsif ($type eq '\@') { # array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | *{"$class\::$name"} = sub ($;$$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | (scalar @_ == 3) ? \($_[0]->{$name}[$_[1]] = $_[2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | : (scalar @_ == 2) ? \($_[0]->{$name}[$_[1]]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | : ($_[0]->{$name} ||= [ ]); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$_[0]{$name} ||= []
MC/DC0%0/1
$_[0]{$name} ||= []
$_[0]{$name}
Truth table0%0/2
A
A= $_[0]{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } elsif ($type eq '%') { # hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 9 | ▶ | *{"$class\::$name"} = sub ($;$$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | (scalar @_ == 3) ? ($_[0]->{$name}{$_[1]} = $_[2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | : (scalar @_ == 2) ? ($_[0]->{$name}{$_[1]}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 63 | ▶ | : ($_[0]->{$name} ||= { }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$_[0]{$name} ||= {}
MC/DC0%0/1
$_[0]{$name} ||= {}
$_[0]{$name}
Truth table0%0/2
A
A= $_[0]{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } elsif ($type eq '\%') { # hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | *{"$class\::$name"} = sub ($;$$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | (scalar @_ == 3) ? \($_[0]->{$name}{$_[1]} = $_[2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | : (scalar @_ == 2) ? \($_[0]->{$name}{$_[1]}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | ▶ | : ($_[0]->{$name} ||= { }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$_[0]{$name} ||= {}
MC/DC0%0/1
$_[0]{$name} ||= {}
$_[0]{$name}
Truth table0%0/2
A
A= $_[0]{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } elsif ($type eq '*') { # glob | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | (scalar @_ == 2) ? ($_[0]->{$name} = $_[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | : ($_[0]->{$name} ||= *{Symbol::gensym ( )}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[0]{$name} ||= *{&Symbol::gensym();}
MC/DC0%0/2
$_[0]{$name} ||= *{&Symbol::gensym();}
$_[0]{$name}
*{&Symbol::gensym();}
Truth table0%0/3
A ||= B
A= $_[0]{$name}B= *{&Symbol::gensym();}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } elsif ($type eq '\*') { # glob reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | (scalar @_ == 2) ? \($_[0]->{$name} = $_[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | : \($_[0]->{$name} ||= *{Symbol::gensym ( )}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[0]{$name} ||= *{&Symbol::gensym();}
MC/DC0%0/2
$_[0]{$name} ||= *{&Symbol::gensym();}
$_[0]{$name}
*{&Symbol::gensym();}
Truth table0%0/3
A ||= B
A= $_[0]{$name}B= *{&Symbol::gensym();}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } elsif ($type eq '&') { # coderef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Surpress subroutine redefined and prototype mismatch: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | local $^W = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | ▶ | warn @_ unless $_[0] =~ /^Prototype mismatch:/o; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | (scalar @_ == 2) ? (*{"$class\::$name"} = $_[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | : Carp::croak ("No coderef defined for '$name' yet"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } elsif ($type eq '\&') { # coderef reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 2 | my ($self, $value) = @_; # need lexicals | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | (scalar @_ == 2) ? ($self->{$name} = $value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # Need to do it this way so that we can arrange for $self to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # be at the front of the argument list, as if by magic: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | : (sub { $self->{$name}->($self, @_); }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } elsif ($type =~ /^[^\\]/) { # class (we hope) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | Carp::croak ("Not a class or subclass of '$_[1]'") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[1] and not UNIVERSAL::isa($_[1], $type)
MC/DC0%0/2
defined $_[1] and not UNIVERSAL::isa($_[1], $type)
defined $_[1]
not UNIVERSAL::isa($_[1], $type)
Truth table33%1/3
A and not(B)
A= defined $_[1]B= not UNIVERSAL::isa($_[1], $type)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | if defined $_[1] and not UNIVERSAL::isa ($_[1], $type); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Be super careful -- because of closure tricks, need to use | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # $type->new syntax instead of new $type. (Why? See TC's | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # "indirect object syntax considered harmful" whitepaper.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | (scalar @_ == 2) ? ($_[0]->{$name} = $_[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | ▶ | : ($_[0]->{$name} ||= $type->new); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[0]{$name} ||= $type->new
MC/DC0%0/2
$_[0]{$name} ||= $type->new
$_[0]{$name}
$type->new
Truth table33%1/3
A ||= B
A= $_[0]{$name}B= $type->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } else { # class reference (we hope) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | $type =~ s/^\\//o; # object class is name sans leader | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ▶ | *{"$class\::$name"} = sub ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | ▶ | Carp::croak ("Not a class or subclass of '$_[1]'") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[1] and not UNIVERSAL::isa($_[1], $type)
MC/DC0%0/2
defined $_[1] and not UNIVERSAL::isa($_[1], $type)
defined $_[1]
not UNIVERSAL::isa($_[1], $type)
Truth table33%1/3
A and not(B)
A= defined $_[1]B= not UNIVERSAL::isa($_[1], $type)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | if defined $_[1] and not UNIVERSAL::isa ($_[1], $type); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # Be super careful -- because of closure tricks, need to use | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # $type->new syntax instead of new $type. (Why? See TC's | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # "indirect object syntax considered harmful" whitepaper.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | (scalar @_ == 2) ? \($_[0]->{$name} = $_[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | ▶ | : \($_[0]->{$name} ||= $type->new); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[0]{$name} ||= $type->new
MC/DC0%0/2
$_[0]{$name} ||= $type->new
$_[0]{$name}
$type->new
Truth table33%1/3
A ||= B
A= $_[0]{$name}B= $type->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 33 | return $this; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 6 | ▶ | sub _make_methods ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_methods: called CC=9 SCAR=24.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Build from most derived to least derived order: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 6 | foreach my $class (Class::ISA::self_and_super_path (ref $self)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # Try to avoid fooling around with a parent class which defines | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # MEMBERS but for different purposes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 43 | ▶ | next unless UNIVERSAL::isa ($class, __PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # Check the cache so we don't do this twice: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 31 | ▶ | next if $Class::Class::BUILT_METHODS{$class}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 21 | for my $key (keys %{"$class\::MEMBERS"}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # Careful not to override user-defined access methods: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 33 | ▶ | if ($Class::Class::OVERRIDE_INHERITED) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # This is for the object's package itself defining the method: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $glob = ${"$class\::"}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | next if (defined $glob and defined *{$glob}{CODE}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $glob and defined *{$glob;}{"CODE"}
MC/DC0%0/2
defined $glob and defined *{$glob;}{"CODE"}
defined $glob
defined *{$glob;}{"CODE"}
Truth table0%0/3
A and B
A= defined $globB= defined *{$glob;}{"CODE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # This is for inherited methods: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 33 | ▶ | next if $self->can ($key); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 33 | $class->add_method ($key, ${"$class\::MEMBERS"}{$key}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 21 | $Class::Class::BUILT_METHODS{$class} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # Lastly, wire in our DESTROY: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 6 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 6 | *{"$class\::DESTROY"} = \&DESTROY; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 6 | ▶ | sub _process_args ($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_args: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 6 | my $self = shift; # important not to use my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 6 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 6 | ▶ | while (ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | push @args, %{(shift)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Include yourself so you don't delete existing keys: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 6 | %$self = (%$self, @args, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 26 | ▶ | sub _initialize_parents ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initialize_parents: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # To restore my class after initing my parents: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 26 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # Initing is idempotent: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 26 | ▶ | return $self if $self->__inited ($class); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # I'm not inited until after all my parents init, but this breaks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # downcasting via polymorph. Think about this more. --bko FIXME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 21 | $self->__inited ($class, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 21 | for (@{"$class\::ISA"}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 24 | ▶ | next unless UNIVERSAL::isa ($_, __PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # While initializing, self should be the class of the parent so | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # that ISA lookup doesn't check unconstructed subclasses: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 20 | $self = (bless $self, $_)->_initialize_parents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # Check if we've been polymorphed into a subclass already: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 21 | ▶ | bless $self, $class unless UNIVERSAL::isa (ref $self, $class); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 13 | $self = &{"$class\::initialize"} ($self) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 21 | ▶ | if defined &{"$class\::initialize"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 21 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||