| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Role/Application/ToClass.pm |
| Statements Executed | 996 |
| Statement Execution Time | 3.33ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 13 | 1 | 1 | 1.17ms | 28.0ms | Moose::Meta::Role::Application::ToClass::apply_methods |
| 13 | 1 | 1 | 611µs | 61.5ms | Moose::Meta::Role::Application::ToClass::apply_attributes |
| 39 | 3 | 1 | 547µs | 11.2ms | Moose::Meta::Role::Application::ToClass::apply_method_modifiers |
| 13 | 1 | 1 | 313µs | 106ms | Moose::Meta::Role::Application::ToClass::apply |
| 13 | 1 | 1 | 174µs | 3.08ms | Moose::Meta::Role::Application::ToClass::check_role_exclusions |
| 13 | 1 | 1 | 143µs | 401µs | Moose::Meta::Role::Application::ToClass::check_required_methods |
| 13 | 1 | 1 | 96µs | 250µs | Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers |
| 13 | 1 | 1 | 18µs | 18µs | Moose::Meta::Role::Application::ToClass::check_required_attributes |
| 1 | 1 | 1 | 15µs | 18µs | Moose::Meta::Role::Application::ToClass::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 210µs | Moose::Meta::Role::Application::ToClass::BEGIN@7 |
| 1 | 1 | 1 | 9µs | 52µs | Moose::Meta::Role::Application::ToClass::BEGIN@14 |
| 1 | 1 | 1 | 8µs | 37µs | Moose::Meta::Role::Application::ToClass::BEGIN@8 |
| 1 | 1 | 1 | 8µs | 17µs | Moose::Meta::Role::Application::ToClass::BEGIN@4 |
| 1 | 1 | 1 | 7µs | 112µs | Moose::Meta::Role::Application::ToClass::BEGIN@5 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::Role::Application::ToClass; | ||||
| 2 | |||||
| 3 | 3 | 21µs | 2 | 21µ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 | 20µs | 2 | 26µs | # spent 17µ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 17µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@4
# spent 9µs making 1 call to warnings::import |
| 5 | 3 | 27µs | 2 | 216µs | # spent 112µs (7+105) within Moose::Meta::Role::Application::ToClass::BEGIN@5 which was called
# once (7µs+105µs) by Moose::BEGIN@30 at line 5 # spent 112µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@5
# spent 105µs making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 31µs | 2 | 411µs | # spent 210µs (9+201) within Moose::Meta::Role::Application::ToClass::BEGIN@7 which was called
# once (9µs+201µs) by Moose::BEGIN@30 at line 7 # spent 210µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@7
# spent 201µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 8 | 3 | 57µs | 2 | 66µs | # spent 37µs (8+29) within Moose::Meta::Role::Application::ToClass::BEGIN@8 which was called
# once (8µs+29µs) by Moose::BEGIN@30 at line 8 # spent 37µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@8
# spent 29µ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 | 748µs | 2 | 95µs | # spent 52µs (9+43) within Moose::Meta::Role::Application::ToClass::BEGIN@14 which was called
# once (9µs+43µs) by Moose::BEGIN@30 at line 14 # spent 52µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@14
# spent 43µs making 1 call to base::import |
| 15 | |||||
| 16 | 1 | 3µs | 2 | 303µs | __PACKAGE__->meta->add_attribute('role' => ( # spent 282µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 21µs making 1 call to Moose::Meta::Role::Application::ToClass::meta |
| 17 | reader => 'role', | ||||
| 18 | )); | ||||
| 19 | |||||
| 20 | 1 | 3µs | 2 | 293µs | __PACKAGE__->meta->add_attribute('class' => ( # spent 280µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::Role::Application::ToClass::meta |
| 21 | reader => 'class', | ||||
| 22 | )); | ||||
| 23 | |||||
| 24 | # spent 106ms (313µs+106) within Moose::Meta::Role::Application::ToClass::apply which was called 13 times, avg 8.14ms/call:
# 13 times (313µs+106ms) by Moose::Meta::Role::apply at line 419 of Moose/Meta/Role.pm, avg 8.14ms/call | ||||
| 25 | 13 | 14µs | my ($self, $role, $class) = @_; | ||
| 26 | |||||
| 27 | # We need weak_ref in CMOP :( | ||||
| 28 | 13 | 68µs | 13 | 20µs | weaken($self->{role} = $role); # spent 20µs making 13 calls to Scalar::Util::weaken, avg 2µs/call |
| 29 | 13 | 49µs | 13 | 15µs | weaken($self->{class} = $class); # spent 15µs making 13 calls to Scalar::Util::weaken, avg 1µs/call |
| 30 | |||||
| 31 | 13 | 81µs | 13 | 105ms | $self->SUPER::apply($role, $class); # spent 105ms making 13 calls to Moose::Meta::Role::Application::apply, avg 8.09ms/call |
| 32 | |||||
| 33 | 13 | 39µs | 13 | 185µs | $class->add_role($role); # spent 185µs making 13 calls to Moose::Meta::Class::add_role, avg 14µs/call |
| 34 | 13 | 63µs | 13 | 190µs | $class->add_role_application($self); # spent 190µs making 13 calls to Moose::Meta::Class::add_role_application, avg 15µs/call |
| 35 | } | ||||
| 36 | |||||
| 37 | # spent 3.08ms (174µs+2.91) within Moose::Meta::Role::Application::ToClass::check_role_exclusions which was called 13 times, avg 237µs/call:
# 13 times (174µs+2.91ms) by Moose::Meta::Role::Application::apply at line 68 of Moose/Meta/Role/Application.pm, avg 237µs/call | ||||
| 38 | 13 | 13µs | my ($self, $role, $class) = @_; | ||
| 39 | 13 | 85µs | 26 | 2.76ms | if ($class->excludes_role($role->name)) { # spent 2.75ms making 13 calls to Moose::Meta::Class::excludes_role, avg 212µs/call
# spent 13µs making 13 calls to Class::MOP::Package::name, avg 1µs/call |
| 40 | $class->throw_error("Conflict detected: " . $class->name . " excludes role '" . $role->name . "'"); | ||||
| 41 | } | ||||
| 42 | 13 | 76µs | 13 | 145µs | foreach my $excluded_role_name ($role->get_excluded_roles_list) { # spent 145µs making 13 calls to Moose::Meta::Role::get_excluded_roles_list, avg 11µs/call |
| 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 | # spent 401µs (143+258) within Moose::Meta::Role::Application::ToClass::check_required_methods which was called 13 times, avg 31µs/call:
# 13 times (143µs+258µs) by Moose::Meta::Role::Application::apply at line 69 of Moose/Meta/Role/Application.pm, avg 31µs/call | ||||
| 50 | 13 | 14µs | my ($self, $role, $class) = @_; | ||
| 51 | |||||
| 52 | 13 | 7µs | my @missing; | ||
| 53 | 13 | 2µs | 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 | 13 | 46µs | 13 | 135µs | foreach my $required_method ($role->get_required_method_list) { # spent 135µs making 13 calls to Moose::Meta::Role::get_required_method_list, avg 10µs/call |
| 62 | 2 | 5µs | 2 | 7µs | my $required_method_name = $required_method->name; # spent 7µs making 2 calls to Moose::Meta::Role::Method::Required::name, avg 3µs/call |
| 63 | |||||
| 64 | 2 | 9µs | 2 | 116µs | if (!$class->find_method_by_name($required_method_name)) { # spent 116µs making 2 calls to Class::MOP::Class::find_method_by_name, avg 58µs/call |
| 65 | |||||
| 66 | next if $self->is_aliased_method($required_method_name); | ||||
| 67 | |||||
| 68 | push @missing, $required_method; | ||||
| 69 | } | ||||
| 70 | } | ||||
| 71 | |||||
| 72 | 13 | 37µs | 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 | 13 | 30µs | # spent 18µs within Moose::Meta::Role::Application::ToClass::check_required_attributes which was called 13 times, avg 1µs/call:
# 13 times (18µs+0s) by Moose::Meta::Role::Application::apply at line 70 of Moose/Meta/Role/Application.pm, avg 1µs/call | ||
| 127 | |||||
| 128 | } | ||||
| 129 | |||||
| 130 | # spent 61.5ms (611µs+60.9) within Moose::Meta::Role::Application::ToClass::apply_attributes which was called 13 times, avg 4.73ms/call:
# 13 times (611µs+60.9ms) by Moose::Meta::Role::Application::apply at line 72 of Moose/Meta/Role/Application.pm, avg 4.73ms/call | ||||
| 131 | 13 | 12µs | my ($self, $role, $class) = @_; | ||
| 132 | 13 | 40µs | 13 | 30µs | my $attr_metaclass = $class->attribute_metaclass; # spent 30µs making 13 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 2µs/call |
| 133 | |||||
| 134 | 13 | 76µs | 13 | 111µs | foreach my $attribute_name ($role->get_attribute_list) { # spent 111µs making 13 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 9µs/call |
| 135 | # it if it has one already | ||||
| 136 | 37 | 176µs | 37 | 209µs | if ($class->has_attribute($attribute_name) && # spent 209µs making 37 calls to Class::MOP::Mixin::HasAttributes::has_attribute, avg 6µs/call |
| 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 | 37 | 162µs | 111 | 60.5ms | $class->add_attribute( # spent 45.8ms making 37 calls to Moose::Meta::Class::add_attribute, avg 1.24ms/call
# spent 14.6ms making 37 calls to Moose::Meta::Role::Attribute::attribute_for_class, avg 394µs/call
# spent 187µs making 37 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 5µs/call |
| 143 | $role->get_attribute($attribute_name)->attribute_for_class($attr_metaclass) | ||||
| 144 | ); | ||||
| 145 | } | ||||
| 146 | } | ||||
| 147 | } | ||||
| 148 | |||||
| 149 | # spent 28.0ms (1.17+26.8) within Moose::Meta::Role::Application::ToClass::apply_methods which was called 13 times, avg 2.15ms/call:
# 13 times (1.17ms+26.8ms) by Moose::Meta::Role::Application::apply at line 73 of Moose/Meta/Role/Application.pm, avg 2.15ms/call | ||||
| 150 | 13 | 15µs | my ($self, $role, $class) = @_; | ||
| 151 | 13 | 121µs | 13 | 9.34ms | foreach my $method_name ($role->get_method_list) { # spent 9.34ms making 13 calls to Class::MOP::Mixin::HasMethods::get_method_list, avg 719µs/call |
| 152 | 81 | 22µs | next if $method_name eq 'meta'; | ||
| 153 | |||||
| 154 | 68 | 165µs | 68 | 476µs | unless ($self->is_method_excluded($method_name)) { # spent 476µs making 68 calls to Moose::Meta::Role::Application::is_method_excluded, avg 7µs/call |
| 155 | # it if it has one already | ||||
| 156 | 68 | 95µs | 68 | 2.22ms | if ($class->has_method($method_name) && # spent 2.22ms making 68 calls to Class::MOP::Mixin::HasMethods::has_method, avg 33µs/call |
| 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 | 68 | 145µs | 136 | 14.3ms | $class->add_method( # spent 12.8ms making 68 calls to Class::MOP::Mixin::HasMethods::add_method, avg 188µs/call
# spent 1.53ms making 68 calls to Class::MOP::Mixin::HasMethods::get_method, avg 22µs/call |
| 164 | $method_name, | ||||
| 165 | $role->get_method($method_name) | ||||
| 166 | ); | ||||
| 167 | } | ||||
| 168 | } | ||||
| 169 | |||||
| 170 | 68 | 131µs | 68 | 420µs | if ($self->is_method_aliased($method_name)) { # spent 420µs making 68 calls to Moose::Meta::Role::Application::is_method_aliased, avg 6µs/call |
| 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 | 13 | 66µs | 13 | 35µs | $class->reset_package_cache_flag; # spent 35µs making 13 calls to Class::MOP::Class::reset_package_cache_flag, avg 3µs/call |
| 188 | } | ||||
| 189 | |||||
| 190 | # spent 250µs (96+154) within Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers which was called 13 times, avg 19µs/call:
# 13 times (96µs+154µs) by Moose::Meta::Role::Application::apply at line 75 of Moose/Meta/Role/Application.pm, avg 19µs/call | ||||
| 191 | 13 | 13µs | my ($self, $role, $class) = @_; | ||
| 192 | 13 | 79µs | 13 | 154µs | foreach my $method_name ($role->get_method_modifier_list('override')) { # spent 154µs making 13 calls to Moose::Meta::Role::get_method_modifier_list, avg 12µs/call |
| 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 | # spent 11.2ms (547µs+10.7) within Moose::Meta::Role::Application::ToClass::apply_method_modifiers which was called 39 times, avg 288µs/call:
# 13 times (189µs+4.30ms) by Moose::Meta::Role::Application::apply_after_method_modifiers at line 93 of Moose/Meta/Role/Application.pm, avg 345µs/call
# 13 times (146µs+3.23ms) by Moose::Meta::Role::Application::apply_around_method_modifiers at line 92 of Moose/Meta/Role/Application.pm, avg 260µs/call
# 13 times (212µs+3.16ms) by Moose::Meta::Role::Application::apply_before_method_modifiers at line 91 of Moose/Meta/Role/Application.pm, avg 260µs/call | ||||
| 211 | 39 | 27µs | my ($self, $modifier_type, $role, $class) = @_; | ||
| 212 | 39 | 21µs | my $add = "add_${modifier_type}_method_modifier"; | ||
| 213 | 39 | 13µs | my $get = "get_${modifier_type}_method_modifiers"; | ||
| 214 | 39 | 154µs | 39 | 341µs | foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { # spent 341µs making 39 calls to Moose::Meta::Role::get_method_modifier_list, avg 9µs/call |
| 215 | $class->$add( | ||||
| 216 | $method_name, | ||||
| 217 | $_ | ||||
| 218 | 86 | 219µs | 86 | 10.4ms | ) foreach $role->$get($method_name); # spent 4.06ms making 20 calls to Class::MOP::Class::add_after_method_modifier, avg 203µs/call
# spent 3.04ms making 10 calls to Class::MOP::Class::add_around_method_modifier, avg 304µs/call
# spent 2.95ms making 13 calls to Class::MOP::Class::add_before_method_modifier, avg 227µs/call
# spent 128µs making 20 calls to Moose::Meta::Role::get_after_method_modifiers, avg 6µs/call
# spent 100µs making 13 calls to Moose::Meta::Role::get_before_method_modifiers, avg 8µs/call
# spent 75µs making 10 calls to Moose::Meta::Role::get_around_method_modifiers, avg 8µs/call |
| 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 |