Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/Role/Application/ToClass.pm |
Statements | Executed 20 statements in 1.53ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 4.25ms | 4.25ms | BEGIN@2 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 15µs | 507µs | BEGIN@11 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 15µs | 180µs | BEGIN@14 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 10µs | 15µs | BEGIN@10 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 10µs | 41µs | BEGIN@13 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 10µs | 44µs | BEGIN@15 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 10µs | 78µs | BEGIN@17 | Moose::Meta::Role::Application::ToClass::
1 | 1 | 1 | 9µs | 24µs | BEGIN@9 | Moose::Meta::Role::Application::ToClass::
0 | 0 | 0 | 0s | 0s | __ANON__[:127] | 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 | # spent 4.25ms within Moose::Meta::Role::Application::ToClass::BEGIN@2 which was called:
# once (4.25ms+0s) by Moose::BEGIN@39 at line 4 | ||||
3 | 1 | 8µs | $Moose::Meta::Role::Application::ToClass::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 45µs | 1 | 4.25ms | } # spent 4.25ms making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::Role::Application::ToClass::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 37µs | 2 | 40µs | # spent 24µs (9+15) within Moose::Meta::Role::Application::ToClass::BEGIN@9 which was called:
# once (9µs+15µs) by Moose::BEGIN@39 at line 9 # spent 24µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@9
# spent 15µs making 1 call to strict::import |
10 | 2 | 29µs | 2 | 20µs | # spent 15µs (10+5) within Moose::Meta::Role::Application::ToClass::BEGIN@10 which was called:
# once (10µs+5µs) by Moose::BEGIN@39 at line 10 # spent 15µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@10
# spent 5µs making 1 call to warnings::import |
11 | 2 | 39µs | 2 | 1.00ms | # spent 507µs (15+493) within Moose::Meta::Role::Application::ToClass::BEGIN@11 which was called:
# once (15µs+493µs) by Moose::BEGIN@39 at line 11 # spent 507µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@11
# spent 493µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 38µs | 2 | 71µs | # spent 41µs (10+31) within Moose::Meta::Role::Application::ToClass::BEGIN@13 which was called:
# once (10µs+31µs) by Moose::BEGIN@39 at line 13 # spent 41µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@13
# spent 31µs making 1 call to Exporter::import |
14 | 2 | 41µs | 2 | 345µs | # spent 180µs (15+165) within Moose::Meta::Role::Application::ToClass::BEGIN@14 which was called:
# once (15µs+165µs) by Moose::BEGIN@39 at line 14 # spent 180µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@14
# spent 165µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
15 | 2 | 39µs | 2 | 78µs | # spent 44µs (10+34) within Moose::Meta::Role::Application::ToClass::BEGIN@15 which was called:
# once (10µs+34µs) by Moose::BEGIN@39 at line 15 # spent 44µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@15
# spent 34µs making 1 call to Exporter::import |
16 | |||||
17 | 2 | 1.24ms | 2 | 147µs | # spent 78µs (10+69) within Moose::Meta::Role::Application::ToClass::BEGIN@17 which was called:
# once (10µs+69µs) by Moose::BEGIN@39 at line 17 # spent 78µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@17
# spent 69µs making 1 call to base::import |
18 | |||||
19 | 1 | 5µs | 3 | 414µs | __PACKAGE__->meta->add_attribute('role' => ( # spent 386µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::Role::Application::ToClass::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
20 | reader => 'role', | ||||
21 | Class::MOP::_definition_context(), | ||||
22 | )); | ||||
23 | |||||
24 | 1 | 4µs | 3 | 394µs | __PACKAGE__->meta->add_attribute('class' => ( # spent 375µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::Role::Application::ToClass::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
25 | accessor => 'class', | ||||
26 | Class::MOP::_definition_context(), | ||||
27 | )); | ||||
28 | |||||
29 | sub apply { | ||||
30 | my ($self, $role, $class) = @_; | ||||
31 | |||||
32 | # We need weak_ref in CMOP :( | ||||
33 | weaken($self->{role} = $role); | ||||
34 | weaken($self->{class} = $class); | ||||
35 | |||||
36 | $self->SUPER::apply($role, $class); | ||||
37 | |||||
38 | $class->add_role($role); | ||||
39 | $class->add_role_application($self); | ||||
40 | } | ||||
41 | |||||
42 | sub check_role_exclusions { | ||||
43 | my ($self, $role, $class) = @_; | ||||
44 | if ($class->excludes_role($role->name)) { | ||||
45 | $class->throw_error("Conflict detected: " . $class->name . " excludes role '" . $role->name . "'"); | ||||
46 | } | ||||
47 | foreach my $excluded_role_name ($role->get_excluded_roles_list) { | ||||
48 | if ($class->does_role($excluded_role_name)) { | ||||
49 | $class->throw_error("The class " . $class->name . " does the excluded role '$excluded_role_name'"); | ||||
50 | } | ||||
51 | } | ||||
52 | } | ||||
53 | |||||
54 | sub check_required_methods { | ||||
55 | my ($self, $role, $class) = @_; | ||||
56 | |||||
57 | 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 | foreach my $required_method ($role->get_required_method_list) { | ||||
67 | my $required_method_name = $required_method->name; | ||||
68 | |||||
69 | if (!$class->find_method_by_name($required_method_name)) { | ||||
70 | |||||
71 | next if $self->is_aliased_method($required_method_name); | ||||
72 | |||||
73 | push @missing, $required_method; | ||||
74 | } | ||||
75 | } | ||||
76 | |||||
77 | return unless @missing; | ||||
78 | |||||
79 | my $error = ''; | ||||
80 | |||||
81 | @missing = sort { $a->name cmp $b->name } @missing; | ||||
82 | my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing; | ||||
83 | |||||
84 | if (@conflicts) { | ||||
85 | my $conflict = $conflicts[0]; | ||||
86 | my $roles = $conflict->roles_as_english_list; | ||||
87 | |||||
88 | my @same_role_conflicts = grep { $_->roles_as_english_list eq $roles } @conflicts; | ||||
89 | |||||
90 | if (@same_role_conflicts == 1) { | ||||
91 | $error | ||||
92 | .= "Due to a method name conflict in roles " | ||||
93 | . $roles | ||||
94 | . ", the method '" | ||||
95 | . $conflict->name | ||||
96 | . "' must be implemented or excluded by '" | ||||
97 | . $class->name | ||||
98 | . q{'}; | ||||
99 | } | ||||
100 | else { | ||||
101 | my $methods | ||||
102 | = Moose::Util::english_list( map { q{'} . $_->name . q{'} } @same_role_conflicts ); | ||||
103 | |||||
104 | $error | ||||
105 | .= "Due to method name conflicts in roles " | ||||
106 | . $roles | ||||
107 | . ", the methods " | ||||
108 | . $methods | ||||
109 | . " must be implemented or excluded by '" | ||||
110 | . $class->name | ||||
111 | . q{'}; | ||||
112 | } | ||||
113 | } | ||||
114 | elsif (@missing) { | ||||
115 | my $noun = @missing == 1 ? 'method' : 'methods'; | ||||
116 | |||||
117 | my $list | ||||
118 | = Moose::Util::english_list( map { q{'} . $_ . q{'} } @missing ); | ||||
119 | |||||
120 | $error | ||||
121 | .= q{'} | ||||
122 | . $role->name | ||||
123 | . "' requires the $noun $list " | ||||
124 | . "to be implemented by '" | ||||
125 | . $class->name . q{'}; | ||||
126 | |||||
127 | if (my $meth = firstval { $class->name->can($_) } @missing) { | ||||
128 | $error .= ". If you imported functions intending to use them as " | ||||
129 | . "methods, you need to explicitly mark them as such, via " | ||||
130 | . $class->name . "->meta->add_method($meth => \\\&$meth)"; | ||||
131 | } | ||||
132 | } | ||||
133 | |||||
134 | $class->throw_error($error); | ||||
135 | } | ||||
136 | |||||
137 | sub check_required_attributes { | ||||
138 | |||||
139 | } | ||||
140 | |||||
141 | sub apply_attributes { | ||||
142 | my ($self, $role, $class) = @_; | ||||
143 | |||||
144 | foreach my $attribute_name ($role->get_attribute_list) { | ||||
145 | # it if it has one already | ||||
146 | if ($class->has_attribute($attribute_name) && | ||||
147 | # make sure we haven't seen this one already too | ||||
148 | $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)) { | ||||
149 | next; | ||||
150 | } | ||||
151 | else { | ||||
152 | $class->add_attribute( | ||||
153 | $role->get_attribute($attribute_name)->attribute_for_class | ||||
154 | ); | ||||
155 | } | ||||
156 | } | ||||
157 | } | ||||
158 | |||||
159 | sub apply_methods { | ||||
160 | my ( $self, $role, $class ) = @_; | ||||
161 | |||||
162 | foreach my $method ( $role->_get_local_methods ) { | ||||
163 | my $method_name = $method->name; | ||||
164 | |||||
165 | next if $method->isa('Class::MOP::Method::Meta'); | ||||
166 | |||||
167 | unless ( $self->is_method_excluded($method_name) ) { | ||||
168 | |||||
169 | my $class_method = $class->get_method($method_name); | ||||
170 | |||||
171 | next if $class_method && $class_method->body != $method->body; | ||||
172 | |||||
173 | $class->add_method( | ||||
174 | $method_name, | ||||
175 | $method, | ||||
176 | ); | ||||
177 | } | ||||
178 | |||||
179 | next unless $self->is_method_aliased($method_name); | ||||
180 | |||||
181 | my $aliased_method_name = $self->get_method_aliases->{$method_name}; | ||||
182 | |||||
183 | my $class_method = $class->get_method($aliased_method_name); | ||||
184 | |||||
185 | if ( $class_method && $class_method->body != $method->body ) { | ||||
186 | $class->throw_error( | ||||
187 | "Cannot create a method alias if a local method of the same name exists" | ||||
188 | ); | ||||
189 | } | ||||
190 | |||||
191 | $class->add_method( | ||||
192 | $aliased_method_name, | ||||
193 | $method, | ||||
194 | ); | ||||
195 | } | ||||
196 | |||||
197 | # we must reset the cache here since | ||||
198 | # we are just aliasing methods, otherwise | ||||
199 | # the modifiers go wonky. | ||||
200 | $class->reset_package_cache_flag; | ||||
201 | } | ||||
202 | |||||
203 | sub apply_override_method_modifiers { | ||||
204 | my ($self, $role, $class) = @_; | ||||
205 | foreach my $method_name ($role->get_method_modifier_list('override')) { | ||||
206 | # it if it has one already then ... | ||||
207 | if ($class->has_method($method_name)) { | ||||
208 | next; | ||||
209 | } | ||||
210 | else { | ||||
211 | # if this is not a role, then we need to | ||||
212 | # find the original package of the method | ||||
213 | # so that we can tell the class were to | ||||
214 | # find the right super() method | ||||
215 | my $method = $role->get_override_method_modifier($method_name); | ||||
216 | my ($package) = Class::MOP::get_code_info($method); | ||||
217 | # if it is a class, we just add it | ||||
218 | $class->add_override_method_modifier($method_name, $method, $package); | ||||
219 | } | ||||
220 | } | ||||
221 | } | ||||
222 | |||||
223 | sub apply_method_modifiers { | ||||
224 | my ($self, $modifier_type, $role, $class) = @_; | ||||
225 | my $add = "add_${modifier_type}_method_modifier"; | ||||
226 | my $get = "get_${modifier_type}_method_modifiers"; | ||||
227 | foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { | ||||
228 | $class->$add( | ||||
229 | $method_name, | ||||
230 | $_ | ||||
231 | ) foreach $role->$get($method_name); | ||||
232 | } | ||||
233 | } | ||||
234 | |||||
235 | 1 | 8µs | 1; | ||
236 | |||||
237 | # ABSTRACT: Compose a role into a class | ||||
238 | |||||
239 | __END__ |