use strict;
use warnings;
+use Class::MOP::Instance;
+use Class::MOP::Method::Wrapped;
+
use Carp 'confess';
use Scalar::Util 'blessed', 'reftype', 'weaken';
use Sub::Name 'subname';
use B 'svref_2object';
-our $VERSION = '0.20';
+our $VERSION = '0.21';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Class::MOP::Module';
-use Class::MOP::Instance;
-
# Self-introspection
sub meta { Class::MOP::Class->initialize(blessed($_[0]) || $_[0]) }
: blessed($class))
: $class);
- $class = blessed($class) || $class;
# now create the metaclass
my $meta;
if ($class =~ /^Class::MOP::Class$/) {
sub is_anon_class {
my $self = shift;
+ no warnings 'uninitialized';
$self->name =~ /^$ANON_CLASS_PREFIX/ ? 1 : 0;
}
# really need to be handled explicitly
sub DESTROY {
my $self = shift;
+ no warnings 'uninitialized';
return unless $self->name =~ /^$ANON_CLASS_PREFIX/;
my ($serial_id) = ($self->name =~ /^$ANON_CLASS_PREFIX(\d+)/);
no strict 'refs';
foreach my $symbol ($self->list_all_package_symbols('CODE')) {
my $code = $self->get_package_symbol('&' . $symbol);
- next if exists $map->{$symbol} && $map->{$symbol}->body == $code;
+ next if exists $map->{$symbol} &&
+ defined $map->{$symbol} &&
+ $map->{$symbol}->body == $code;
my $gv = svref_2object($code)->GV;
next if ($gv->STASH->NAME || '') ne $class_name &&
$method = $self->find_next_method_by_name($method_name);
# die if it does not exist
(defined $method)
- || confess "The method '$method_name' is not found in the inherience hierarchy for this class";
+ || confess "The method '$method_name' is not found in the inherience hierarchy for class " . $self->name;
# and now make sure to wrap it
# even if it is already wrapped
# because we need a new sub ref
sub find_method_by_name {
my ($self, $method_name) = @_;
- # FIXME
- return $self->name->can($method_name);
+ (defined $method_name && $method_name)
+ || confess "You must define a method name to find";
+ # keep a record of what we have seen
+ # here, this will handle all the
+ # inheritence issues because we are
+ # using the &class_precedence_list
+ my %seen_class;
+ my @cpl = $self->class_precedence_list();
+ foreach my $class (@cpl) {
+ next if $seen_class{$class};
+ $seen_class{$class}++;
+ # fetch the meta-class ...
+ my $meta = $self->initialize($class);
+ return $meta->get_method($method_name)
+ if $meta->has_method($method_name);
+ }
+ return;
}
sub compute_all_applicable_methods {