blib/lib/Mouse/Meta/Method/Delegation.pm

filter: Statementstmt 92.6% 38 / 41 Branchbran 75.0% 18 / 24 Conditioncond 63.3% 19 / 30 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 72.2% 86 / 119 CC 23 SCAR 19.9
CC
23
Cov
79%
_generate_delegation
12.4
__ANON__
5.6
child_g_method_1
5.6
CRAP 7.3
« blib/lib/Mouse/Meta/TypeConstraint.pm ↑ Summary blib/lib/Mouse/Util/TypeConstraints.pm »
1 package Mouse::Meta::Method::Delegation;
2 6 ▶use Mouse::Util qw(:meta); # enables strict and warnings
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 22 ▶sub _generate_delegation{
Subroutine _generate_delegation: called CC=11 SCAR=25.2
6 22 my (undef, $attr, $handle_name, $method_to_call) = @_;
7  
8 22 my @curried_args;
9 22 ▶ if(ref($method_to_call) eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $method_to_call eq "ARRAY") 2 20 22
10 2 ($method_to_call, @curried_args) = @{$method_to_call};
11 }
12  
13 # If it has a reader, we must use it to make method modifiers work
14 22 ▶ my $reader = $attr->get_read_method() || $attr->get_read_method_ref();
Condition66%2/3
$attr->get_read_method || $attr->get_read_method_ref
l!l&&r!l&&!r
2110
MC/DC0%0/2
$attr->get_read_method || $attr->get_read_method_ref
$attr->get_read_method $attr->get_read_method_ref
Truth table66%2/3
A || B
A= $attr->get_read_methodB= $attr->get_read_method_ref
ABresult
1X1
011
000
15  
16 22 my $can_be_optimized = $attr->{_mouse_cache_method_delegation_can_be_optimized};
17  
18 22 ▶ if(!defined $can_be_optimized){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $can_be_optimized) 14 8 22
19 14 my $tc = $attr->type_constraint;
20 $attr->{_mouse_cache_method_delegation_can_be_optimized} =
21 14 ▶ (defined($tc) && $tc->is_a_type_of('Object'))
Condition72%13/18
defined $tc && $tc->is_a_type_of('Object') && ($attr->is_required || $attr->has_default || $attr->has_builder) && ($attr->is_lazy || !$attr->has_clearer)
!ll&&!rl&&r
608
defined $tc and $tc->is_a_type_of("Object") and $attr->is_required || $attr->has_default || $attr->has_builder
!ll&&!rl&&r
248
defined $tc and $tc->is_a_type_of("Object")
!ll&&!rl&&r
2012
$attr->is_required or $attr->has_default or $attr->has_builder
l!l&&r!l&&!r
804
$attr->is_required or $attr->has_default
l!l&&r!l&&!r
084
$attr->is_lazy or not $attr->has_clearer
l!l&&r!l&&!r
170
MC/DC28%2/7
defined $tc && $tc->is_a_type_of('Object') && ($attr->is_required || $attr->has_default || $attr->has_builder) && ($attr->is_lazy || !$attr->has_clearer)
defined $tc $tc->is_a_type_of("Object") $attr->is_required $attr->has_default $attr->has_builder $attr->is_lazy not $attr->has_clearer
Truth table33%4/12
A and B and C or D or E && F or not(G)
A= defined $tcB= $tc->is_a_type_of("Object")C= $attr->is_requiredD= $attr->has_defaultE= $attr->has_builderF= $attr->is_lazyG= not $attr->has_clearer
ABCDEFGresult
0XXXXXX0
10XXXXX0
11000XX0
111XX000
1101X000
11001000
111XX1X1
111XX011
1101X1X1
1101X011
110011X1
11001011
22 && ($attr->is_required || $attr->has_default || $attr->has_builder)
23 && ($attr->is_lazy || !$attr->has_clearer);
24 }
25  
26 22 ▶ if($can_be_optimized){
Branch: 1 branch
BranchTrueFalseTotal
if ($can_be_optimized) { } 5 17 22
27 # need not check the attribute value
28 1 ▶ return sub {
Subroutine name: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=1 SCAR=0.4
Subroutine child_a_super_method: called CC=1 SCAR=0.4
29 0 return shift()->$reader()->$method_to_call(@curried_args, @_);
30 5 };
31 }
32 else {
33 # need to check the attribute value
34 12 ▶ return sub {
Subroutine person_hello: called CC=5 SCAR=17.2
Subroutine __ANON__: called CC=5 SCAR=17.2
Subroutine child_g_method_1: called CC=5 SCAR=17.2
35 12 my $instance = shift;
36 12 my $proxy = $instance->$reader();
37  
38 12 ▶ my $error = !defined($proxy) ? ' is not defined'
Branch: 6 branches
BranchTrueFalseTotal
!defined($proxy) ? : 2 10 12
ref $proxy && !builtin::blessed($proxy) ? : 2 8 10
!defined($proxy) ? : 0 3 3
ref $proxy && !builtin::blessed($proxy) ? : 0 3 3
!defined($proxy) ? : 0 4 4
ref $proxy && !builtin::blessed($proxy) ? : 0 4 4
Condition44%4/9
ref $proxy and not builtin::blessed($proxy)
!ll&&!rl&&r
082
ref $proxy and not builtin::blessed($proxy)
!ll&&!rl&&r
030
ref $proxy and not builtin::blessed($proxy)
!ll&&!rl&&r
040
MC/DC50%1/2
ref $proxy and not builtin::blessed($proxy)
ref $proxy not builtin::blessed($proxy)
MC/DC0%0/2
ref $proxy and not builtin::blessed($proxy)
ref $proxy not builtin::blessed($proxy)
MC/DC0%0/2
ref $proxy and not builtin::blessed($proxy)
ref $proxy not builtin::blessed($proxy)
Truth table66%2/3
A and not(B)
A= ref $proxyB= not builtin::blessed($proxy)
ABresult
0X0
100
111
Truth table33%1/3
A and not(B)
A= ref $proxyB= not builtin::blessed($proxy)
ABresult
0X0
100
111
Truth table33%1/3
A and not(B)
A= ref $proxyB= not builtin::blessed($proxy)
ABresult
0X0
100
111
39 : ref($proxy) && !Scalar::Util::blessed($proxy) ? qq{ is not an object (got '$proxy')}
40 : undef;
41 12 ▶ if ($error) {
Branch: 3 branches
BranchTrueFalseTotal
if ($error) 4 8 12
if ($error) 0 3 3
if ($error) 0 4 4
42 0 $instance->meta->throw_error(
43 "Cannot delegate $handle_name to $method_to_call because "
44 . "the value of "
45 . $attr->name
46 . $error
47 );
48 }
49 0 $proxy->$method_to_call(@curried_args, @_);
50 17 };
51 }
52 }
53  
54  
55 1 1;
56 __END__
« blib/lib/Mouse/Meta/TypeConstraint.pm ↑ Summary blib/lib/Mouse/Util/TypeConstraints.pm »