| 1 | package Object::InsideOut; { | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | sub generate_OVERLOAD :Sub(Private) | ||||||||||||||||||||||||||
|
Subroutine
generate_OVERLOAD: called CC=11 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 8 | { | ||||||||||||||||||||||||||||
| 9 | 4 | my ($GBL) = @_; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # Overload specifiers | ||||||||||||||||||||||||||||
| 12 | 4 | my %TYPE = ( | |||||||||||||||||||||||||||
| 13 | 'STRINGIFY' => q/""/, | ||||||||||||||||||||||||||||
| 14 | 'NUMERIFY' => q/0+/, | ||||||||||||||||||||||||||||
| 15 | 'BOOLIFY' => q/bool/, | ||||||||||||||||||||||||||||
| 16 | 'ARRAYIFY' => q/@{}/, | ||||||||||||||||||||||||||||
| 17 | 'HASHIFY' => q/%{}/, | ||||||||||||||||||||||||||||
| 18 | 'GLOBIFY' => q/*{}/, | ||||||||||||||||||||||||||||
| 19 | 'CODIFY' => q/&{}/, | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | my (%code, $code, %meta); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Generate overload strings | ||||||||||||||||||||||||||||
| 25 | 4 | ▶ | while (my $info = shift(@{$$GBL{'sub'}{'ol'}})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 35 | ▶ | if ($$info{'ify'} eq 'EQUATE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | push(@{$code{$$info{'pkg'}}}, "\tq/==/ => sub { (ref(\$_[0]) eq ref(\$_[1])) && (\${\$_[0]} == \${\$_[1]}) },"); | |||||||||||||||||||||||||||
| 28 | } else { | ||||||||||||||||||||||||||||
| 29 | 35 | ▶ | $$info{'name'} ||= sub_name($$info{'code'}, ":$$info{'ify'}", $$info{'loc'}); | ||||||||||||||||||||||||||
|
Condition66%2/3
$info->{"name"} ||= sub_name($info->{"code"}, qq[:$info->{"ify"}], $info->{"loc"})
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, qq[:$info->{"ify"}], $info->{"loc"})
$info->{"name"}
sub_name($info->{"code"}, qq[:$info->{"ify"}], $info->{"loc"})
Truth table66%2/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, qq[:$info->{"ify"}], $info->{"loc"})
| |||||||||||||||||||||||||||||
| 30 | 35 | my $pkg = $$info{'pkg'}; | |||||||||||||||||||||||||||
| 31 | 35 | my $name = $$info{'name'}; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 35 | push(@{$code{$pkg}}, "\tq/$TYPE{$$info{'ify'}}/ => sub { \$_[0]->$name() },"); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 35 | $meta{$pkg}{$name}{'kind'} = 'overload'; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 4 | delete($$GBL{'sub'}{'ol'}); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Generate entire code string | ||||||||||||||||||||||||||||
| 41 | 4 | foreach my $pkg (keys(%code)) { | |||||||||||||||||||||||||||
| 42 | $code .= "package $pkg;\nuse overload (\n" . | ||||||||||||||||||||||||||||
| 43 | 6 | join("\n", @{$code{$pkg}}) . | |||||||||||||||||||||||||||
| 44 | "\n\t'fallback' => 1);\n"; | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Eval the code string | ||||||||||||||||||||||||||||
| 48 | 4 | my @errs; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | local $SIG{'__WARN__'} = sub { push(@errs, @_); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 50 | 3 | ▶ | eval $code; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | if ($@ || @errs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or @errs
MC/DC0%0/2
$@ or @errs
$@
@errs
Truth table33%1/3
A or B
A= $@B= @errs
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my ($err) = split(/ at /, $@ || join(" | ", @errs)); | ||||||||||||||||||||||||||
|
Condition0%0/3
$@ || join(' | ', @errs)
MC/DC0%0/2
$@ || join(' | ', @errs)
$@
join(' | ', @errs)
Truth table0%0/3
A || B
A= $@B= join(' | ', @errs)
| |||||||||||||||||||||||||||||
| 53 | 0 | OIO::Internal->die( | |||||||||||||||||||||||||||
| 54 | 'message' => "Failure creating overloads", | ||||||||||||||||||||||||||||
| 55 | 'Error' => $err, | ||||||||||||||||||||||||||||
| 56 | 'Code' => $code, | ||||||||||||||||||||||||||||
| 57 | 'self' => 1); | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Add accumulated metadata | ||||||||||||||||||||||||||||
| 61 | 4 | add_meta(\%meta); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | foreach my $pkg (keys(%{$$GBL{'tree'}{'td'}})) { | |||||||||||||||||||||||||||
| 66 | # Bless an object into every class | ||||||||||||||||||||||||||||
| 67 | # This works around an obscure 'overload' bug reported against | ||||||||||||||||||||||||||||
| 68 | # Class::Std (http://rt.cpan.org/Public/Bug/Display.html?id=14048) | ||||||||||||||||||||||||||||
| 69 | 14 | bless(\do{ my $scalar; }, $pkg); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Verify that scalar dereferencing is not overloaded in any class | ||||||||||||||||||||||||||||
| 72 | 14 | ▶ | if (exists(${$pkg.'::'}{'(${}'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | (my $file = $pkg . '.pm') =~ s/::/\//g; | |||||||||||||||||||||||||||
| 74 | OIO::Code->die( | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | 'location' => [ $pkg, $INC{$file} || '', '' ], | ||||||||||||||||||||||||||
|
Condition0%0/2
$INC{$file} || ''
MC/DC0%0/1
$INC{$file} || ''
$INC{$file}
Truth table0%0/2
A
A= $INC{$file}
| |||||||||||||||||||||||||||||
| 76 | 'message' => q/Overloading scalar dereferencing '${}' is not allowed/, | ||||||||||||||||||||||||||||
| 77 | 'Info' => q/The scalar of an object is its object ID, and can't be redefined/); | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | } # End of package's lexical scope | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # Ensure correct versioning | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | ($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'
| |||||||||||||||||||||||||||||
| 87 | or die("Version mismatch\n"); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # EOF | ||||||||||||||||||||||||||||