blib/lib/Moose/Meta/Role/Application/ToRole.pm

filter: Statementstmt 100% 66 / 66 Branchbran 96.4% 27 / 28 Conditioncond 75.0% 9 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 13 / 13 Podpod 100% 8 / 8 totaltotal 94.8% 128 / 135 CC 26 SCAR 17.1
CC
26
Cov
96%
apply_methods
11.1
apply_override_method_modifiers
5.0
apply_attributes
4.0
CRAP 5.5
« blib/lib/Moose/Meta/Method/Delegation.pm ↑ Summary blib/lib/Moose/Exception/InvalidArgPassedToMooseUtilMetaRole.pm »
1 package Moose::Meta::Role::Application::ToRole;
2 385 our $VERSION = '2.4001';
3  
4 385 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 385 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 385 ▶use metaclass;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 385 ▶use parent 'Moose::Meta::Role::Application';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 385 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 504 ▶sub apply {
Subroutine apply: called CC=1 SCAR=0.0
Pod documented
13 504 my ($self, $role1, $role2) = @_;
14 504 $self->SUPER::apply($role1, $role2);
15 497 $role2->add_role($role1);
16 }
17  
18 506 ▶sub check_role_exclusions {
Subroutine check_role_exclusions: called CC=4 SCAR=13.9
Pod documented
19 506 my ($self, $role1, $role2) = @_;
20 506 ▶ if ( $role2->excludes_role($role1->name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($role2->excludes_role($role1->name)) 1 505 506
21 1 throw_exception( ConflictDetectedInCheckRoleExclusions => role_name => $role2->name,
22 excluded_role_name => $role1->name,
23 );
24 }
25 505 foreach my $excluded_role_name ($role1->get_excluded_roles_list) {
26 2 ▶ if ( $role2->does_role($excluded_role_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($role2->does_role($excluded_role_name)) 1 1 2
27 1 throw_exception( RoleDoesTheExcludedRole => role_name => $role2->name,
28 excluded_role_name => $excluded_role_name,
29 second_role_name => $role1->name,
30 );
31 }
32 1 $role2->add_excluded_roles($excluded_role_name);
33 }
34 }
35  
36 504 ▶sub check_required_methods {
Subroutine check_required_methods: called CC=4 SCAR=13.9
Pod documented
37 504 my ($self, $role1, $role2) = @_;
38 504 foreach my $required_method ($role1->get_required_method_list) {
39 641 my $required_method_name = $required_method->name;
40  
41 641 ▶ next if $self->is_aliased_method($required_method_name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_aliased_method($required_method_name) 3 638 641
42  
43 638 ▶ $role2->add_required_methods($required_method)
Branch: 1 branch
BranchTrueFalseTotal
unless $role2->find_method_by_name($required_method_name) 144 494 638
44 unless $role2->find_method_by_name($required_method_name);
45 }
46 }
47  
48 504 ▶sub check_required_attributes {
Subroutine check_required_attributes: called CC=1 SCAR=0.0
Pod documented
49  
50 }
51  
52 505 ▶sub apply_attributes {
Subroutine apply_attributes: called CC=4 SCAR=13.9
Pod documented
53 505 my ($self, $role1, $role2) = @_;
54 505 foreach my $attribute_name ($role1->get_attribute_list) {
55 # it if it has one already
56 86 ▶ if ($role2->has_attribute($attribute_name) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($role2->has_attribute($attribute_name) and $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) { } 2 84 86
Condition66%2/3
$role2->has_attribute($attribute_name) and $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)
!ll&&!rl&&r
8402
MC/DC50%1/2
$role2->has_attribute($attribute_name) and $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)
$role2->has_attribute($attribute_name) $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)
Truth table66%2/3
A and B
A= $role2->has_attribute($attribute_name)B= $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)
ABresult
0X0
100
111
57 # make sure we haven't seen this one already too
58 $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) {
59  
60 2 my $role2_name = $role2->name;
61  
62 2 throw_exception( AttributeConflictInRoles => role_name => $role1->name,
63 second_role_name => $role2->name,
64 attribute_name => $attribute_name
65 );
66 }
67 else {
68 84 $role2->add_attribute(
69 $role1->get_attribute($attribute_name)->clone
70 );
71 }
72 }
73 }
74  
75 503 ▶sub apply_methods {
Subroutine apply_methods: called CC=11 SCAR=24.0
Pod documented
76 503 my ( $self, $role1, $role2 ) = @_;
77 503 foreach my $method ( $role1->_get_local_methods ) {
78  
79 7201 my $method_name = $method->name;
80  
81 7201 ▶ next if $method->isa('Class::MOP::Method::Meta');
Branch: 1 branch
BranchTrueFalseTotal
if $method->isa("Class::MOP::Method::Meta") 425 6776 7201
82  
83 6776 ▶ unless ( $self->is_method_excluded($method_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_method_excluded($method_name)) 6767 9 6776
84  
85 6767 my $role2_method = $role2->get_method($method_name);
86 6767 ▶ if ( $role2_method
Branch: 1 branch
BranchTrueFalseTotal
if ($role2_method and $role2_method->body != $method->body) { } 726 6041 6767
Condition66%2/3
$role2_method and $role2_method->body != $method->body
!ll&&!rl&&r
60410726
MC/DC50%1/2
$role2_method and $role2_method->body != $method->body
$role2_method $role2_method->body != $method->body
Truth table66%2/3
A and B
A= $role2_methodB= $role2_method->body != $method->body
ABresult
0X0
100
111
87 && $role2_method->body != $method->body ) {
88  
89 # method conflicts between roles used to result in the method
90 # becoming a requirement but now are permitted just like
91 # for classes, hence no code in this branch anymore.
92 }
93 else {
94 6041 $role2->add_method(
95 $method_name,
96 $method,
97 );
98 }
99 }
100  
101 6776 ▶ next unless $self->is_method_aliased($method_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_method_aliased($method_name) 6765 11 6776
102  
103 11 my $aliased_method_name = $self->get_method_aliases->{$method_name};
104  
105 11 my $role2_method = $role2->get_method($aliased_method_name);
106  
107 11 ▶ if ( $role2_method
Branch: 1 branch
BranchTrueFalseTotal
if ($role2_method and $role2_method->body != $method->body) 2 9 11
Condition66%2/3
$role2_method and $role2_method->body != $method->body
!ll&&!rl&&r
902
MC/DC50%1/2
$role2_method and $role2_method->body != $method->body
$role2_method $role2_method->body != $method->body
Truth table66%2/3
A and B
A= $role2_methodB= $role2_method->body != $method->body
ABresult
0X0
100
111
108 && $role2_method->body != $method->body ) {
109  
110 2 throw_exception( CannotCreateMethodAliasLocalMethodIsPresent => aliased_method_name => $aliased_method_name,
111 method => $method,
112 role_name => $role2->name,
113 role_being_applied_name => $role1->name,
114 );
115 }
116  
117 $role2->add_method(
118 9 $aliased_method_name,
119 $role1->get_method($method_name)
120 );
121  
122 9 ▶ if ( !$role2->has_method($method_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($role2->has_method($method_name)) 2 7 9
123 2 ▶ $role2->add_required_methods($method_name)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_method_excluded($method_name) 0 2 2
124 unless $self->is_method_excluded($method_name);
125 }
126 }
127 }
128  
129 501 ▶sub apply_override_method_modifiers {
Subroutine apply_override_method_modifiers: called CC=5 SCAR=16.1
Pod documented
130 501 my ($self, $role1, $role2) = @_;
131 501 foreach my $method_name ($role1->get_method_modifier_list('override')) {
132 # it if it has one already then ...
133 1048 ▶ if ($role2->has_method($method_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($role2->has_method($method_name)) { } 2 1046 1048
134 # if it is being composed into another role
135 # we have a conflict here, because you cannot
136 # combine an overridden method with a locally
137 # defined one
138 2 throw_exception( OverrideConflictInComposition => role_name => $role2->name,
139 role_being_applied_name => $role1->name,
140 method_name => $method_name
141 );
142 }
143 else {
144 # if we are a role, we need to make sure
145 # we don't have a conflict with the role
146 # we are composing into
147 1046 ▶ if ($role2->has_override_method_modifier($method_name) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($role2->has_override_method_modifier($method_name) and $role1->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) { } 2 1044 1046
Condition100%3/3
$role2->has_override_method_modifier($method_name) and $role1->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)
!ll&&!rl&&r
104312
MC/DC100%2/2
$role2->has_override_method_modifier($method_name) and $role1->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)
$role2->has_override_method_modifier($method_name) $role1->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)
Truth table100%3/3
A and B
A= $role2->has_override_method_modifier($method_name)B= $role1->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)
ABresult
0X0
100
111
148 $role1->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) {
149  
150 2 throw_exception( OverrideConflictInComposition => role_name => $role2->name,
151 role_being_applied_name => $role1->name,
152 method_name => $method_name,
153 two_overrides_found => 1
154 );
155 }
156 else {
157 # if there is no conflict,
158 # just add it to the role
159 1044 $role2->add_override_method_modifier(
160 $method_name,
161 $role1->get_override_method_modifier($method_name)
162 );
163 }
164 }
165 }
166 }
167  
168 1491 ▶sub apply_method_modifiers {
Subroutine apply_method_modifiers: called CC=3 SCAR=11.0
Pod documented
169 1491 my ($self, $modifier_type, $role1, $role2) = @_;
170 1491 my $add = "add_${modifier_type}_method_modifier";
171 1491 my $get = "get_${modifier_type}_method_modifiers";
172 1491 foreach my $method_name ($role1->get_method_modifier_list($modifier_type)) {
173 $role2->$add(
174 $method_name,
175 $_
176 984 ) foreach $role1->$get($method_name);
177 }
178 }
179  
180 385 1;
181  
182 # ABSTRACT: Compose a role into another role
183  
184 __END__
« blib/lib/Moose/Meta/Method/Delegation.pm ↑ Summary blib/lib/Moose/Exception/InvalidArgPassedToMooseUtilMetaRole.pm »