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} }
21 = $self->associated_metaclass->find_next_method_by_name( $self->name )
23 if ( $super_method->isa(__PACKAGE__) ) {
24 return $super_method->_uninlined_body;
27 return $super_method->body;
37 my $metaclass = $self->associated_metaclass;
38 my $class = $metaclass->name;
40 if ( my $expected_class = $self->_expected_method_class ) {
42 # if we are shadowing a method we first verify that it is
43 # compatible with the definition we are replacing it with
44 my $expected_method = $expected_class->can( $self->name );
49 . "' for $class since it is not"
50 . " inheriting the default ${expected_class}::"
52 . "If you are certain you don't need to inline your";
54 if ( $self->isa("Class::MOP::Method::Constructor") ) {
56 # FIXME kludge, refactor warning generation to a method
58 .= " constructor, specify inline_constructor => 0 in your"
59 . " call to $class->meta->make_immutable\n";
62 if ( my $actual_method = $class->can( $self->name ) ) {
63 if ( refaddr($expected_method) == refaddr($actual_method) ) {
65 # the method is what we wanted (probably Moose::Object::new)
68 elsif ( my $inherited_method
69 = $metaclass->find_next_method_by_name( $self->name ) ) {
71 # otherwise we have to check that the actual method is an
72 # inlined version of what we're expecting
73 if ( $inherited_method->isa(__PACKAGE__) ) {
74 if ( refaddr( $inherited_method->_uninlined_body )
75 == refaddr($expected_method) ) {
79 elsif ( refaddr( $inherited_method->body )
80 == refaddr($expected_method) ) {
84 # FIXME we can just rewrap them =P
88 . "' has method modifiers which would be lost if it were inlined)\n"
89 if $inherited_method->isa('Class::MOP::Method::Wrapped');
94 # This would be a rather weird case where we have no method
95 # in the inheritance chain even though we're expecting one to be
98 # this returns 1 for backwards compatibility for now
108 # there is no expected class so we just install the constructor as a