blib/lib/Class/MOP/Method/Inlined.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 81.8% 18 / 22 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 87.6% 71 / 81 CC 14 SCAR 21.3
CC
14
Cov
89%
can_be_inlined
12.2
_uninlined_body
3.3
BEGIN
1.0
CRAP 8.4
« blib/lib/Moose/Util.pm ↑ Summary blib/lib/Moose/Meta/TypeConstraint/DuckType.pm »
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
BranchTrueFalseTotal
my $super_method = $self->associated_metaclass->find_next_method_by_name($self->name) or return 890 0 890
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
BranchTrueFalseTotal
if ($super_method->isa(__PACKAGE__)) { } 0 890 890
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
BranchTrueFalseTotal
if ($inherited_method and $inherited_method->isa("Class::MOP::Method::Wrapped")) 4 13235 13239
Condition100%3/3
$inherited_method and $inherited_method->isa("Class::MOP::Method::Wrapped")
!ll&&!rl&&r
815124204
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
my $expected_class = $self->_expected_method_class or return 1 760 12475 13235
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
BranchTrueFalseTotal
unless ($expected_method) 1 759 760
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
BranchTrueFalseTotal
my $actual_method = $class->can($self->name) or return 1 756 3 759
65 or return 1;
66  
67 # the method is what we wanted (probably Moose::Object::new)
68 756 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($expected_method) == builtin::refaddr($actual_method) 308 448 756
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
BranchTrueFalseTotal
if ($inherited_method->isa(__PACKAGE__)) { } 445 3 448
elsif (builtin::refaddr($inherited_method->body) == builtin::refaddr($expected_method)) { } 0 3 3
74 445 ▶ if ( $inherited_method->_uninlined_body
Branch: 1 branch
BranchTrueFalseTotal
if ($inherited_method->_uninlined_body and builtin::refaddr($inherited_method->_uninlined_body) == builtin::refaddr($expected_method)) 445 0 445
Condition33%1/3
$inherited_method->_uninlined_body and builtin::refaddr($inherited_method->_uninlined_body) == builtin::refaddr($expected_method)
!ll&&!rl&&r
00445
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->isa("Class::MOP::Method::Constructor")) 2 1 3
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__
« blib/lib/Moose/Util.pm ↑ Summary blib/lib/Moose/Meta/TypeConstraint/DuckType.pm »