| 1 | package Object::InsideOut; { | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Handles :Automethods and foreign inheritance | ||||||||||||||||||||||||||||
| 8 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 9 | { | ||||||||||||||||||||||||||||
| 10 | my ($GBL, @args) = @_; | ||||||||||||||||||||||||||||
| 11 | push(@{$$GBL{'export'}}, 'AUTOLOAD'); | ||||||||||||||||||||||||||||
| 12 | $$GBL{'init'} = 1; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | *Object::InsideOut::AUTOLOAD = sub | ||||||||||||||||||||||||||||
| 15 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=41 SCAR=51.2
| |||||||||||||||||||||||||||||
| 16 | 12 | my $thing = $_[0]; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Extract the class and method names from the fully-qualified name | ||||||||||||||||||||||||||||
| 19 | 12 | my ($class, $method) = our $AUTOLOAD =~ /(.*)::(.*)/; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Handle superclass calls | ||||||||||||||||||||||||||||
| 22 | 12 | my $super; | |||||||||||||||||||||||||||
| 23 | 12 | ▶ | if ($class =~ /::SUPER$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | $class =~ s/::SUPER//; | |||||||||||||||||||||||||||
| 25 | 0 | $super = 1; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 12 | my $heritage = $$GBL{'heritage'}; | |||||||||||||||||||||||||||
| 29 | 12 | my $automethods = $$GBL{'sub'}{'auto'}; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Find a something to handle the method call | ||||||||||||||||||||||||||||
| 32 | 12 | my ($code_type, $code_dir, %code_refs); | |||||||||||||||||||||||||||
| 33 | 12 | foreach my $pkg (@{$$GBL{'tree'}{'bu'}{$class}}) { | |||||||||||||||||||||||||||
| 34 | # Skip self's class if SUPER | ||||||||||||||||||||||||||||
| 35 | 23 | ▶ | if ($super && $class eq $pkg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$super and $class eq $pkg
MC/DC0%0/2
$super and $class eq $pkg
$super
$class eq $pkg
Truth table33%1/3
A and B
A= $superB= $class eq $pkg
| |||||||||||||||||||||||||||||
| 36 | 0 | next; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Check with heritage objects/classes | ||||||||||||||||||||||||||||
| 40 | 23 | ▶ | if (exists($$heritage{$pkg})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 9 | my $objects = $$heritage{$pkg}{'obj'}; | |||||||||||||||||||||||||||
| 42 | 9 | my $classes = $$heritage{$pkg}{'cl'}; | |||||||||||||||||||||||||||
| 43 | 9 | ▶ | if (Scalar::Util::blessed($thing)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 8 | ▶ | if (exists($$objects{$$thing})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | # Check objects | ||||||||||||||||||||||||||||
| 46 | 4 | foreach my $obj (@{$$objects{$$thing}}) { | |||||||||||||||||||||||||||
| 47 | 4 | ▶ | if (my $code = $obj->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 4 | shift; | |||||||||||||||||||||||||||
| 49 | 4 | unshift(@_, $obj); | |||||||||||||||||||||||||||
| 50 | 4 | goto $code; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||
| 54 | # Check classes | ||||||||||||||||||||||||||||
| 55 | 4 | foreach my $pkg (keys(%{$classes})) { | |||||||||||||||||||||||||||
| 56 | 4 | ▶ | if (my $code = $pkg->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 4 | @_ = @_; # Perl 5.8.5 bug workaround | |||||||||||||||||||||||||||
| 58 | 4 | goto $code; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||
| 63 | # Check classes | ||||||||||||||||||||||||||||
| 64 | 1 | foreach my $pkg (keys(%{$classes})) { | |||||||||||||||||||||||||||
| 65 | 1 | ▶ | if (my $code = $pkg->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 1 | shift; | |||||||||||||||||||||||||||
| 67 | 1 | unshift(@_, $pkg); | |||||||||||||||||||||||||||
| 68 | 1 | goto $code; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # Check with Automethod | ||||||||||||||||||||||||||||
| 75 | 14 | ▶ | if (my $automethod = $$automethods{$pkg}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | # Call the Automethod to get a code ref | ||||||||||||||||||||||||||||
| 77 | 4 | local $CALLER::_ = $_; | |||||||||||||||||||||||||||
| 78 | 4 | local $_ = $method; | |||||||||||||||||||||||||||
| 79 | 4 | local $SIG{'__DIE__'} = 'OIO::trap'; | |||||||||||||||||||||||||||
| 80 | 4 | ▶ | if (my ($code, $ctype) = $automethod->(@_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | if (ref($code) ne 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | # Delete defective automethod | ||||||||||||||||||||||||||||
| 83 | 0 | delete($$automethods{$pkg}); | |||||||||||||||||||||||||||
| 84 | # Not a code ref | ||||||||||||||||||||||||||||
| 85 | 0 | OIO::Code->die( | |||||||||||||||||||||||||||
| 86 | 'message' => ':Automethod did not return a code ref', | ||||||||||||||||||||||||||||
| 87 | 'Info' => "NOTICE: The defective :Automethod in package '$pkg' has been DELETED!", | ||||||||||||||||||||||||||||
| 88 | 'Code' => ":Automethod in package '$pkg' invoked for method '$method'"); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 4 | ▶ | if (defined($ctype)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 3 | my ($type, $dir) = $ctype =~ /(\w+)(?:[(]\s*(.*)\s*[)])?/; | |||||||||||||||||||||||||||
| 93 | 3 | ▶ | if ($type && $type =~ /CUM/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type and $type =~ /CUM/i
MC/DC0%0/2
$type and $type =~ /CUM/i
$type
$type =~ /CUM/i
Truth table33%1/3
A and B
A= $typeB= $type =~ /CUM/i
| |||||||||||||||||||||||||||||
| 94 | 3 | ▶ | if ($code_type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 2 | $type = ':Cumulative'; | |||||||||||||||||||||||||||
| 96 | 2 | ▶ | $dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dir and $dir =~ /BOT/i
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir
$dir =~ /BOT/i
Truth table33%1/3
A and B
A= $dirB= $dir =~ /BOT/i
| |||||||||||||||||||||||||||||
| 97 | 2 | ▶ | if ($code_type ne $type || $code_dir ne $dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$code_type ne $type or $code_dir ne $dir
MC/DC0%0/2
$code_type ne $type or $code_dir ne $dir
$code_type ne $type
$code_dir ne $dir
Truth table33%1/3
A or B
A= $code_type ne $typeB= $code_dir ne $dir
| |||||||||||||||||||||||||||||
| 98 | # Mixed types | ||||||||||||||||||||||||||||
| 99 | 0 | my ($pkg2) = keys(%code_refs); | |||||||||||||||||||||||||||
| 100 | 0 | OIO::Code->die( | |||||||||||||||||||||||||||
| 101 | 'message' => 'Inconsistent code types returned by :Automethods', | ||||||||||||||||||||||||||||
| 102 | 'Info' => "Class '$pkg' returned type $type($dir), and class '$pkg2' returned type $code_type($code_dir)"); | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||
| 105 | 1 | $code_type = ':Cumulative'; | |||||||||||||||||||||||||||
| 106 | 1 | ▶ | $code_dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dir and $dir =~ /BOT/i
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir
$dir =~ /BOT/i
Truth table33%1/3
A and B
A= $dirB= $dir =~ /BOT/i
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 3 | $code_refs{$pkg} = $code; | |||||||||||||||||||||||||||
| 109 | 3 | next; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($type && $type =~ /CHA/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type and $type =~ /CHA/i
MC/DC0%0/2
$type and $type =~ /CHA/i
$type
$type =~ /CHA/i
Truth table0%0/3
A and B
A= $typeB= $type =~ /CHA/i
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($code_type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | $type = ':Chained'; | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | $dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dir and $dir =~ /BOT/i
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir
$dir =~ /BOT/i
Truth table0%0/3
A and B
A= $dirB= $dir =~ /BOT/i
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($code_type ne $type || $code_dir ne $dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$code_type ne $type or $code_dir ne $dir
MC/DC0%0/2
$code_type ne $type or $code_dir ne $dir
$code_type ne $type
$code_dir ne $dir
Truth table0%0/3
A or B
A= $code_type ne $typeB= $code_dir ne $dir
| |||||||||||||||||||||||||||||
| 116 | # Mixed types | ||||||||||||||||||||||||||||
| 117 | 0 | my ($pkg2) = keys(%code_refs); | |||||||||||||||||||||||||||
| 118 | 0 | OIO::Code->die( | |||||||||||||||||||||||||||
| 119 | 'message' => 'Inconsistent code types returned by :Automethods', | ||||||||||||||||||||||||||||
| 120 | 'Info' => "Class '$pkg' returned type $type($dir), and class '$pkg2' returned type $code_type($code_dir)"); | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||
| 123 | 0 | $code_type = ':Chained'; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | $code_dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dir and $dir =~ /BOT/i
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir
$dir =~ /BOT/i
Truth table0%0/3
A and B
A= $dirB= $dir =~ /BOT/i
| |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 0 | $code_refs{$pkg} = $code; | |||||||||||||||||||||||||||
| 127 | 0 | next; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Unknown automethod code type | ||||||||||||||||||||||||||||
| 131 | OIO::Code->die( | ||||||||||||||||||||||||||||
| 132 | 0 | 'message' => "Unknown :Automethod code type: $ctype", | |||||||||||||||||||||||||||
| 133 | 'Info' => ":Automethod in package '$pkg' invoked for method '$method'"); | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | ▶ | if ($code_type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | # Mixed types | ||||||||||||||||||||||||||||
| 138 | 0 | my ($pkg2) = keys(%code_refs); | |||||||||||||||||||||||||||
| 139 | 0 | OIO::Code->die( | |||||||||||||||||||||||||||
| 140 | 'message' => 'Inconsistent code types returned by :Automethods', | ||||||||||||||||||||||||||||
| 141 | 'Info' => "Class '$pkg' returned an 'execute immediately' type, and class '$pkg2' returned type $code_type($code_dir)"); | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # Just a one-shot - execute it | ||||||||||||||||||||||||||||
| 145 | 1 | @_ = @_; # Perl 5.8.5 bug workaround | |||||||||||||||||||||||||||
| 146 | 1 | goto $code; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 2 | ▶ | if ($code_type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 1 | ▶ | my $tree = ($code_dir eq 'bottom up') ? $$GBL{'tree'}{'bu'} : $$GBL{'tree'}{'td'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 1 | ▶ | my $code = ($code_type eq ':Cumulative') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | ? create_CUMULATIVE($method, $tree, \%code_refs) | ||||||||||||||||||||||||||||
| 155 | : create_CHAINED($method, $tree, \%code_refs); | ||||||||||||||||||||||||||||
| 156 | 1 | @_ = @_; # Perl 5.8.5 bug workaround | |||||||||||||||||||||||||||
| 157 | 1 | goto $code; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # Failed to AUTOLOAD | ||||||||||||||||||||||||||||
| 161 | 1 | ▶ | my $type = ref($thing) ? 'object' : 'class'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 1 | OIO::Method->die('message' => qq/Can't locate $type method "$method" via package "$class"/); | |||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # Do the original call | ||||||||||||||||||||||||||||
| 167 | @_ = @args; | ||||||||||||||||||||||||||||
| 168 | goto &Object::InsideOut::AUTOLOAD; | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | } # End of package's lexical scope | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # Ensure correct versioning | ||||||||||||||||||||||||||||
| 175 | 5 | ▶ | ($Object::InsideOut::VERSION eq '4.05') | ||||||||||||||||||||||||||
|
Condition50%1/2
$VERSION eq '4.05' || die("Version mismatch\n")
MC/DC0%0/1
$VERSION eq '4.05' || die("Version mismatch\n")
$VERSION eq '4.05'
Truth table50%1/2
A
A= $VERSION eq '4.05'
| |||||||||||||||||||||||||||||
| 176 | or die("Version mismatch\n"); | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # EOF | ||||||||||||||||||||||||||||