| 1 | package perl5i::2::Meta; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 109 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 109 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 109 | ▶ | use 5.010_000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Be very careful not to import anything. | ||||||||||||||||||||||||||||
| 8 | 109 | require Carp::Fix::1_25; | |||||||||||||||||||||||||||
| 9 | 109 | require mro; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 109 | require perl5i::2::Meta::Instance; | |||||||||||||||||||||||||||
| 12 | 109 | require perl5i::2::Meta::Class; | |||||||||||||||||||||||||||
| 13 | 109 | ▶ | use perl5i::2::autobox; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub UNIVERSAL::mo { | ||||||||||||||||||||||||||||
| 16 | # Be careful to pass through an alias, not a copy | ||||||||||||||||||||||||||||
| 17 | 210 | ▶ | return perl5i::2::Meta::Instance->new($_[0]); | ||||||||||||||||||||||||||
|
Subroutine
mo: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub UNIVERSAL::mc { | ||||||||||||||||||||||||||||
| 21 | 30 | ▶ | return perl5i::2::Meta::Class->new($_[0]); | ||||||||||||||||||||||||||
|
Subroutine
mc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub new { | ||||||||||||||||||||||||||||
| 25 | 240 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | # Be careful to take a reference to an alias, not a copy | ||||||||||||||||||||||||||||
| 27 | 240 | return bless \\$_[0], $class; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub ISA { | ||||||||||||||||||||||||||||
| 31 | 6 | ▶ | my $class = $_[0]->class; | ||||||||||||||||||||||||||
|
Subroutine
ISA: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 109 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 6 | ▶ | return wantarray ? @{$class.'::ISA'} : \@{$class.'::ISA'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub linear_isa { | ||||||||||||||||||||||||||||
| 38 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
linear_isa: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 13 | my $class = $self->class; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # get_linear_isa() does not return UNIVERSAL | ||||||||||||||||||||||||||||
| 42 | 13 | my @extra; | |||||||||||||||||||||||||||
| 43 | 13 | ▶ | @extra = qw(UNIVERSAL) unless $class eq 'UNIVERSAL'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 13 | my $isa = [@{mro::get_linear_isa($class)}, @extra]; | |||||||||||||||||||||||||||
| 46 | 13 | ▶ | return wantarray ? @$isa : $isa; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub methods { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
methods: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $opts = shift // {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() // {}
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 52 | 0 | my $top = $self->class; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my %exclude; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | state $defaults = { | |||||||||||||||||||||||||||
| 57 | with_UNIVERSAL => 0, | ||||||||||||||||||||||||||||
| 58 | just_mine => 0, | ||||||||||||||||||||||||||||
| 59 | }; | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | $opts = { %$defaults, %$opts }; | |||||||||||||||||||||||||||
| 62 | 0 | $exclude{UNIVERSAL} = !$opts->{with_UNIVERSAL}; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my @classes = $opts->{just_mine} ? $self->class : $self->linear_isa; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my %all_methods; | |||||||||||||||||||||||||||
| 67 | 0 | for my $class (@classes) { | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | next if $exclude{$class} && $class ne $top; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$exclude{$class} and $class ne $top
MC/DC0%0/2
$exclude{$class} and $class ne $top
$exclude{$class}
$class ne $top
Truth table0%0/3
A and B
A= $exclude{$class}B= $class ne $top
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my $sym_table = $class->mc->symbol_table; | |||||||||||||||||||||||||||
| 71 | 0 | for my $name (keys %$sym_table) { | |||||||||||||||||||||||||||
| 72 | 0 | my $glob = $sym_table->{$name}; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | next unless ref \$glob eq "GLOB"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | next unless my $code = *{$glob}{CODE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | my $sig = $code->signature; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | next if $sig and !$sig->is_method; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sig and not $sig->is_method
MC/DC0%0/2
$sig and not $sig->is_method
$sig
not $sig->is_method
Truth table0%0/3
A and not(B)
A= $sigB= not $sig->is_method
| |||||||||||||||||||||||||||||
| 77 | 0 | $all_methods{$name} = $class; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | return wantarray ? keys %all_methods : [keys %all_methods]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub symbol_table { | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
symbol_table: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 1 | my $class = $self->class; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 109 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 1 | return \%{$class.'::'}; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # A single place to put the "method not found" error. | ||||||||||||||||||||||||||||
| 93 | my $method_not_found = sub { | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 95 | 0 | my $method = shift; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | Carp::Fix::1_25::croak( | |||||||||||||||||||||||||||
| 98 | sprintf q[Can't locate object method "%s" via package "%s"], | ||||||||||||||||||||||||||||
| 99 | $method, $class | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | 109 | }; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # caller() will return if its inside an eval, need to skip over those. | ||||||||||||||||||||||||||||
| 105 | my $find_method = sub { | ||||||||||||||||||||||||||||
| 106 | 10 | ▶ | my $method; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 107 | 10 | my $height = 2; | |||||||||||||||||||||||||||
| 108 | 10 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $method or $method ne "(eval)"
MC/DC100%2/2
not defined $method or $method ne "(eval)"
not defined $method
$method ne "(eval)"
Truth table100%3/3
not(A) or B
A= not defined $methodB= $method ne "(eval)"
| |||||||||||||||||||||||||||||
| 109 | 13 | $method = (caller($height))[3]; | |||||||||||||||||||||||||||
| 110 | 13 | $height++; | |||||||||||||||||||||||||||
| 111 | } until( !defined $method or $method ne '(eval)' ); | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 10 | return $method; | |||||||||||||||||||||||||||
| 114 | 109 | }; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub super { | ||||||||||||||||||||||||||||
| 118 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
super: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 10 | my $class = $self->class; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 10 | my $fq_method = $find_method->(); | |||||||||||||||||||||||||||
| 122 | 10 | ▶ | Carp::Fix::1_25::croak("super() called outside a method") unless $fq_method; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 9 | my($parent, $method) = $fq_method =~ /^(.*)::(\w+)$/; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 9 | ▶ | Carp::Fix::1_25::croak( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | sprintf qq["%s" is not a parent class of "%s"], | ||||||||||||||||||||||||||||
| 128 | $parent, $class | ||||||||||||||||||||||||||||
| 129 | ) unless $class->isa($parent); | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 8 | my @isa = $self->linear_isa(); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 8 | ▶ | while(@isa) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 12 | my $class = shift @isa; | |||||||||||||||||||||||||||
| 135 | 12 | ▶ | last if $class eq $parent; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 8 | for (@isa) { | |||||||||||||||||||||||||||
| 139 | 8 | my $code = $_->can($method); | |||||||||||||||||||||||||||
| 140 | 8 | @_ = ($$$self, @_); | |||||||||||||||||||||||||||
| 141 | 8 | ▶ | goto &$code if $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | $class->$method_not_found($method); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 109 | 1; | |||||||||||||||||||||||||||