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';
19 = $self->associated_metaclass->find_next_method_by_name( $self->name )
22 if ( $super_method->isa(__PACKAGE__) ) {
23 return $super_method->_uninlined_body;
26 return $super_method->body;
32 my $metaclass = $self->associated_metaclass;
33 my $class = $metaclass->name;
35 # If we don't find an inherited method, this is a rather weird
36 # case where we have no method in the inheritance chain even
37 # though we're expecting one to be there
39 = $metaclass->find_next_method_by_name( $self->name );
41 if ( $inherited_method
42 && $inherited_method->isa('Class::MOP::Method::Wrapped') ) {
45 . "' for $class since it "
46 . "has method modifiers which would be lost if it were inlined\n";
51 my $expected_class = $self->_expected_method_class
54 # if we are shadowing a method we first verify that it is
55 # compatible with the definition we are replacing it with
56 my $expected_method = $expected_class->can( $self->name );
58 if ( ! $expected_method ) {
61 . "' for $class since ${expected_class}::"
63 . " is not defined\n";
68 my $actual_method = $class->can( $self->name )
71 # the method is what we wanted (probably Moose::Object::new)
73 if refaddr($expected_method) == refaddr($actual_method);
75 # otherwise we have to check that the actual method is an inlined
76 # version of what we're expecting
77 if ( $inherited_method->isa(__PACKAGE__) ) {
78 if ( $inherited_method->_uninlined_body
79 && refaddr( $inherited_method->_uninlined_body )
80 == refaddr($expected_method) ) {
84 elsif ( refaddr( $inherited_method->body )
85 == refaddr($expected_method) ) {
92 . "' for $class since it is not"
93 . " inheriting the default ${expected_class}::"
96 if ( $self->isa("Class::MOP::Method::Constructor") ) {
98 # FIXME kludge, refactor warning generation to a method
100 .= "If you are certain you don't need to inline your"
101 . " constructor, specify inline_constructor => 0 in your"
102 . " call to $class->meta->make_immutable\n";
118 Class::MOP::Method::Inlined - Method base class for methods which have been inlined
122 This is a L<Class::MOP::Method::Generated> subclass for methods which
129 =item B<< $metamethod->can_be_inlined >>
131 This method returns true if the method in question can be inlined in
132 the associated metaclass.
134 If it cannot be inlined, it spits out a warning and returns false.
140 Stevan Little E<lt>stevan@iinteractive.comE<gt>
142 =head1 COPYRIGHT AND LICENSE
144 Copyright 2006-2010 by Infinity Interactive, Inc.
146 L<http://www.iinteractive.com>
148 This library is free software; you can redistribute it and/or modify
149 it under the same terms as Perl itself.