1 package Class::MOP::Method::Inlined;
7 use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Class::MOP::Method::Generated';
15 sub _expected_method_class { $_[0]{_expected_method_class} }
20 if ( my $super_method = $self->associated_metaclass->find_next_method_by_name( $self->name ) ) {
21 if ( $super_method->isa(__PACKAGE__) ) {
22 return $super_method->_uninlined_body;
24 return $super_method->body;
33 my $metaclass = $self->associated_metaclass;
34 my $class = $metaclass->name;
36 if ( my $expected_class = $self->_expected_method_class ) {
38 # if we are shadowing a method we first verify that it is
39 # compatible with the definition we are replacing it with
40 my $expected_method = $expected_class->can($self->name);
43 = "Not inlining '" . $self->name . "' for $class since it is not"
44 . " inheriting the default ${expected_class}::" . $self->name . "\n"
45 . "If you are certain you don't need to inline your";
47 if ( $self->isa("Class::MOP::Method::Constructor") ) {
48 # FIXME kludge, refactor warning generation to a method
49 $warning .= " constructor, specify inline_constructor => 0 in your"
50 . " call to $class->meta->make_immutable\n";
53 if ( my $actual_method = $class->can($self->name) ) {
54 if ( refaddr($expected_method) == refaddr($actual_method) ) {
55 # the method is what we wanted (probably Moose::Object::new)
57 } elsif ( my $inherited_method = $metaclass->find_next_method_by_name( $self->name ) ) {
58 # otherwise we have to check that the actual method is an
59 # inlined version of what we're expecting
60 if ( $inherited_method->isa(__PACKAGE__) ) {
61 if ( refaddr($inherited_method->_uninlined_body) == refaddr($expected_method) ) {
64 } elsif ( refaddr($inherited_method->body) == refaddr($expected_method) ) {
68 # FIXME we can just rewrap them =P
69 $warning .= " ('" . $self->name . "' has method modifiers which would be lost if it were inlined)\n"
70 if $inherited_method->isa('Class::MOP::Method::Wrapped');
73 # This would be a rather weird case where we have no method
74 # in the inheritance chain even though we're expecting one to be
77 # this returns 1 for backwards compatibility for now
85 # there is no expected class so we just install the constructor as a