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 )
24 if ( $super_method->isa(__PACKAGE__) ) {
25 return $super_method->_uninlined_body;
28 return $super_method->body;
34 my $metaclass = $self->associated_metaclass;
35 my $class = $metaclass->name;
37 # If we don't find an inherited method, this is a rather weird
38 # case where we have no method in the inheritance chain even
39 # though we're expecting one to be there
41 = $metaclass->find_next_method_by_name( $self->name );
43 if ( $inherited_method
44 && $inherited_method->isa('Class::MOP::Method::Wrapped') ) {
47 . "' for $class since it "
48 . "has method modifiers which would be lost if it were inlined\n";
53 my $expected_class = $self->_expected_method_class
56 # if we are shadowing a method we first verify that it is
57 # compatible with the definition we are replacing it with
58 my $expected_method = $expected_class->can( $self->name );
60 if ( ! $expected_method ) {
63 . "' for $class since ${expected_class}::"
65 . " is not defined\n";
70 my $actual_method = $class->can( $self->name )
73 # the method is what we wanted (probably Moose::Object::new)
75 if refaddr($expected_method) == refaddr($actual_method);
77 # otherwise we have to check that the actual method is an inlined
78 # version of what we're expecting
79 if ( $inherited_method->isa(__PACKAGE__) ) {
80 if ( $inherited_method->_uninlined_body
81 && refaddr( $inherited_method->_uninlined_body )
82 == refaddr($expected_method) ) {
86 elsif ( refaddr( $inherited_method->body )
87 == refaddr($expected_method) ) {
94 . "' for $class since it is not"
95 . " inheriting the default ${expected_class}::"
98 if ( $self->isa("Class::MOP::Method::Constructor") ) {
100 # FIXME kludge, refactor warning generation to a method
102 .= "If you are certain you don't need to inline your"
103 . " constructor, specify inline_constructor => 0 in your"
104 . " call to $class->meta->make_immutable\n";
120 Class::MOP::Method::Inlined - Method base class for methods which have been inlined
124 This is a L<Class::MOP::Method::Generated> subclass for methods which
131 =item B<< $metamethod->can_be_inlined >>
133 This method returns true if the method in question can be inlined in
134 the associated metaclass.
136 If it cannot be inlined, it spits out a warning and returns false.
142 Stevan Little E<lt>stevan@iinteractive.comE<gt>
144 =head1 COPYRIGHT AND LICENSE
146 Copyright 2006-2010 by Infinity Interactive, Inc.
148 L<http://www.iinteractive.com>
150 This library is free software; you can redistribute it and/or modify
151 it under the same terms as Perl itself.