| 1 | package Class::MOP::Method::Inlined; | ||||||||||||||||||||||||||||
| 2 | 459 | our $VERSION = '2.4001'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 459 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 459 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 459 | ▶ | use Scalar::Util 'refaddr'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 459 | ▶ | use parent 'Class::MOP::Method::Generated'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 890 | ▶ | sub _uninlined_body { | ||||||||||||||||||||||||||
|
Subroutine
_uninlined_body: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 12 | 890 | my $self = shift; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 890 | ▶ | my $super_method | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | = $self->associated_metaclass->find_next_method_by_name( $self->name ) | ||||||||||||||||||||||||||||
| 16 | or return; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 890 | ▶ | if ( $super_method->isa(__PACKAGE__) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | return $super_method->_uninlined_body; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | else { | ||||||||||||||||||||||||||||
| 22 | 890 | return $super_method->body; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 13239 | ▶ | sub can_be_inlined { | ||||||||||||||||||||||||||
|
Subroutine
can_be_inlined: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 13239 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 13239 | my $metaclass = $self->associated_metaclass; | |||||||||||||||||||||||||||
| 29 | 13239 | my $class = $metaclass->name; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||
| 34 | 13239 | my $inherited_method | |||||||||||||||||||||||||||
| 35 | = $metaclass->find_next_method_by_name( $self->name ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 13239 | ▶ | if ( $inherited_method | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inherited_method and $inherited_method->isa("Class::MOP::Method::Wrapped")
MC/DC100%2/2
$inherited_method and $inherited_method->isa("Class::MOP::Method::Wrapped")
$inherited_method
$inherited_method->isa("Class::MOP::Method::Wrapped")
Truth table100%3/3
A and B
A= $inherited_methodB= $inherited_method->isa("Class::MOP::Method::Wrapped")
| |||||||||||||||||||||||||||||
| 38 | && $inherited_method->isa('Class::MOP::Method::Wrapped') ) { | ||||||||||||||||||||||||||||
| 39 | 4 | warn "Not inlining '" | |||||||||||||||||||||||||||
| 40 | . $self->name | ||||||||||||||||||||||||||||
| 41 | . "' for $class since it " | ||||||||||||||||||||||||||||
| 42 | . "has method modifiers which would be lost if it were inlined\n"; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | return 0; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 13235 | ▶ | my $expected_class = $self->_expected_method_class | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | or return 1; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # if we are shadowing a method we first verify that it is | ||||||||||||||||||||||||||||
| 51 | # compatible with the definition we are replacing it with | ||||||||||||||||||||||||||||
| 52 | 760 | my $expected_method = $expected_class->can( $self->name ); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 760 | ▶ | if ( ! $expected_method ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 1 | warn "Not inlining '" | |||||||||||||||||||||||||||
| 56 | . $self->name | ||||||||||||||||||||||||||||
| 57 | . "' for $class since ${expected_class}::" | ||||||||||||||||||||||||||||
| 58 | . $self->name | ||||||||||||||||||||||||||||
| 59 | . " is not defined\n"; | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | return 0; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 759 | ▶ | my $actual_method = $class->can( $self->name ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | or return 1; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # the method is what we wanted (probably Moose::Object::new) | ||||||||||||||||||||||||||||
| 68 | 756 | ▶ | return 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | if refaddr($expected_method) == refaddr($actual_method); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # otherwise we have to check that the actual method is an inlined | ||||||||||||||||||||||||||||
| 72 | # version of what we're expecting | ||||||||||||||||||||||||||||
| 73 | 448 | ▶ | if ( $inherited_method->isa(__PACKAGE__) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 74 | 445 | ▶ | if ( $inherited_method->_uninlined_body | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$inherited_method->_uninlined_body and builtin::refaddr($inherited_method->_uninlined_body) == builtin::refaddr($expected_method)
MC/DC0%0/2
$inherited_method->_uninlined_body and builtin::refaddr($inherited_method->_uninlined_body) == builtin::refaddr($expected_method)
$inherited_method->_uninlined_body
builtin::refaddr($inherited_method->_uninlined_body) == builtin::refaddr($expected_method)
Truth table33%1/3
A and B
A= $inherited_method->_uninlined_bodyB= builtin::refaddr($inherited_method->_uninlined_body) == builtin::refaddr($expected_method)
| |||||||||||||||||||||||||||||
| 75 | && refaddr( $inherited_method->_uninlined_body ) | ||||||||||||||||||||||||||||
| 76 | == refaddr($expected_method) ) { | ||||||||||||||||||||||||||||
| 77 | 445 | return 1; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | elsif ( refaddr( $inherited_method->body ) | ||||||||||||||||||||||||||||
| 81 | == refaddr($expected_method) ) { | ||||||||||||||||||||||||||||
| 82 | 0 | return 1; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 3 | my $warning | |||||||||||||||||||||||||||
| 86 | = "Not inlining '" | ||||||||||||||||||||||||||||
| 87 | . $self->name | ||||||||||||||||||||||||||||
| 88 | . "' for $class since it is not" | ||||||||||||||||||||||||||||
| 89 | . " inheriting the default ${expected_class}::" | ||||||||||||||||||||||||||||
| 90 | . $self->name . "\n"; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 3 | ▶ | if ( $self->isa("Class::MOP::Method::Constructor") ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # FIXME kludge, refactor warning generation to a method | ||||||||||||||||||||||||||||
| 95 | 2 | $warning | |||||||||||||||||||||||||||
| 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"; | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3 | warn $warning; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 3 | return 0; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 459 | 1; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # ABSTRACT: Method base class for methods which have been inlined | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||