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

filter: Statementstmt 100% 92 / 92 Branchbran 96.6% 29 / 30 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 16 / 16 Podpod 100% 8 / 8 totaltotal 95.6% 154 / 161 CC 26 SCAR 16.1
CC
26
Cov
97%
apply_methods
9.0
check_required_methods
8.0
apply_attributes
4.0
CRAP 5.0
« blib/lib/Class/MOP/Attribute.pm ↑ Summary blib/lib/Moose/Meta/Attribute/Native/Trait.pm »
1 package Moose::Meta::Role::Application::ToClass;
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 List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 385 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 385 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 385 ▶use parent 'Moose::Meta::Role::Application';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 385 __PACKAGE__->meta->add_attribute('role' => (
15 reader => 'role',
16 Class::MOP::_definition_context(),
17 ));
18  
19 385 __PACKAGE__->meta->add_attribute('class' => (
20 accessor => 'class',
21 Class::MOP::_definition_context(),
22 ));
23  
24 1123 ▶sub apply {
Subroutine apply: called CC=1 SCAR=0.0
Pod documented
25 1123 my ($self, $role, $class) = @_;
26  
27 # We need weak_ref in CMOP :(
28 1123 weaken($self->{role} = $role);
29 1123 weaken($self->{class} = $class);
30  
31 1123 $self->SUPER::apply($role, $class);
32  
33 1088 $class->add_role($role);
34 1088 $class->add_role_application($self);
35 }
36  
37 1123 ▶sub check_role_exclusions {
Subroutine check_role_exclusions: called CC=4 SCAR=13.9
Pod documented
38 1123 my ($self, $role, $class) = @_;
39 1123 ▶ if ($class->excludes_role($role->name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->excludes_role($role->name)) 3 1120 1123
40 3 throw_exception( ConflictDetectedInCheckRoleExclusionsInToClass => class_name => $class->name,
41 role_name => $role->name,
42 );
43 }
44 1120 foreach my $excluded_role_name ($role->get_excluded_roles_list) {
45 5 ▶ if ($class->does_role($excluded_role_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->does_role($excluded_role_name)) 1 4 5
46 1 throw_exception( ClassDoesTheExcludedRole => role_name => $role->name,
47 excluded_role_name => $excluded_role_name,
48 class_name => $class->name,
49 );
50 }
51 }
52 }
53  
54 1119 ▶sub check_required_methods {
Subroutine check_required_methods: called CC=8 SCAR=20.8
Pod documented
55 1119 my ($self, $role, $class) = @_;
56  
57 1119 my @missing;
58 my @is_attr;
59  
60 # NOTE:
61 # we might need to move this down below the
62 # the attributes so that we can require any
63 # attribute accessors. However I am thinking
64 # that maybe those are somehow exempt from
65 # the require methods stuff.
66 1119 foreach my $required_method ($role->get_required_method_list) {
67 169 my $required_method_name = $required_method->name;
68  
69 168 ▶ if (!$class->find_method_by_name($required_method_name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->find_method_by_name($required_method_name)) 41 127 168
70  
71 41 ▶ next if $self->is_aliased_method($required_method_name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_aliased_method($required_method_name) 1 40 41
72  
73 40 push @missing, $required_method;
74 }
75 }
76  
77 1118 ▶ return unless @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 1091 28 1119
78  
79 29 my $error = '';
80  
81 28 @missing = sort { $a->name cmp $b->name } @missing;
82 28 my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing;
83  
84 28 ▶ if (@conflicts) {
Branch: 2 branches
BranchTrueFalseTotal
if (@conflicts) { } 10 18 28
elsif (@missing) { } 18 0 18
85 10 my $conflict = $conflicts[0];
86 10 my $roles = $conflict->roles_as_english_list;
87  
88 10 my @same_role_conflicts = grep { $_->roles_as_english_list eq $roles } @conflicts;
89  
90 10 throw_exception( MethodNameConflictInRoles => conflict => \@same_role_conflicts,
91 class_name => $class->name
92 );
93 }
94 elsif (@missing) {
95 18 ▶ if (my $meth = first { $class->name->can($_) } @missing) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $meth = &first(sub { $class->name->can($_); } , @missing)) { } 2 16 18
96 2 throw_exception( RequiredMethodsImportedByClass => class_name => $class->name,
97 role_name => $role->name,
98 missing_methods => \@missing,
99 imported_method => $meth
100 );
101 }
102 else {
103 16 throw_exception( RequiredMethodsNotImplementedByClass => class_name => $class->name,
104 role_name => $role->name,
105 missing_methods => \@missing,
106 );
107 }
108 }
109 }
110  
111 1090 ▶sub check_required_attributes {
Subroutine check_required_attributes: called CC=1 SCAR=0.0
Pod documented
112  
113 }
114  
115 1091 ▶sub apply_attributes {
Subroutine apply_attributes: called CC=4 SCAR=13.9
Pod documented
116 1091 my ($self, $role, $class) = @_;
117  
118 1091 foreach my $attribute_name ($role->get_attribute_list) {
119 # it if it has one already
120 655 ▶ if ($class->has_attribute($attribute_name) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($class->has_attribute($attribute_name) and $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)) { } 2 653 655
Condition66%2/3
$class->has_attribute($attribute_name) and $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)
!ll&&!rl&&r
65302
MC/DC50%1/2
$class->has_attribute($attribute_name) and $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)
$class->has_attribute($attribute_name) $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)
Truth table66%2/3
A and B
A= $class->has_attribute($attribute_name)B= $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)
ABresult
0X0
100
111
121 # make sure we haven't seen this one already too
122 $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)) {
123 2 next;
124 }
125 else {
126 653 $class->add_attribute(
127 $role->get_attribute($attribute_name)->attribute_for_class
128 );
129 }
130 }
131 }
132  
133 1091 ▶sub apply_methods {
Subroutine apply_methods: called CC=9 SCAR=22.0
Pod documented
134 1091 my ( $self, $role, $class ) = @_;
135  
136 1091 foreach my $method ( $role->_get_local_methods ) {
137 8696 my $method_name = $method->name;
138  
139 8696 ▶ next if $method->isa('Class::MOP::Method::Meta');
Branch: 1 branch
BranchTrueFalseTotal
if $method->isa("Class::MOP::Method::Meta") 965 7731 8696
140  
141 7731 ▶ unless ( $self->is_method_excluded($method_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_method_excluded($method_name)) 7723 8 7731
142  
143 7723 my $class_method = $class->get_method($method_name);
144  
145 7723 ▶ next if $class_method && $class_method->body != $method->body;
Branch: 1 branch
BranchTrueFalseTotal
if $class_method and $class_method->body != $method->body 13 7710 7723
Condition66%2/3
$class_method and $class_method->body != $method->body
!ll&&!rl&&r
7710013
MC/DC50%1/2
$class_method and $class_method->body != $method->body
$class_method $class_method->body != $method->body
Truth table66%2/3
A and B
A= $class_methodB= $class_method->body != $method->body
ABresult
0X0
100
111
146  
147 7710 $class->add_method(
148 $method_name,
149 $method,
150 );
151 }
152  
153 7718 ▶ next unless $self->is_method_aliased($method_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_method_aliased($method_name) 7705 13 7718
154  
155 13 my $aliased_method_name = $self->get_method_aliases->{$method_name};
156  
157 13 my $class_method = $class->get_method($aliased_method_name);
158  
159 13 ▶ if ( $class_method && $class_method->body != $method->body ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_method and $class_method->body != $method->body) 2 11 13
Condition66%2/3
$class_method and $class_method->body != $method->body
!ll&&!rl&&r
1102
MC/DC50%1/2
$class_method and $class_method->body != $method->body
$class_method $class_method->body != $method->body
Truth table66%2/3
A and B
A= $class_methodB= $class_method->body != $method->body
ABresult
0X0
100
111
160 2 throw_exception( CannotCreateMethodAliasLocalMethodIsPresentInClass => aliased_method_name => $aliased_method_name,
161 method => $method,
162 role_name => $role->name,
163 class_name => $class->name,
164 );
165 }
166  
167 $class->add_method(
168 11 $aliased_method_name,
169 $method,
170 );
171 }
172  
173 # we must reset the cache here since
174 # we are just aliasing methods, otherwise
175 # the modifiers go wonky.
176 1089 $class->reset_package_cache_flag;
177 }
178  
179 1089 ▶sub apply_override_method_modifiers {
Subroutine apply_override_method_modifiers: called CC=3 SCAR=11.0
Pod documented
180 1089 my ($self, $role, $class) = @_;
181 1089 foreach my $method_name ($role->get_method_modifier_list('override')) {
182 # it if it has one already then ...
183 997 ▶ if ($class->has_method($method_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->has_method($method_name)) { } 3 994 997
184 3 next;
185 }
186 else {
187 # if this is not a role, then we need to
188 # find the original package of the method
189 # so that we can tell the class were to
190 # find the right super() method
191 994 my $method = $role->get_override_method_modifier($method_name);
192 994 my ($package) = Class::MOP::get_code_info($method);
193 # if it is a class, we just add it
194 994 $class->add_override_method_modifier($method_name, $method, $package);
195 }
196 }
197 }
198  
199 3264 ▶sub apply_method_modifiers {
Subroutine apply_method_modifiers: called CC=3 SCAR=11.0
Pod documented
200 3264 my ($self, $modifier_type, $role, $class) = @_;
201 3264 my $add = "add_${modifier_type}_method_modifier";
202 3264 my $get = "get_${modifier_type}_method_modifiers";
203 3264 foreach my $method_name ($role->get_method_modifier_list($modifier_type)) {
204 $class->$add(
205 $method_name,
206 $_
207 1092 ) foreach $role->$get($method_name);
208 }
209 }
210  
211 385 1;
212  
213 # ABSTRACT: Compose a role into a class
214  
215 __END__
« blib/lib/Class/MOP/Attribute.pm ↑ Summary blib/lib/Moose/Meta/Attribute/Native/Trait.pm »