File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Role/Application/ToClass.pm |
Statements Executed | 24 |
Statement Execution Time | 895µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 15µs | 18µs | BEGIN@3 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 11µs | 249µs | BEGIN@7 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 9µs | 54µs | BEGIN@14 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 8µs | 18µs | BEGIN@4 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 8µs | 39µs | BEGIN@8 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 7µs | 102µs | BEGIN@5 | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | apply | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | apply_attributes | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | apply_method_modifiers | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | apply_methods | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | apply_override_method_modifiers | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | check_required_attributes | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | check_required_methods | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | check_role_exclusions | Moose::Meta::Role::Application::ToClass::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Role::Application::ToClass; | ||||
2 | |||||
3 | 3 | 21µs | 2 | 22µs | # spent 18µs (15+3) within Moose::Meta::Role::Application::ToClass::BEGIN@3 which was called
# once (15µs+3µs) by Moose::BEGIN@30 at line 3 # spent 18µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@3
# spent 3µs making 1 call to strict::import |
4 | 3 | 19µs | 2 | 27µs | # spent 18µs (8+9) within Moose::Meta::Role::Application::ToClass::BEGIN@4 which was called
# once (8µs+9µs) by Moose::BEGIN@30 at line 4 # spent 18µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@4
# spent 9µs making 1 call to warnings::import |
5 | 3 | 26µs | 2 | 198µs | # spent 102µs (7+96) within Moose::Meta::Role::Application::ToClass::BEGIN@5 which was called
# once (7µs+96µs) by Moose::BEGIN@30 at line 5 # spent 102µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@5
# spent 96µs making 1 call to metaclass::import |
6 | |||||
7 | 3 | 32µs | 2 | 487µs | # spent 249µs (11+238) within Moose::Meta::Role::Application::ToClass::BEGIN@7 which was called
# once (11µs+238µs) by Moose::BEGIN@30 at line 7 # spent 249µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@7
# spent 238µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
8 | 3 | 59µs | 2 | 70µs | # spent 39µs (8+31) within Moose::Meta::Role::Application::ToClass::BEGIN@8 which was called
# once (8µs+31µs) by Moose::BEGIN@30 at line 8 # spent 39µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@8
# spent 31µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 700ns | our $VERSION = '0.98'; | ||
11 | 1 | 18µs | $VERSION = eval $VERSION; | ||
12 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
13 | |||||
14 | 3 | 705µs | 2 | 99µs | # spent 54µs (9+45) within Moose::Meta::Role::Application::ToClass::BEGIN@14 which was called
# once (9µs+45µs) by Moose::BEGIN@30 at line 14 # spent 54µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@14
# spent 45µs making 1 call to base::import |
15 | |||||
16 | 1 | 3µs | 2 | 294µs | __PACKAGE__->meta->add_attribute('role' => ( # spent 277µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 17µs making 1 call to Moose::Meta::Role::Application::ToClass::meta |
17 | reader => 'role', | ||||
18 | )); | ||||
19 | |||||
20 | 1 | 2µs | 2 | 264µs | __PACKAGE__->meta->add_attribute('class' => ( # spent 253µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Moose::Meta::Role::Application::ToClass::meta |
21 | reader => 'class', | ||||
22 | )); | ||||
23 | |||||
24 | sub apply { | ||||
25 | my ($self, $role, $class) = @_; | ||||
26 | |||||
27 | # We need weak_ref in CMOP :( | ||||
28 | weaken($self->{role} = $role); | ||||
29 | weaken($self->{class} = $class); | ||||
30 | |||||
31 | $self->SUPER::apply($role, $class); | ||||
32 | |||||
33 | $class->add_role($role); | ||||
34 | $class->add_role_application($self); | ||||
35 | } | ||||
36 | |||||
37 | sub check_role_exclusions { | ||||
38 | my ($self, $role, $class) = @_; | ||||
39 | if ($class->excludes_role($role->name)) { | ||||
40 | $class->throw_error("Conflict detected: " . $class->name . " excludes role '" . $role->name . "'"); | ||||
41 | } | ||||
42 | foreach my $excluded_role_name ($role->get_excluded_roles_list) { | ||||
43 | if ($class->does_role($excluded_role_name)) { | ||||
44 | $class->throw_error("The class " . $class->name . " does the excluded role '$excluded_role_name'"); | ||||
45 | } | ||||
46 | } | ||||
47 | } | ||||
48 | |||||
49 | sub check_required_methods { | ||||
50 | my ($self, $role, $class) = @_; | ||||
51 | |||||
52 | my @missing; | ||||
53 | my @is_attr; | ||||
54 | |||||
55 | # NOTE: | ||||
56 | # we might need to move this down below the | ||||
57 | # the attributes so that we can require any | ||||
58 | # attribute accessors. However I am thinking | ||||
59 | # that maybe those are somehow exempt from | ||||
60 | # the require methods stuff. | ||||
61 | foreach my $required_method ($role->get_required_method_list) { | ||||
62 | my $required_method_name = $required_method->name; | ||||
63 | |||||
64 | if (!$class->find_method_by_name($required_method_name)) { | ||||
65 | |||||
66 | next if $self->is_aliased_method($required_method_name); | ||||
67 | |||||
68 | push @missing, $required_method; | ||||
69 | } | ||||
70 | } | ||||
71 | |||||
72 | return unless @missing; | ||||
73 | |||||
74 | my $error = ''; | ||||
75 | |||||
76 | @missing = sort { $a->name cmp $b->name } @missing; | ||||
77 | my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing; | ||||
78 | |||||
79 | if (@conflicts) { | ||||
80 | my $conflict = $conflicts[0]; | ||||
81 | my $roles = $conflict->roles_as_english_list; | ||||
82 | |||||
83 | my @same_role_conflicts = grep { $_->roles_as_english_list eq $roles } @conflicts; | ||||
84 | |||||
85 | if (@same_role_conflicts == 1) { | ||||
86 | $error | ||||
87 | .= "Due to a method name conflict in roles " | ||||
88 | . $roles | ||||
89 | . ", the method '" | ||||
90 | . $conflict->name | ||||
91 | . "' must be implemented or excluded by '" | ||||
92 | . $class->name | ||||
93 | . q{'}; | ||||
94 | } | ||||
95 | else { | ||||
96 | my $methods | ||||
97 | = Moose::Util::english_list( map { q{'} . $_->name . q{'} } @same_role_conflicts ); | ||||
98 | |||||
99 | $error | ||||
100 | .= "Due to method name conflicts in roles " | ||||
101 | . $roles | ||||
102 | . ", the methods " | ||||
103 | . $methods | ||||
104 | . " must be implemented or excluded by '" | ||||
105 | . $class->name | ||||
106 | . q{'}; | ||||
107 | } | ||||
108 | } | ||||
109 | elsif (@missing) { | ||||
110 | my $noun = @missing == 1 ? 'method' : 'methods'; | ||||
111 | |||||
112 | my $list | ||||
113 | = Moose::Util::english_list( map { q{'} . $_ . q{'} } @missing ); | ||||
114 | |||||
115 | $error | ||||
116 | .= q{'} | ||||
117 | . $role->name | ||||
118 | . "' requires the $noun $list " | ||||
119 | . "to be implemented by '" | ||||
120 | . $class->name . q{'}; | ||||
121 | } | ||||
122 | |||||
123 | $class->throw_error($error); | ||||
124 | } | ||||
125 | |||||
126 | sub check_required_attributes { | ||||
127 | |||||
128 | } | ||||
129 | |||||
130 | sub apply_attributes { | ||||
131 | my ($self, $role, $class) = @_; | ||||
132 | my $attr_metaclass = $class->attribute_metaclass; | ||||
133 | |||||
134 | foreach my $attribute_name ($role->get_attribute_list) { | ||||
135 | # it if it has one already | ||||
136 | if ($class->has_attribute($attribute_name) && | ||||
137 | # make sure we haven't seen this one already too | ||||
138 | $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)) { | ||||
139 | next; | ||||
140 | } | ||||
141 | else { | ||||
142 | $class->add_attribute( | ||||
143 | $role->get_attribute($attribute_name)->attribute_for_class($attr_metaclass) | ||||
144 | ); | ||||
145 | } | ||||
146 | } | ||||
147 | } | ||||
148 | |||||
149 | sub apply_methods { | ||||
150 | my ($self, $role, $class) = @_; | ||||
151 | foreach my $method_name ($role->get_method_list) { | ||||
152 | next if $method_name eq 'meta'; | ||||
153 | |||||
154 | unless ($self->is_method_excluded($method_name)) { | ||||
155 | # it if it has one already | ||||
156 | if ($class->has_method($method_name) && | ||||
157 | # and if they are not the same thing ... | ||||
158 | $class->get_method($method_name)->body != $role->get_method($method_name)->body) { | ||||
159 | next; | ||||
160 | } | ||||
161 | else { | ||||
162 | # add it, although it could be overridden | ||||
163 | $class->add_method( | ||||
164 | $method_name, | ||||
165 | $role->get_method($method_name) | ||||
166 | ); | ||||
167 | } | ||||
168 | } | ||||
169 | |||||
170 | if ($self->is_method_aliased($method_name)) { | ||||
171 | my $aliased_method_name = $self->get_method_aliases->{$method_name}; | ||||
172 | # it if it has one already | ||||
173 | if ($class->has_method($aliased_method_name) && | ||||
174 | # and if they are not the same thing ... | ||||
175 | $class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body) { | ||||
176 | $class->throw_error("Cannot create a method alias if a local method of the same name exists"); | ||||
177 | } | ||||
178 | $class->add_method( | ||||
179 | $aliased_method_name, | ||||
180 | $role->get_method($method_name) | ||||
181 | ); | ||||
182 | } | ||||
183 | } | ||||
184 | # we must reset the cache here since | ||||
185 | # we are just aliasing methods, otherwise | ||||
186 | # the modifiers go wonky. | ||||
187 | $class->reset_package_cache_flag; | ||||
188 | } | ||||
189 | |||||
190 | sub apply_override_method_modifiers { | ||||
191 | my ($self, $role, $class) = @_; | ||||
192 | foreach my $method_name ($role->get_method_modifier_list('override')) { | ||||
193 | # it if it has one already then ... | ||||
194 | if ($class->has_method($method_name)) { | ||||
195 | next; | ||||
196 | } | ||||
197 | else { | ||||
198 | # if this is not a role, then we need to | ||||
199 | # find the original package of the method | ||||
200 | # so that we can tell the class were to | ||||
201 | # find the right super() method | ||||
202 | my $method = $role->get_override_method_modifier($method_name); | ||||
203 | my ($package) = Class::MOP::get_code_info($method); | ||||
204 | # if it is a class, we just add it | ||||
205 | $class->add_override_method_modifier($method_name, $method, $package); | ||||
206 | } | ||||
207 | } | ||||
208 | } | ||||
209 | |||||
210 | sub apply_method_modifiers { | ||||
211 | my ($self, $modifier_type, $role, $class) = @_; | ||||
212 | my $add = "add_${modifier_type}_method_modifier"; | ||||
213 | my $get = "get_${modifier_type}_method_modifiers"; | ||||
214 | foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { | ||||
215 | $class->$add( | ||||
216 | $method_name, | ||||
217 | $_ | ||||
218 | ) foreach $role->$get($method_name); | ||||
219 | } | ||||
220 | } | ||||
221 | |||||
222 | 1 | 9µs | 1; | ||
223 | |||||
224 | __END__ | ||||
225 | |||||
226 | =pod | ||||
227 | |||||
228 | =head1 NAME | ||||
229 | |||||
230 | Moose::Meta::Role::Application::ToClass - Compose a role into a class | ||||
231 | |||||
232 | =head1 DESCRIPTION | ||||
233 | |||||
234 | =head2 METHODS | ||||
235 | |||||
236 | =over 4 | ||||
237 | |||||
238 | =item B<new> | ||||
239 | |||||
240 | =item B<meta> | ||||
241 | |||||
242 | =item B<apply> | ||||
243 | |||||
244 | =item B<check_role_exclusions> | ||||
245 | |||||
246 | =item B<check_required_methods> | ||||
247 | |||||
248 | =item B<check_required_attributes> | ||||
249 | |||||
250 | =item B<apply_attributes> | ||||
251 | |||||
252 | =item B<apply_methods> | ||||
253 | |||||
254 | =item B<apply_method_modifiers> | ||||
255 | |||||
256 | =item B<apply_override_method_modifiers> | ||||
257 | |||||
258 | =back | ||||
259 | |||||
260 | =head1 BUGS | ||||
261 | |||||
262 | See L<Moose/BUGS> for details on reporting bugs. | ||||
263 | |||||
264 | =head1 AUTHOR | ||||
265 | |||||
266 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
267 | |||||
268 | =head1 COPYRIGHT AND LICENSE | ||||
269 | |||||
270 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
271 | |||||
272 | L<http://www.iinteractive.com> | ||||
273 | |||||
274 | This library is free software; you can redistribute it and/or modify | ||||
275 | it under the same terms as Perl itself. | ||||
276 | |||||
277 | =cut | ||||
278 |