1 package Class::MOP::Method::Inlined;
7 use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
9 our $AUTHORITY = 'cpan:STEVAN';
11 use base 'Class::MOP::Method::Generated';
17 = $self->associated_metaclass->find_next_method_by_name( $self->name )
20 if ( $super_method->isa(__PACKAGE__) ) {
21 return $super_method->_uninlined_body;
24 return $super_method->body;
30 my $metaclass = $self->associated_metaclass;
31 my $class = $metaclass->name;
33 # If we don't find an inherited method, this is a rather weird
34 # case where we have no method in the inheritance chain even
35 # though we're expecting one to be there
37 = $metaclass->find_next_method_by_name( $self->name );
39 if ( $inherited_method
40 && $inherited_method->isa('Class::MOP::Method::Wrapped') ) {
43 . "' for $class since it "
44 . "has method modifiers which would be lost if it were inlined\n";
49 my $expected_class = $self->_expected_method_class
52 # if we are shadowing a method we first verify that it is
53 # compatible with the definition we are replacing it with
54 my $expected_method = $expected_class->can( $self->name );
56 if ( ! $expected_method ) {
59 . "' for $class since ${expected_class}::"
61 . " is not defined\n";
66 my $actual_method = $class->can( $self->name )
69 # the method is what we wanted (probably Moose::Object::new)
71 if refaddr($expected_method) == refaddr($actual_method);
73 # otherwise we have to check that the actual method is an inlined
74 # version of what we're expecting
75 if ( $inherited_method->isa(__PACKAGE__) ) {
76 if ( $inherited_method->_uninlined_body
77 && refaddr( $inherited_method->_uninlined_body )
78 == refaddr($expected_method) ) {
82 elsif ( refaddr( $inherited_method->body )
83 == refaddr($expected_method) ) {
90 . "' for $class since it is not"
91 . " inheriting the default ${expected_class}::"
94 if ( $self->isa("Class::MOP::Method::Constructor") ) {
96 # FIXME kludge, refactor warning generation to a method
98 .= "If you are certain you don't need to inline your"
99 . " constructor, specify inline_constructor => 0 in your"
100 . " call to $class->meta->make_immutable\n";
110 # ABSTRACT: Method base class for methods which have been inlined
118 This is a L<Class::MOP::Method::Generated> subclass for methods which
125 =item B<< $metamethod->can_be_inlined >>
127 This method returns true if the method in question can be inlined in
128 the associated metaclass.
130 If it cannot be inlined, it spits out a warning and returns false.