blib/lib/Role/Hooks.pm

filter: Statementstmt 73.2% 204 / 280 (1 uncoverable) Branchbran 62.5% 50 / 80 Conditioncond 56.8% 75 / 132 MC/DCmcdc 29.3% 22 / 75 Subroutinesub 80.0% 28 / 35 Podpod 100% 4 / 4 totaltotal 63.3% 383 / 606 (1 uncoverable) CC 105 SCAR 28.8
CC
105
Cov
67%
__ANON__
72.0
__ANON__
72.0
_install_patches
23.7
CRAP 17.8
↑ Summary
1 10 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Role::Hooks;
6  
7 10 ▶use Class::Method::Modifiers qw( install_modifier );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 our $AUTHORITY = 'cpan:TOBYINK';
10 10 our $VERSION = '0.008';
11  
12 10 our %CALLBACKS_BEFORE_APPLY;
13 10 our %CALLBACKS_AFTER_APPLY;
14 10 our %CALLBACKS_AFTER_INFLATE;
15 10 our %ARGS;
16  
17 10 ▶BEGIN { *DEBUG = $ENV{'PERL_ROLE_HOOKS_DEBUG'} ? sub(){1} : sub(){0} };
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERL_ROLE_HOOKS_DEBUG'} ? : 0 10 10
18  
19 # limited version of Safe::Isa
20 30 ▶my $_isa = sub { ref( $_[0] ) and $_[0]->isa( $_[1] ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] and $_[0]->isa($_[1]) 29 1 30
21  
22 0 ▶sub _croak {
Subroutine _croak: not called CC=2 SCAR=17.9
23 0 my ($me, $msg, @args) = @_;
24 0 require Carp;
25 0 ▶ Carp::croak( @args ? sprintf($msg, @args) : $msg );
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 0 0
26 }
27  
28 0 ▶sub _carp {
Subroutine _carp: not called CC=2 SCAR=17.9
29 0 my ($me, $msg, @args) = @_;
30 0 require Carp;
31 0 ▶ Carp::carp( @args ? sprintf($msg, @args) : $msg );
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 0 0
32 }
33  
34 0 ▶sub _debug {
Subroutine _debug: not called CC=1 SCAR=6.9
35 0 my ($me, $msg, @args) = @_;
36 0 require Carp;
37 0 Carp::carp( @args ? sprintf($msg, @args) : $msg ) if DEBUG;
38 }
39  
40 96 ▶sub is_role {
Subroutine is_role: called CC=17 SCAR=31.4
Pod documented
41 96 my $target = pop;
42
43 96 ▶ if ($INC{'Role/Tiny.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Role/Tiny.pm"} and "Role::Tiny"->can("is_role") and "Role::Tiny"->is_role($target)) 46 50 96
Condition83%5/6
$INC{"Role/Tiny.pm"} and "Role::Tiny"->can("is_role") and "Role::Tiny"->is_role($target)
!ll&&!rl&&r
311946
$INC{"Role/Tiny.pm"} and "Role::Tiny"->can("is_role")
!ll&&!rl&&r
31065
MC/DC66%2/3
$INC{"Role/Tiny.pm"} and "Role::Tiny"->can("is_role") and "Role::Tiny"->is_role($target)
$INC{"Role/Tiny.pm"} "Role::Tiny"->can("is_role") "Role::Tiny"->is_role($target)
Truth table75%3/4
A and B and C
A= $INC{"Role/Tiny.pm"}B= "Role::Tiny"->can("is_role")C= "Role::Tiny"->is_role($target)
ABCresult
0XX0
10X0
1100
1111
44 and 'Role::Tiny'->can('is_role')
45 and 'Role::Tiny'->is_role($target)) {
46 46 return 'Role::Tiny';
47 }
48
49 # really old versions of Role::Tiny
50 50 ▶ if ($INC{'Role/Tiny.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Role/Tiny.pm"} and not "Role::Tiny"->can("is_role") and $Role::Tiny::INFO{$target}) 0 50 50
Condition50%3/6
$INC{"Role/Tiny.pm"} and not "Role::Tiny"->can("is_role") and $Role::Tiny::INFO{$target}
!ll&&!rl&&r
5000
$INC{"Role/Tiny.pm"} and not "Role::Tiny"->can("is_role")
!ll&&!rl&&r
31190
MC/DC0%0/3
$INC{"Role/Tiny.pm"} and not "Role::Tiny"->can("is_role") and $Role::Tiny::INFO{$target}
$INC{"Role/Tiny.pm"} not "Role::Tiny"->can("is_role") $Role::Tiny::INFO{$target}
Truth table50%2/4
A and not(B) and C
A= $INC{"Role/Tiny.pm"}B= not "Role::Tiny"->can("is_role")C= $Role::Tiny::INFO{$target}
ABCresult
0XX0
10X0
1100
1111
51 and !'Role::Tiny'->can('is_role')
52 and $Role::Tiny::INFO{$target}) {
53 0 return 'Role::Tiny'; # uncoverable statement
54 }
55
56 50 ▶ if ($INC{'Moose/Meta/Role.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moose/Meta/Role.pm"} and do { require Moose::Util; 1 } and Moose::Util::find_meta($target)->$_isa("Moose::Meta::Role")) 26 24 50
Condition83%5/6
$INC{"Moose/Meta/Role.pm"} and do { require Moose::Util; 1 } and Moose::Util::find_meta($target)->$_isa("Moose::Meta::Role")
!ll&&!rl&&r
20426
$INC{"Moose/Meta/Role.pm"} and do { require Moose::Util; 1 }
!ll&&!rl&&r
20030
MC/DC66%2/3
$INC{"Moose/Meta/Role.pm"} and do { require Moose::Util; 1 } and Moose::Util::find_meta($target)->$_isa("Moose::Meta::Role")
$INC{"Moose/Meta/Role.pm"} do { require Moose::Util; 1 } Moose::Util::find_meta($target)->$_isa("Moose::Meta::Role")
Truth table75%3/4
A and B and C
A= $INC{"Moose/Meta/Role.pm"}B= do { require Moose::Util; 1 }C= Moose::Util::find_meta($target)->$_isa("Moose::Meta::Role")
ABCresult
0XX0
10X0
1100
1111
57 30 and do { require Moose::Util; 1 }
58 and Moose::Util::find_meta($target)->$_isa('Moose::Meta::Role')) {
59 26 return 'Moose::Role';
60 }
61
62 24 ▶ if ($INC{'Mouse/Meta/Role.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Mouse/Meta/Role.pm"} and do { require Mouse::Util; 1 } and Mouse::Util::find_meta($target)->$_isa("Mouse::Meta::Role")) 0 24 24
Condition33%2/6
$INC{"Mouse/Meta/Role.pm"} and do { require Mouse::Util; 1 } and Mouse::Util::find_meta($target)->$_isa("Mouse::Meta::Role")
!ll&&!rl&&r
2400
$INC{"Mouse/Meta/Role.pm"} and do { require Mouse::Util; 1 }
!ll&&!rl&&r
2400
MC/DC0%0/3
$INC{"Mouse/Meta/Role.pm"} and do { require Mouse::Util; 1 } and Mouse::Util::find_meta($target)->$_isa("Mouse::Meta::Role")
$INC{"Mouse/Meta/Role.pm"} do { require Mouse::Util; 1 } Mouse::Util::find_meta($target)->$_isa("Mouse::Meta::Role")
Truth table25%1/4
A and B and C
A= $INC{"Mouse/Meta/Role.pm"}B= do { require Mouse::Util; 1 }C= Mouse::Util::find_meta($target)->$_isa("Mouse::Meta::Role")
ABCresult
0XX0
10X0
1100
1111
63 0 and do { require Mouse::Util; 1 }
64 and Mouse::Util::find_meta($target)->$_isa('Mouse::Meta::Role')) {
65 0 return 'Mouse::Role';
66 }
67
68 24 ▶ if ($INC{'Role/Basic.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Role/Basic.pm"} and eval { do { "Role::Basic"->_load_role($target) } }) 0 24 24
Condition33%1/3
$INC{"Role/Basic.pm"} and eval { do { "Role::Basic"->_load_role($target) } }
!ll&&!rl&&r
2400
MC/DC0%0/2
$INC{"Role/Basic.pm"} and eval { do { "Role::Basic"->_load_role($target) } }
$INC{"Role/Basic.pm"} eval { do { "Role::Basic"->_load_role($target) } }
Truth table33%1/3
A and B
A= $INC{"Role/Basic.pm"}B= eval { do { "Role::Basic"->_load_role($target) } }
ABresult
0X0
100
111
69 0 and eval { 'Role::Basic'->_load_role($target) }) {
70 0 return 'Role::Basic';
71 }
72
73 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 10 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 24 my $UM = ${"$target\::USES_MITE"};
76 24 ▶ if ( defined $UM and $UM eq 'Mite::Role' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $UM and $UM eq "Mite::Role") 13 11 24
Condition100%3/3
defined $UM and $UM eq "Mite::Role"
!ll&&!rl&&r
9213
MC/DC100%2/2
defined $UM and $UM eq "Mite::Role"
defined $UM $UM eq "Mite::Role"
Truth table100%3/3
A and B
A= defined $UMB= $UM eq "Mite::Role"
ABresult
0X0
100
111
77 13 return 'Mite::Role';
78 }
79
80 11 return undef;
81 }
82  
83 20 ▶sub before_apply {
Subroutine before_apply: called CC=4 SCAR=13.9
Pod documented
84 20 my ($me, $target, @callbacks) = @_;
85 20 ▶ return unless @callbacks;
Branch: 1 branch
BranchTrueFalseTotal
unless @callbacks 1 19 20
86 19 ▶ $me->is_role($target) or $me->_croak('%s is not a role', $target);
Branch: 1 branch
BranchTrueFalseTotal
$me->is_role($target) or $me->_croak("%s is not a role", $target) 19 0 19
87 19 $me->_install_patches($target);
88 19 ▶ push @{ $CALLBACKS_BEFORE_APPLY{$target}||=[] }, @callbacks;
Condition100%2/2
$CALLBACKS_BEFORE_APPLY{$target} ||= []
l!l
613
MC/DC100%1/1
$CALLBACKS_BEFORE_APPLY{$target} ||= []
$CALLBACKS_BEFORE_APPLY{$target}
Truth table100%2/2
A
A= $CALLBACKS_BEFORE_APPLY{$target}
Aresult
11
00
89 19 return $me;
90 }
91  
92 19 ▶sub after_apply {
Subroutine after_apply: called CC=4 SCAR=13.9
Pod documented
93 19 my ($me, $target, @callbacks) = @_;
94 19 ▶ return unless @callbacks;
Branch: 1 branch
BranchTrueFalseTotal
unless @callbacks 1 18 19
95 18 ▶ $me->is_role($target) or $me->_croak('%s is not a role', $target);
Branch: 1 branch
BranchTrueFalseTotal
$me->is_role($target) or $me->_croak("%s is not a role", $target) 18 0 18
96 18 $me->_install_patches($target);
97 18 ▶ push @{ $CALLBACKS_AFTER_APPLY{$target}||=[] }, @callbacks;
Condition100%2/2
$CALLBACKS_AFTER_APPLY{$target} ||= []
l!l
612
MC/DC100%1/1
$CALLBACKS_AFTER_APPLY{$target} ||= []
$CALLBACKS_AFTER_APPLY{$target}
Truth table100%2/2
A
A= $CALLBACKS_AFTER_APPLY{$target}
Aresult
11
00
98 18 return $me;
99 }
100  
101 6 ▶sub after_inflate {
Subroutine after_inflate: called CC=5 SCAR=16.3
Pod documented
102 10 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
103 6 my ($me, $target, @callbacks) = @_;
104 6 ▶ return unless @callbacks;
Branch: 1 branch
BranchTrueFalseTotal
unless @callbacks 3 3 6
105 3 ▶ $me->is_role($target) eq 'Role::Tiny'
Branch: 1 branch
BranchTrueFalseTotal
$me->is_role($target) eq "Role::Tiny" or $target->isa("Moo::Object") or $me->_croak("%s is not a Moo class or role", $target) 3 0 3
Condition66%2/3
$me->is_role($target) eq "Role::Tiny" or $target->isa("Moo::Object")
l!l&&r!l&&!r
210
MC/DC0%0/2
$me->is_role($target) eq "Role::Tiny" or $target->isa("Moo::Object")
$me->is_role($target) eq "Role::Tiny" $target->isa("Moo::Object")
Truth table66%2/3
A or B
A= $me->is_role($target) eq "Role::Tiny"B= $target->isa("Moo::Object")
ABresult
1X1
011
000
106 or $target->isa('Moo::Object')
107 or $me->_croak('%s is not a Moo class or role', $target);
108 3 $me->_install_patches($target);
109 3 $me->_install_patches_inflation($target);
110 3 ▶ push @{ $CALLBACKS_AFTER_INFLATE{$target}||=[] }, @callbacks;
Condition50%1/2
$CALLBACKS_AFTER_INFLATE{$target} ||= []
l!l
03
MC/DC0%0/1
$CALLBACKS_AFTER_INFLATE{$target} ||= []
$CALLBACKS_AFTER_INFLATE{$target}
Truth table50%1/2
A
A= $CALLBACKS_AFTER_INFLATE{$target}
Aresult
11
00
111 3 return $me;
112 }
113  
114 {
115 # Internals for monkey-patching role implementations.
116 #
117
118 10 my %patched;
119 40 ▶ sub _install_patches {
Subroutine _install_patches: called CC=17 SCAR=31.7
120 40 my ($me, $target) = @_;
121
122 40 ▶ if ($INC{'Role/Tiny.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Role/Tiny.pm"}) 27 13 40
123 27 ▶ $patched{'Role::Tiny'} ||= $me->_install_patches_roletiny;
Condition66%2/3
$patched{"Role::Tiny"} ||= $me->_install_patches_roletiny
l!l&&r!l&&!r
2250
MC/DC0%0/2
$patched{"Role::Tiny"} ||= $me->_install_patches_roletiny
$patched{"Role::Tiny"} $me->_install_patches_roletiny
Truth table66%2/3
A ||= B
A= $patched{"Role::Tiny"}B= $me->_install_patches_roletiny
ABresult
1X1
011
000
124 }
125 40 ▶ if ($INC{'Moo/Role.pm'} or $INC{'Moo.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moo/Role.pm"} or $INC{"Moo.pm"}) 21 19 40
Condition100%3/3
$INC{"Moo/Role.pm"} or $INC{"Moo.pm"}
l!l&&r!l&&!r
20119
MC/DC100%2/2
$INC{"Moo/Role.pm"} or $INC{"Moo.pm"}
$INC{"Moo/Role.pm"} $INC{"Moo.pm"}
Truth table100%3/3
A or B
A= $INC{"Moo/Role.pm"}B= $INC{"Moo.pm"}
ABresult
1X1
011
000
126 21 ▶ $patched{'Moo::Role'} ||= $me->_install_patches_moorole;
Condition66%2/3
$patched{"Moo::Role"} ||= $me->_install_patches_moorole
l!l&&r!l&&!r
1740
MC/DC0%0/2
$patched{"Moo::Role"} ||= $me->_install_patches_moorole
$patched{"Moo::Role"} $me->_install_patches_moorole
Truth table66%2/3
A ||= B
A= $patched{"Moo::Role"}B= $me->_install_patches_moorole
ABresult
1X1
011
000
127 }
128 40 ▶ if ($INC{'Moose/Role.pm'} or $INC{'Moose.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moose/Role.pm"} or $INC{"Moose.pm"}) 19 21 40
Condition100%3/3
$INC{"Moose/Role.pm"} or $INC{"Moose.pm"}
l!l&&r!l&&!r
12721
MC/DC100%2/2
$INC{"Moose/Role.pm"} or $INC{"Moose.pm"}
$INC{"Moose/Role.pm"} $INC{"Moose.pm"}
Truth table100%3/3
A or B
A= $INC{"Moose/Role.pm"}B= $INC{"Moose.pm"}
ABresult
1X1
011
000
129 19 ▶ $patched{'Moose::Role'} ||= $me->_install_patches_mooserole;
Condition66%2/3
$patched{"Moose::Role"} ||= $me->_install_patches_mooserole
l!l&&r!l&&!r
1540
MC/DC0%0/2
$patched{"Moose::Role"} ||= $me->_install_patches_mooserole
$patched{"Moose::Role"} $me->_install_patches_mooserole
Truth table66%2/3
A ||= B
A= $patched{"Moose::Role"}B= $me->_install_patches_mooserole
ABresult
1X1
011
000
130 }
131 40 ▶ if ($INC{'Mouse/Role.pm'} or $INC{'Mouse.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Mouse/Role.pm"} or $INC{"Mouse.pm"}) 0 40 40
Condition33%1/3
$INC{"Mouse/Role.pm"} or $INC{"Mouse.pm"}
l!l&&r!l&&!r
0040
MC/DC0%0/2
$INC{"Mouse/Role.pm"} or $INC{"Mouse.pm"}
$INC{"Mouse/Role.pm"} $INC{"Mouse.pm"}
Truth table33%1/3
A or B
A= $INC{"Mouse/Role.pm"}B= $INC{"Mouse.pm"}
ABresult
1X1
011
000
132 0 ▶ $patched{'Mouse::Role'} ||= $me->_install_patches_mouserole;
Condition0%0/3
$patched{"Mouse::Role"} ||= $me->_install_patches_mouserole
l!l&&r!l&&!r
000
MC/DC0%0/2
$patched{"Mouse::Role"} ||= $me->_install_patches_mouserole
$patched{"Mouse::Role"} $me->_install_patches_mouserole
Truth table0%0/3
A ||= B
A= $patched{"Mouse::Role"}B= $me->_install_patches_mouserole
ABresult
1X1
011
000
133 }
134 40 ▶ if ($INC{'Role/Basic.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Role/Basic.pm"}) 0 40 40
135 0 ▶ $patched{'Role::Basic'} ||= $me->_install_patches_rolebasic;
Condition0%0/3
$patched{"Role::Basic"} ||= $me->_install_patches_rolebasic
l!l&&r!l&&!r
000
MC/DC0%0/2
$patched{"Role::Basic"} ||= $me->_install_patches_rolebasic
$patched{"Role::Basic"} $me->_install_patches_rolebasic
Truth table0%0/3
A ||= B
A= $patched{"Role::Basic"}B= $me->_install_patches_rolebasic
ABresult
1X1
011
000
136 }
137
138 40 my $is_role = $me->is_role($target);
139 40 ▶ if ( defined $is_role and $is_role eq 'Mite::Role' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $is_role and $is_role eq "Mite::Role") 6 34 40
Condition100%3/3
defined $is_role and $is_role eq "Mite::Role"
!ll&&!rl&&r
1336
MC/DC100%2/2
defined $is_role and $is_role eq "Mite::Role"
defined $is_role $is_role eq "Mite::Role"
Truth table100%3/3
A and B
A= defined $is_roleB= $is_role eq "Mite::Role"
ABresult
0X0
100
111
140 6 ▶ $patched{'Mite::Role'}{$target} ||= $me->_install_patches_miterole($target);
Condition66%2/3
$patched{"Mite::Role"}{$target} ||= $me->_install_patches_miterole($target)
l!l&&r!l&&!r
420
MC/DC0%0/2
$patched{"Mite::Role"}{$target} ||= $me->_install_patches_miterole($target)
$patched{"Mite::Role"}{$target} $me->_install_patches_miterole($target)
Truth table66%2/3
A ||= B
A= $patched{"Mite::Role"}{$target}B= $me->_install_patches_miterole($target)
ABresult
1X1
011
000
141 }
142 }
143
144 10 my %patched_inflation;
145 3 ▶ sub _install_patches_inflation {
Subroutine _install_patches_inflation: called CC=4 SCAR=15.6
146 3 my ($me, $target) = @_;
147 3 ▶ if ($INC{'Moo/Role.pm'} or $INC{'Moo.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moo/Role.pm"} or $INC{"Moo.pm"}) 3 0 3
Condition33%1/3
$INC{"Moo/Role.pm"} or $INC{"Moo.pm"}
l!l&&r!l&&!r
300
MC/DC0%0/2
$INC{"Moo/Role.pm"} or $INC{"Moo.pm"}
$INC{"Moo/Role.pm"} $INC{"Moo.pm"}
Truth table33%1/3
A or B
A= $INC{"Moo/Role.pm"}B= $INC{"Moo.pm"}
ABresult
1X1
011
000
148 3 ▶ $patched_inflation{'Moo::Role'} ||= $me->_install_patches_moorole_inflation;
Condition66%2/3
$patched_inflation{"Moo::Role"} ||= $me->_install_patches_moorole_inflation
l!l&&r!l&&!r
210
MC/DC0%0/2
$patched_inflation{"Moo::Role"} ||= $me->_install_patches_moorole_inflation
$patched_inflation{"Moo::Role"} $me->_install_patches_moorole_inflation
Truth table66%2/3
A ||= B
A= $patched_inflation{"Moo::Role"}B= $me->_install_patches_moorole_inflation
ABresult
1X1
011
000
149 }
150 }
151
152 6 ▶ sub _install_patches_roletiny {
Subroutine _install_patches_roletiny: called CC=2 SCAR=6.9
153 6 my ($me) = @_;
154 6 ▶ return 1 if $patched{'Role::Tiny'};
Branch: 1 branch
BranchTrueFalseTotal
if $patched{"Role::Tiny"} 0 6 6
155
156 6 $me->_debug("Installing patches for Role::Tiny") if DEBUG;
157
158 6 require Role::Tiny;
159
160 8 ▶ install_modifier 'Role::Tiny', around => 'role_application_steps', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
161 8 my $orig = shift;
162 8 my @steps = $orig->(@_);
163 return (
164 8 __PACKAGE__ . '::_run_role_tiny_before_callbacks',
165 @steps,
166 __PACKAGE__ . '::_run_role_tiny_after_callbacks',
167 );
168 6 };
169
170 8 ▶ *_run_role_tiny_before_callbacks = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
171 8 my (undef, $to, $role) = @_;
172 8 $me->_debug("Calling role hooks for $role before application to $to") if DEBUG;
173 8 ▶ my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] };
Condition100%2/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
62
MC/DC100%1/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table100%2/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
174 8 for my $cb (@callbacks) {
175 9 $cb->($role, $to);
176 }
177 8 return;
178 6 };
179
180 8 ▶ *_run_role_tiny_after_callbacks = sub {
Subroutine __ANON__: called CC=9 SCAR=22.1
181 8 my (undef, $to, $role) = @_;
182 8 $me->_debug("Calling role hooks for $role after application to $to") if DEBUG;
183 8 ▶ my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] };
Condition100%2/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
62
MC/DC100%1/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table100%2/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
184 8 for my $cb (@callbacks) {
185 9 $cb->($role, $to);
186 }
187 8 ▶ if (my $is_role = $me->is_role($to)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $is_role = $me->is_role($to)) 4 4 8
188 4 $me->_debug("Copying role hooks for $role to $to") if DEBUG;
189 4 ▶ $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] });
Condition100%2/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
31
MC/DC100%1/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table100%2/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
190 4 ▶ $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] });
Condition100%2/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
31
MC/DC100%1/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table100%2/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
191 4 ▶ if ($is_role eq 'Role::Tiny' or $to->isa('Moo::Object')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_role eq "Role::Tiny" or $to->isa("Moo::Object")) 4 0 4
Condition33%1/3
$is_role eq "Role::Tiny" or $to->isa("Moo::Object")
l!l&&r!l&&!r
400
MC/DC0%0/2
$is_role eq "Role::Tiny" or $to->isa("Moo::Object")
$is_role eq "Role::Tiny" $to->isa("Moo::Object")
Truth table33%1/3
A or B
A= $is_role eq "Role::Tiny"B= $to->isa("Moo::Object")
ABresult
1X1
011
000
192 4 ▶ $me->after_inflate($to, @{ $CALLBACKS_AFTER_INFLATE{$role} || [] });
Condition100%2/2
$CALLBACKS_AFTER_INFLATE{$role} || []
l!l
13
MC/DC100%1/1
$CALLBACKS_AFTER_INFLATE{$role} || []
$CALLBACKS_AFTER_INFLATE{$role}
Truth table100%2/2
A
A= $CALLBACKS_AFTER_INFLATE{$role}
Aresult
11
00
193 }
194 }
195 8 return;
196 6 };
197
198 6 return 1;
199 }
200
201 4 ▶ sub _install_patches_moorole {
Subroutine _install_patches_moorole: called CC=3 SCAR=11.0
202 4 my ($me) = @_;
203 4 ▶ $patched{'Role::Tiny'} ||= $me->_install_patches_roletiny;
Condition66%2/3
$patched{"Role::Tiny"} ||= $me->_install_patches_roletiny
l!l&&r!l&&!r
310
MC/DC0%0/2
$patched{"Role::Tiny"} ||= $me->_install_patches_roletiny
$patched{"Role::Tiny"} $me->_install_patches_roletiny
Truth table66%2/3
A ||= B
A= $patched{"Role::Tiny"}B= $me->_install_patches_roletiny
ABresult
1X1
011
000
204 4 ▶ return 1 if $patched{'Moo::Role'};
Branch: 1 branch
BranchTrueFalseTotal
if $patched{"Moo::Role"} 0 4 4
205
206 4 $me->_debug("Installing patches for Moo::Role") if DEBUG;
207
208 4 require Moo::Role;
209 4 require List::Util;
210
211 # Mostly can just rely on Role::Tiny, but need
212 # to move _run_callbacks_before_apply to the
213 # front of the queue!
214 #
215 5 ▶ install_modifier 'Moo::Role', around => 'role_application_steps', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
216 5 my $orig = shift;
217 5 my @steps = $orig->(@_);
218 5 return List::Util::uniqstr(
219 __PACKAGE__ . '::_run_role_tiny_before_callbacks',
220 @steps,
221 );
222 4 };
223
224 4 return 1;
225 }
226
227 1 ▶ sub _install_patches_moorole_inflation {
Subroutine _install_patches_moorole_inflation: called CC=2 SCAR=6.9
228 1 my ($me) = @_;
229 1 ▶ return 1 if $patched_inflation{'Moo::Role'};
Branch: 1 branch
BranchTrueFalseTotal
if $patched_inflation{"Moo::Role"} 0 1 1
230
231 1 $me->_debug("Installing inflation patches for Moo::Role") if DEBUG;
232
233 1 require Moo::HandleMoose;
234
235 4 ▶ install_modifier 'Moo::HandleMoose', after => 'inject_real_metaclass_for', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
236 4 my ( $name ) = @_;
237 4 $me->_run_moo_inhale_callbacks( $name );
238 1 };
239
240 1 my %already;
241 4 ▶ *_run_moo_inhale_callbacks = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
242 4 my (undef, $name) = @_;
243 4 $me->_debug("Calling role hooks for $name after inflation") if DEBUG;
244 4 ▶ my @callbacks = @{ $CALLBACKS_AFTER_INFLATE{$name} || [] };
Condition50%1/2
$CALLBACKS_AFTER_INFLATE{$name} || []
l!l
40
MC/DC0%0/1
$CALLBACKS_AFTER_INFLATE{$name} || []
$CALLBACKS_AFTER_INFLATE{$name}
Truth table50%1/2
A
A= $CALLBACKS_AFTER_INFLATE{$name}
Aresult
11
00
245 4 for my $cb (@callbacks) {
246 4 ▶ next if $already{"$name|$cb"}++;
Branch: 1 branch
BranchTrueFalseTotal
if $already{"$name|$cb"}++ 1 3 4
247 3 $cb->($name);
248 }
249 1 };
250
251 1 return 1;
252 }
253
254 4 ▶ sub _install_patches_mooserole {
Subroutine _install_patches_mooserole: called CC=2 SCAR=7.0
255 4 my ($me) = @_;
256 4 ▶ return 1 if $patched{'Moose::Role'};
Branch: 1 branch
BranchTrueFalseTotal
if $patched{"Moose::Role"} 0 4 4
257
258 4 $me->_debug("Installing patches for Moose::Role") if DEBUG;
259
260 4 require Moose::Meta::Role;
261
262 4 ▶ install_modifier 'Moose::Meta::Role', around => 'apply', sub {
Subroutine __ANON__: called CC=8 SCAR=20.9
263 4 my ($orig, $role_meta, $to_meta, %args) = @_;
264 4 local *ARGS = \%args;
265 4 my $role = $role_meta->name;
266 4 my $to = $to_meta->name;
267 4 do {
268 4 $me->_debug("Calling role hooks for $role before application to $to") if DEBUG;
269 4 ▶ my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] };
Condition50%1/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
40
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
270 4 for my $cb (@callbacks) {
271 6 $cb->($role, $to);
272 }
273 };
274 4 my $application = $role_meta->$orig($to_meta, %args);
275 4 do {
276 4 $me->_debug("Calling role hooks for $role after application to $to") if DEBUG;
277 4 ▶ my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] };
Condition50%1/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
40
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
278 4 for my $cb (@callbacks) {
279 6 $cb->($role, $to);
280 }
281 };
282 4 ▶ if ($me->is_role($to)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->is_role($to)) 2 2 4
283 2 $me->_debug("Copying role hooks for $role to $to") if DEBUG;
284 2 ▶ $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] });
Condition50%1/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
20
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
285 2 ▶ $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] });
Condition50%1/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
20
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
286 }
287 4 return $application;
288 4 };
289
290 4 return 1;
291 }
292
293 0 ▶ sub _install_patches_mouserole {
Subroutine _install_patches_mouserole: not called CC=2 SCAR=17.9
294 0 my ($me) = @_;
295 0 ▶ return 1 if $patched{'Mouse::Role'};
Branch: 1 branch
BranchTrueFalseTotal
if $patched{"Mouse::Role"} 0 0 0
296
297 0 $me->_debug("Installing patches for Mouse::Role") if DEBUG;
298
299 0 require Mouse::Meta::Role;
300
301 0 ▶ install_modifier 'Mouse::Meta::Role', around => 'apply', sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
302 0 my ($orig, $role_meta, $to_meta, %args) = @_;
303 0 local *ARGS = \%args;
304 0 my $role = $role_meta->name;
305 0 my $to = $to_meta->name;
306 0 do {
307 0 $me->_debug("Calling role hooks for $role before application to $to") if DEBUG;
308 0 ▶ my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] };
Condition0%0/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
309 0 for my $cb (@callbacks) {
310 0 $cb->($role, $to);
311 }
312 };
313 0 my $application = $role_meta->$orig($to_meta, %args);
314 0 do {
315 0 $me->_debug("Calling role hooks for $role after application to $to") if DEBUG;
316 0 ▶ my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] };
Condition0%0/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
317 0 for my $cb (@callbacks) {
318 0 $cb->($role, $to);
319 }
320 };
321 0 ▶ if ($me->is_role($to)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->is_role($to)) 0 0 0
322 0 $me->_debug("Copying role hooks for $role to $to") if DEBUG;
323 0 ▶ $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] });
Condition0%0/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
324 0 ▶ $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] });
Condition0%0/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
325 }
326 0 return $application;
327 0 };
328
329 0 return 1;
330 }
331
332 0 ▶ sub _install_patches_rolebasic {
Subroutine _install_patches_rolebasic: not called CC=3 SCAR=24.8
333 0 my ($me) = @_;
334 0 ▶ return 1 if $patched{'Role::Basic'};
Branch: 1 branch
BranchTrueFalseTotal
if $patched{"Role::Basic"} 0 0 0
335
336 0 $me->_debug("Installing patches for Role::Basic") if DEBUG;
337
338 0 require Role::Basic;
339
340 0 ▶ $me->_carp("Role::Hooks is only tested with Role::Basic 0.07 to 0.13")
Branch: 1 branch
BranchTrueFalseTotal
unless $Role::Basic::VERSION =~ /^0\.(?:0[7-9]|1[0-3])/ 0 0 0
341 unless $Role::Basic::VERSION =~ /^0\.(?:0[7-9]|1[0-3])/;
342
343 0 ▶ install_modifier 'Role::Basic', around => '_add_role_methods_to_target', sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
344 0 my ($orig, $rb, $role, $to, $modifiers) = @_;
345 0 local *ARGS = $modifiers;
346 0 do {
347 0 $me->_debug("Calling role hooks for $role before application to $to") if DEBUG;
348 0 ▶ my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] };
Condition0%0/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
349 0 for my $cb (@callbacks) {
350 0 $cb->($role, $to);
351 }
352 };
353 0 my $application = $rb->$orig($role, $to, $modifiers);
354 0 do {
355 0 $me->_debug("Calling role hooks for $role after application to $to") if DEBUG;
356 0 ▶ my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] };
Condition0%0/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
357 0 for my $cb (@callbacks) {
358 0 $cb->($role, $to);
359 }
360 };
361 0 ▶ if ($me->is_role($to)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->is_role($to)) 0 0 0
362 0 $me->_debug("Copying role hooks for $role to $to") if DEBUG;
363 0 ▶ $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] });
Condition0%0/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
364 0 ▶ $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] });
Condition0%0/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
00
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table0%0/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
365 }
366 0 return $application;
367 0 };
368
369 0 return 1;
370 }
371
372 2 ▶ sub _install_patches_miterole {
Subroutine _install_patches_miterole: called CC=2 SCAR=7.0
373 2 my ($me, $target) = @_;
374 2 ▶ return 1 if $ENV{MITE_COMPILE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"MITE_COMPILE"} 0 2 2
375 3 ▶ install_modifier $target, around => '__FINALIZE_APPLICATION__', sub {
Subroutine __ANON__: called CC=13 SCAR=25.8
376 3 my ($orig, $role, $to, $modifiers) = @_;
377 3 ▶ local *ARGS = $modifiers || {};
Condition100%2/2
$modifiers || {}
l!l
12
MC/DC100%1/1
$modifiers || {}
$modifiers
Truth table100%2/2
A
A= $modifiers
Aresult
11
00
378 3 ▶ my $indirect = ( $modifiers || {} )->{-indirect};
Condition100%2/2
$modifiers || {}
l!l
12
MC/DC100%1/1
$modifiers || {}
$modifiers
Truth table100%2/2
A
A= $modifiers
Aresult
11
00
379 3 ▶ if ( not $indirect ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($indirect) 2 1 3
380 2 $me->_debug("Calling role hooks for $role before application to $to") if DEBUG;
381 2 ▶ my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] };
Condition50%1/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
20
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
382 2 for my $cb (@callbacks) {
383 3 $cb->($role, $to);
384 }
385 }
386 3 $role->$orig($to, $modifiers);
387 3 ▶ if ( not $indirect ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($indirect) 2 1 3
388 2 $me->_debug("Calling role hooks for $role after application to $to") if DEBUG;
389 2 ▶ my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] };
Condition50%1/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
20
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
390 2 for my $cb (@callbacks) {
391 3 $cb->($role, $to);
392 }
393 }
394 3 my $to_type = $me->is_role($to);
395 3 ▶ if (defined $to_type and $to_type eq 'Mite::Role') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to_type and $to_type eq "Mite::Role") 1 2 3
Condition66%2/3
defined $to_type and $to_type eq "Mite::Role"
!ll&&!rl&&r
201
MC/DC50%1/2
defined $to_type and $to_type eq "Mite::Role"
defined $to_type $to_type eq "Mite::Role"
Truth table66%2/3
A and B
A= defined $to_typeB= $to_type eq "Mite::Role"
ABresult
0X0
100
111
396 1 $me->_debug("Copying role hooks for $role to $to") if DEBUG;
397 1 ▶ $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] });
Condition50%1/2
$CALLBACKS_BEFORE_APPLY{$role} || []
l!l
10
MC/DC0%0/1
$CALLBACKS_BEFORE_APPLY{$role} || []
$CALLBACKS_BEFORE_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_BEFORE_APPLY{$role}
Aresult
11
00
398 1 ▶ $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] });
Condition50%1/2
$CALLBACKS_AFTER_APPLY{$role} || []
l!l
10
MC/DC0%0/1
$CALLBACKS_AFTER_APPLY{$role} || []
$CALLBACKS_AFTER_APPLY{$role}
Truth table50%1/2
A
A= $CALLBACKS_AFTER_APPLY{$role}
Aresult
11
00
399 }
400 2 };
401 2 1;
402 }
403 }
404  
405 10 1;
406  
407 __END__
↑ Summary