| 1 | package perl5i::1::Meta; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # Be very careful not to import anything. | ||||||||||||||||||||||||||||
| 7 | 1 | require Carp; | |||||||||||||||||||||||||||
| 8 | 1 | require mro; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | require perl5i::1::Meta::Instance; | |||||||||||||||||||||||||||
| 11 | 1 | require perl5i::1::Meta::Class; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub UNIVERSAL::mo { | ||||||||||||||||||||||||||||
| 14 | return perl5i::1::Meta->new($_[0]); | ||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub new { | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my($class, $thing) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | return bless \$thing, ref $thing ? "perl5i::1::Meta::Instance" : "perl5i::1::Meta::Class"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub ISA { | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $class = $_[0]->class; | ||||||||||||||||||||||||||
|
Subroutine
ISA: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 0 | return @{$class.'::ISA'}; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub linear_isa { | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
linear_isa: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | my $class = $self->class; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # get_linear_isa() does not return UNIVERSAL | ||||||||||||||||||||||||||||
| 34 | 0 | my @extra; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | @extra = qw(UNIVERSAL) unless $class eq 'UNIVERSAL'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return @{mro::get_linear_isa($class)}, @extra; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # A single place to put the "method not found" error. | ||||||||||||||||||||||||||||
| 42 | my $method_not_found = sub { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | 0 | my $method = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | Carp::croak sprintf q[Can't locate object method "%s" via package "%s"], | |||||||||||||||||||||||||||
| 47 | $method, $class; | ||||||||||||||||||||||||||||
| 48 | 1 | }; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # caller() will return if its inside an eval, need to skip over those. | ||||||||||||||||||||||||||||
| 52 | my $find_method = sub { | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $method; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 54 | 0 | my $height = 2; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $method or $method ne "(eval)"
MC/DC0%0/2
not defined $method or $method ne "(eval)"
not defined $method
$method ne "(eval)"
Truth table0%0/3
not(A) or B
A= not defined $methodB= $method ne "(eval)"
| |||||||||||||||||||||||||||||
| 56 | 0 | $method = (caller($height))[3]; | |||||||||||||||||||||||||||
| 57 | 0 | $height++; | |||||||||||||||||||||||||||
| 58 | } until( !defined $method or $method ne '(eval)' ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return $method; | |||||||||||||||||||||||||||
| 61 | 1 | }; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub super { | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
super: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 0 | my $class = $self->class; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $fq_method = $find_method->(); | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | Carp::croak "super() called outside a method" unless $fq_method; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my($parent, $method) = $fq_method =~ /^(.*)::(\w+)$/; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | Carp::croak sprintf qq["%s" is not a parent class of "%s"], $parent, $class | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | unless $class->isa($parent); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my @isa = $self->linear_isa(); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | while(@isa) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | my $class = shift @isa; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | last if $class eq $parent; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | for (@isa) { | |||||||||||||||||||||||||||
| 84 | 0 | my $code = $_->can($method); | |||||||||||||||||||||||||||
| 85 | 0 | @_ = ($$self, @_); | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | goto &$code if $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $class->$method_not_found($method); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | 1; | |||||||||||||||||||||||||||