← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/Role/Application/ToClass.pm
StatementsExecuted 20 statements in 1.53ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.25ms4.25msMoose::Meta::Role::Application::ToClass::::BEGIN@2Moose::Meta::Role::Application::ToClass::BEGIN@2
11115µs507µsMoose::Meta::Role::Application::ToClass::::BEGIN@11Moose::Meta::Role::Application::ToClass::BEGIN@11
11115µs180µsMoose::Meta::Role::Application::ToClass::::BEGIN@14Moose::Meta::Role::Application::ToClass::BEGIN@14
11110µs15µsMoose::Meta::Role::Application::ToClass::::BEGIN@10Moose::Meta::Role::Application::ToClass::BEGIN@10
11110µs41µsMoose::Meta::Role::Application::ToClass::::BEGIN@13Moose::Meta::Role::Application::ToClass::BEGIN@13
11110µs44µsMoose::Meta::Role::Application::ToClass::::BEGIN@15Moose::Meta::Role::Application::ToClass::BEGIN@15
11110µs78µsMoose::Meta::Role::Application::ToClass::::BEGIN@17Moose::Meta::Role::Application::ToClass::BEGIN@17
1119µs24µsMoose::Meta::Role::Application::ToClass::::BEGIN@9Moose::Meta::Role::Application::ToClass::BEGIN@9
0000s0sMoose::Meta::Role::Application::ToClass::::__ANON__[:127]Moose::Meta::Role::Application::ToClass::__ANON__[:127]
0000s0sMoose::Meta::Role::Application::ToClass::::applyMoose::Meta::Role::Application::ToClass::apply
0000s0sMoose::Meta::Role::Application::ToClass::::apply_attributesMoose::Meta::Role::Application::ToClass::apply_attributes
0000s0sMoose::Meta::Role::Application::ToClass::::apply_method_modifiersMoose::Meta::Role::Application::ToClass::apply_method_modifiers
0000s0sMoose::Meta::Role::Application::ToClass::::apply_methodsMoose::Meta::Role::Application::ToClass::apply_methods
0000s0sMoose::Meta::Role::Application::ToClass::::apply_override_method_modifiersMoose::Meta::Role::Application::ToClass::apply_override_method_modifiers
0000s0sMoose::Meta::Role::Application::ToClass::::check_required_attributesMoose::Meta::Role::Application::ToClass::check_required_attributes
0000s0sMoose::Meta::Role::Application::ToClass::::check_required_methodsMoose::Meta::Role::Application::ToClass::check_required_methods
0000s0sMoose::Meta::Role::Application::ToClass::::check_role_exclusionsMoose::Meta::Role::Application::ToClass::check_role_exclusions
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package 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
BEGIN {
318µs $Moose::Meta::Role::Application::ToClass::AUTHORITY = 'cpan:STEVAN';
4145µs14.25ms}
# spent 4.25ms making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@2
5{
621µs $Moose::Meta::Role::Application::ToClass::VERSION = '2.1005';
7}
8
9237µs240µ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
use strict;
# spent 24µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@9 # spent 15µs making 1 call to strict::import
10229µs220µ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
use warnings;
# spent 15µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@10 # spent 5µs making 1 call to warnings::import
11239µs21.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
use metaclass;
# spent 507µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@11 # spent 493µs making 1 call to metaclass::import
12
13238µs271µ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
use List::MoreUtils 'firstval';
# spent 41µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@13 # spent 31µs making 1 call to Exporter::import
14241µs2345µ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
use Moose::Util 'english_list';
# 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]
15239µs278µ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
use Scalar::Util 'weaken', 'blessed';
# spent 44µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@15 # spent 34µs making 1 call to Exporter::import
16
1721.24ms2147µ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
use base 'Moose::Meta::Role::Application';
# spent 78µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@17 # spent 69µs making 1 call to base::import
18
1915µs3414µ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
2414µs3394µ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
29sub 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
42sub 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
54sub 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
137sub check_required_attributes {
138
139}
140
141sub 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
159sub 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
203sub 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
223sub 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
23518µs1;
236
237# ABSTRACT: Compose a role into a class
238
239__END__