| 1 | package Class::Component::Component::Autocall::Autoload; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Carp::Clan qw/Class::Component/; | ||
| 7 | |||
| 8 | our $AUTOLOAD; | ||
| 9 | sub AUTOLOAD { | ||
| 10 | my $self = shift; | ||
| 11 | return unless ref($self); | ||
| 12 | (my $method = $AUTOLOAD) =~ s/.*:://; | ||
| 13 | return if $method eq 'DESTROY'; | ||
| 14 | |||
| 15 | eval { | ||
| 16 | # $self->SUPER::can('AUTOLOAD')->(@_) if $self->SUPER::can('AUTOLOAD'); | ||
| 17 | # $self->SUPER::can($method)->(@_) if $self->SUPER::can($method); | ||
| 18 | $self->NEXT($method => @_); | ||
| 19 | }; | ||
| 20 | my $super_error = $@; | ||
| 21 | |||
| 22 | if (ref($self) && (my $plugin = $self->class_component_methods->{$method})) { | ||
| 23 | return $self->call($method, @_); | ||
| 24 | } | ||
| 25 | |||
| 26 | croak $super_error if $super_error; | ||
| 27 | croak sprintf('Can\'t locate object method "%s" via package "%s"', $method, ref($self) || $self); | ||
| 28 | } | ||
| 29 | |||
| 30 | 1; |