1 package Class::MOP::Method::Inlined;
7 use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
9 use base 'Class::MOP::Method::Generated';
15 = $self->associated_metaclass->find_next_method_by_name( $self->name )
18 if ( $super_method->isa(__PACKAGE__) ) {
19 return $super_method->_uninlined_body;
22 return $super_method->body;
28 my $metaclass = $self->associated_metaclass;
29 my $class = $metaclass->name;
31 # If we don't find an inherited method, this is a rather weird
32 # case where we have no method in the inheritance chain even
33 # though we're expecting one to be there
35 = $metaclass->find_next_method_by_name( $self->name );
37 if ( $inherited_method
38 && $inherited_method->isa('Class::MOP::Method::Wrapped') ) {
41 . "' for $class since it "
42 . "has method modifiers which would be lost if it were inlined\n";
47 my $expected_class = $self->_expected_method_class
50 # if we are shadowing a method we first verify that it is
51 # compatible with the definition we are replacing it with
52 my $expected_method = $expected_class->can( $self->name );
54 if ( ! $expected_method ) {
57 . "' for $class since ${expected_class}::"
59 . " is not defined\n";
64 my $actual_method = $class->can( $self->name )
67 # the method is what we wanted (probably Moose::Object::new)
69 if refaddr($expected_method) == refaddr($actual_method);
71 # otherwise we have to check that the actual method is an inlined
72 # version of what we're expecting
73 if ( $inherited_method->isa(__PACKAGE__) ) {
74 if ( $inherited_method->_uninlined_body
75 && refaddr( $inherited_method->_uninlined_body )
76 == refaddr($expected_method) ) {
80 elsif ( refaddr( $inherited_method->body )
81 == refaddr($expected_method) ) {
88 . "' for $class since it is not"
89 . " inheriting the default ${expected_class}::"
92 if ( $self->isa("Class::MOP::Method::Constructor") ) {
94 # FIXME kludge, refactor warning generation to a method
96 .= "If you are certain you don't need to inline your"
97 . " constructor, specify inline_constructor => 0 in your"
98 . " call to $class->meta->make_immutable\n";
108 # ABSTRACT: Method base class for methods which have been inlined
116 This is a L<Class::MOP::Method::Generated> subclass for methods which
123 =item B<< $metamethod->can_be_inlined >>
125 This method returns true if the method in question can be inlined in
126 the associated metaclass.
128 If it cannot be inlined, it spits out a warning and returns false.