1
package perl5i::2::Meta;
6
# Be very careful not to import anything.
10
require perl5i::2::Meta::Instance;
11
require perl5i::2::Meta::Class;
14
return perl5i::2::Meta::Instance->new($_[0]);
18
return perl5i::2::Meta::Class->new($_[0]);
22
my( $class, $thing ) = @_;
23
return bless \$thing, $class;
27
my $class = $_[0]->class;
30
return wantarray ? @{$class.'::ISA'} : \@{$class.'::ISA'};
35
my $class = $self->class;
37
# get_linear_isa() does not return UNIVERSAL
39
@extra = qw(UNIVERSAL) unless $class eq 'UNIVERSAL';
41
my $isa = [@{mro::get_linear_isa($class)}, @extra];
42
return wantarray ? @$isa : $isa;
46
# A single place to put the "method not found" error.
47
my $method_not_found = sub {
51
Carp::croak sprintf q[Can't locate object method "%s" via package "%s"],
56
# caller() will return if its inside an eval, need to skip over those.
57
my $find_method = sub {
61
$method = (caller($height))[3];
63
} until( !defined $method or $method ne '(eval)' );
71
my $class = $self->class;
73
my $fq_method = $find_method->();
74
Carp::croak "super() called outside a method" unless $fq_method;
76
my($parent, $method) = $fq_method =~ /^(.*)::(\w+)$/;
78
Carp::croak sprintf qq["%s" is not a parent class of "%s"], $parent, $class
79
unless $class->isa($parent);
81
my @isa = $self->linear_isa();
84
my $class = shift @isa;
85
last if $class eq $parent;
89
my $code = $_->can($method);
94
$class->$method_not_found($method);