| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm |
| Statements | Executed 8449 statements in 116ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 596 | 6 | 3 | 18.2ms | 26.3ms | Moose::Meta::Role::get_method_modifier_list |
| 141 | 4 | 2 | 16.8ms | 1.82s | Moose::Meta::Role::apply |
| 82 | 2 | 2 | 6.90ms | 319ms | Moose::Meta::Role::initialize |
| 42 | 1 | 1 | 5.52ms | 397ms | Moose::Meta::Role::create |
| 68 | 1 | 1 | 4.46ms | 7.10ms | Moose::Meta::Role::add_role |
| 255 | 6 | 2 | 2.60ms | 2.60ms | Moose::Meta::Role::__ANON__[:302] |
| 1 | 1 | 1 | 2.60ms | 13.8ms | Moose::Meta::Role::BEGIN@17 |
| 60 | 3 | 3 | 2.52ms | 10.8ms | Moose::Meta::Role::add_override_method_modifier |
| 93 | 3 | 3 | 2.46ms | 3.53ms | Moose::Meta::Role::get_override_method_modifier |
| 112 | 2 | 2 | 2.38ms | 30.2ms | Moose::Meta::Role::find_method_by_name |
| 42 | 1 | 1 | 2.15ms | 399ms | Moose::Meta::Role::create_anon_role |
| 23 | 4 | 4 | 2.05ms | 4.33ms | Moose::Meta::Role::add_required_methods |
| 24 | 2 | 2 | 1.71ms | 9.88ms | Moose::Meta::Role::add_attribute |
| 170 | 5 | 2 | 1.70ms | 1.70ms | Moose::Meta::Role::__ANON__[:89] |
| 1 | 1 | 1 | 1.38ms | 7.33ms | Moose::Meta::Role::BEGIN@19 |
| 48 | 1 | 1 | 1.28ms | 1.81ms | Moose::Meta::Role::has_override_method_modifier |
| 1 | 1 | 1 | 1.18ms | 6.42ms | Moose::Meta::Role::BEGIN@20 |
| 1 | 1 | 1 | 965µs | 1.47ms | Moose::Meta::Role::BEGIN@18 |
| 85 | 3 | 2 | 896µs | 896µs | Moose::Meta::Role::__ANON__[:347] |
| 82 | 1 | 1 | 822µs | 822µs | Moose::Meta::Role::_meta_method_class |
| 82 | 2 | 2 | 797µs | 797µs | Moose::Meta::Role::__ANON__[:392] |
| 12 | 2 | 2 | 755µs | 982µs | Moose::Meta::Role::calculate_all_roles (recurses: max depth 1, inclusive time 375µs) |
| 3 | 1 | 1 | 565µs | 73.4ms | Moose::Meta::Role::combine |
| 24 | 1 | 1 | 521µs | 1.97ms | Moose::Meta::Role::_attach_attribute |
| 6 | 1 | 1 | 426µs | 564µs | Moose::Meta::Role::does_role |
| 2 | 1 | 1 | 161µs | 976µs | Moose::Meta::Role::add_conflicting_method |
| 8 | 1 | 1 | 86µs | 86µs | Moose::Meta::Role::_role_for_combination |
| 1 | 1 | 1 | 70µs | 88µs | Moose::Meta::Role::BEGIN@4 |
| 1 | 1 | 1 | 63µs | 296µs | Moose::Meta::Role::BEGIN@8 |
| 1 | 1 | 1 | 62µs | 268µs | Moose::Meta::Role::BEGIN@9 |
| 1 | 1 | 1 | 59µs | 1.30ms | Moose::Meta::Role::BEGIN@10 |
| 1 | 1 | 1 | 56µs | 133µs | Moose::Meta::Role::BEGIN@599 |
| 8 | 1 | 1 | 50µs | 50µs | Moose::Meta::Role::composition_class_roles |
| 1 | 1 | 1 | 48µs | 3.92ms | Moose::Meta::Role::BEGIN@6 |
| 1 | 1 | 1 | 45µs | 105µs | Moose::Meta::Role::BEGIN@621 |
| 1 | 1 | 1 | 39µs | 104µs | Moose::Meta::Role::BEGIN@636 |
| 1 | 1 | 1 | 39µs | 919µs | Moose::Meta::Role::BEGIN@22 |
| 1 | 1 | 1 | 38µs | 633µs | Moose::Meta::Role::BEGIN@25 |
| 1 | 1 | 1 | 38µs | 38µs | Moose::Meta::Role::BEGIN@21 |
| 1 | 1 | 1 | 38µs | 104µs | Moose::Meta::Role::BEGIN@5 |
| 1 | 1 | 1 | 30µs | 30µs | Moose::Meta::Role::BEGIN@16 |
| 1 | 1 | 1 | 27µs | 27µs | Moose::Meta::Role::BEGIN@23 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::DESTROY |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:101] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:106] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:111] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:116] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:121] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:311] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:319] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:338] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:96] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::_restore_metaobjects_from |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::consumers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::is_anon_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::reinitialize |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Role; | ||||
| 3 | |||||
| 4 | 3 | 100µs | 2 | 106µs | # spent 88µs (70+18) within Moose::Meta::Role::BEGIN@4 which was called:
# once (70µs+18µs) by Moose::BEGIN@27 at line 4 # spent 88µs making 1 call to Moose::Meta::Role::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 93µs | 2 | 171µs | # spent 104µs (38+66) within Moose::Meta::Role::BEGIN@5 which was called:
# once (38µs+66µs) by Moose::BEGIN@27 at line 5 # spent 104µs making 1 call to Moose::Meta::Role::BEGIN@5
# spent 66µs making 1 call to warnings::import |
| 6 | 3 | 206µs | 2 | 7.80ms | # spent 3.92ms (48µs+3.88) within Moose::Meta::Role::BEGIN@6 which was called:
# once (48µs+3.88ms) by Moose::BEGIN@27 at line 6 # spent 3.92ms making 1 call to Moose::Meta::Role::BEGIN@6
# spent 3.88ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 3 | 181µs | 2 | 530µs | # spent 296µs (63+234) within Moose::Meta::Role::BEGIN@8 which was called:
# once (63µs+234µs) by Moose::BEGIN@27 at line 8 # spent 296µs making 1 call to Moose::Meta::Role::BEGIN@8
# spent 234µs making 1 call to Exporter::import |
| 9 | 3 | 181µs | 2 | 474µs | # spent 268µs (62+206) within Moose::Meta::Role::BEGIN@9 which was called:
# once (62µs+206µs) by Moose::BEGIN@27 at line 9 # spent 268µs making 1 call to Moose::Meta::Role::BEGIN@9
# spent 206µs making 1 call to Exporter::import |
| 10 | 3 | 296µs | 2 | 2.54ms | # spent 1.30ms (59µs+1.24) within Moose::Meta::Role::BEGIN@10 which was called:
# once (59µs+1.24ms) by Moose::BEGIN@27 at line 10 # spent 1.30ms making 1 call to Moose::Meta::Role::BEGIN@10
# spent 1.24ms making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 11 | |||||
| 12 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 13 | 1 | 74µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 14 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 15 | |||||
| 16 | 3 | 128µs | 1 | 30µs | # spent 30µs within Moose::Meta::Role::BEGIN@16 which was called:
# once (30µs+0s) by Moose::BEGIN@27 at line 16 # spent 30µs making 1 call to Moose::Meta::Role::BEGIN@16 |
| 17 | 3 | 502µs | 1 | 13.8ms | # spent 13.8ms (2.60+11.2) within Moose::Meta::Role::BEGIN@17 which was called:
# once (2.60ms+11.2ms) by Moose::BEGIN@27 at line 17 # spent 13.8ms making 1 call to Moose::Meta::Role::BEGIN@17 |
| 18 | 3 | 878µs | 1 | 1.47ms | # spent 1.47ms (965µs+502µs) within Moose::Meta::Role::BEGIN@18 which was called:
# once (965µs+502µs) by Moose::BEGIN@27 at line 18 # spent 1.47ms making 1 call to Moose::Meta::Role::BEGIN@18 |
| 19 | 3 | 530µs | 1 | 7.33ms | # spent 7.33ms (1.38+5.95) within Moose::Meta::Role::BEGIN@19 which was called:
# once (1.38ms+5.95ms) by Moose::BEGIN@27 at line 19 # spent 7.33ms making 1 call to Moose::Meta::Role::BEGIN@19 |
| 20 | 3 | 508µs | 1 | 6.42ms | # spent 6.42ms (1.18+5.24) within Moose::Meta::Role::BEGIN@20 which was called:
# once (1.18ms+5.24ms) by Moose::BEGIN@27 at line 20 # spent 6.42ms making 1 call to Moose::Meta::Role::BEGIN@20 |
| 21 | 3 | 119µs | 1 | 38µs | # spent 38µs within Moose::Meta::Role::BEGIN@21 which was called:
# once (38µs+0s) by Moose::BEGIN@27 at line 21 # spent 38µs making 1 call to Moose::Meta::Role::BEGIN@21 |
| 22 | 3 | 136µs | 2 | 1.80ms | # spent 919µs (39+880) within Moose::Meta::Role::BEGIN@22 which was called:
# once (39µs+880µs) by Moose::BEGIN@27 at line 22 # spent 919µs making 1 call to Moose::Meta::Role::BEGIN@22
# spent 880µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 23 | 3 | 110µs | 1 | 27µs | # spent 27µs within Moose::Meta::Role::BEGIN@23 which was called:
# once (27µs+0s) by Moose::BEGIN@27 at line 23 # spent 27µs making 1 call to Moose::Meta::Role::BEGIN@23 |
| 24 | |||||
| 25 | 1 | 25µs | 1 | 594µs | # spent 633µs (38+594) within Moose::Meta::Role::BEGIN@25 which was called:
# once (38µs+594µs) by Moose::BEGIN@27 at line 27 # spent 594µs making 1 call to base::import |
| 26 | 'Class::MOP::Mixin::HasAttributes', | ||||
| 27 | 2 | 8.53ms | 1 | 633µs | 'Class::MOP::Mixin::HasMethods'; # spent 633µs making 1 call to Moose::Meta::Role::BEGIN@25 |
| 28 | |||||
| 29 | 1 | 14µs | 1 | 6.90ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 6.90ms making 1 call to Class::MOP::MiniTrait::apply |
| 30 | |||||
| 31 | ## ------------------------------------------------------------------ | ||||
| 32 | ## NOTE: | ||||
| 33 | ## I normally don't do this, but I am doing | ||||
| 34 | ## a whole bunch of meta-programmin in this | ||||
| 35 | ## module, so it just makes sense. For a clearer | ||||
| 36 | ## picture of what is going on in the next | ||||
| 37 | ## several lines of code, look at the really | ||||
| 38 | ## big comment at the end of this file (right | ||||
| 39 | ## before the POD). | ||||
| 40 | ## - SL | ||||
| 41 | ## ------------------------------------------------------------------ | ||||
| 42 | |||||
| 43 | 1 | 14µs | 1 | 90µs | my $META = __PACKAGE__->meta; # spent 90µs making 1 call to Moose::Meta::Role::meta |
| 44 | |||||
| 45 | ## ------------------------------------------------------------------ | ||||
| 46 | ## attributes ... | ||||
| 47 | |||||
| 48 | # NOTE: | ||||
| 49 | # since roles are lazy, we hold all the attributes | ||||
| 50 | # of the individual role in 'statis' until which | ||||
| 51 | # time when it is applied to a class. This means | ||||
| 52 | # keeping a lot of things in hash maps, so we are | ||||
| 53 | # using a little of that meta-programmin' magic | ||||
| 54 | # here an saving lots of extra typin. And since | ||||
| 55 | # many of these attributes above require similar | ||||
| 56 | # functionality to support them, so we again use | ||||
| 57 | # the wonders of meta-programmin' to deliver a | ||||
| 58 | # very compact solution to this normally verbose | ||||
| 59 | # problem. | ||||
| 60 | # - SL | ||||
| 61 | |||||
| 62 | 1 | 49µs | foreach my $action ( | ||
| 63 | { | ||||
| 64 | name => 'excluded_roles_map', | ||||
| 65 | attr_reader => 'get_excluded_roles_map' , | ||||
| 66 | methods => { | ||||
| 67 | add => 'add_excluded_roles', | ||||
| 68 | get_keys => 'get_excluded_roles_list', | ||||
| 69 | existence => 'excludes_role', | ||||
| 70 | } | ||||
| 71 | }, | ||||
| 72 | { | ||||
| 73 | name => 'required_methods', | ||||
| 74 | attr_reader => 'get_required_methods_map', | ||||
| 75 | methods => { | ||||
| 76 | remove => 'remove_required_methods', | ||||
| 77 | get_values => 'get_required_method_list', | ||||
| 78 | existence => 'requires_method', | ||||
| 79 | } | ||||
| 80 | }, | ||||
| 81 | ) { | ||||
| 82 | |||||
| 83 | 2 | 10µs | my $attr_reader = $action->{attr_reader}; | ||
| 84 | 2 | 5µs | my $methods = $action->{methods}; | ||
| 85 | |||||
| 86 | # create the attribute | ||||
| 87 | $META->add_attribute($action->{name} => ( | ||||
| 88 | reader => $attr_reader, | ||||
| 89 | 170 | 2.25ms | # spent 1.70ms within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:89] which was called 170 times, avg 10µs/call:
# 88 times (979µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 11µs/call
# 38 times (337µs+0s) by Moose::Meta::Role::_new at line 111 of generated method (unknown origin), avg 9µs/call
# 38 times (333µs+0s) by Moose::Meta::Role::_new at line 81 of generated method (unknown origin), avg 9µs/call
# 3 times (26µs+0s) by Moose::Meta::Role::Composite::_new at line 87 of generated method (unknown origin), avg 9µs/call
# 3 times (25µs+0s) by Moose::Meta::Role::Composite::_new at line 120 of generated method (unknown origin), avg 8µs/call | ||
| 90 | 2 | 40µs | 2 | 4.01ms | )); # spent 4.01ms making 2 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.00ms/call |
| 91 | |||||
| 92 | # create some helper methods | ||||
| 93 | $META->add_method($methods->{add} => sub { | ||||
| 94 | 3 | 12µs | my ($self, @values) = @_; | ||
| 95 | 6 | 64µs | $self->$attr_reader->{$_} = undef foreach @values; | ||
| 96 | 2 | 29µs | 1 | 323µs | }) if exists $methods->{add}; # spent 323µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 97 | |||||
| 98 | $META->add_method($methods->{get_keys} => sub { | ||||
| 99 | 149 | 505µs | my ($self) = @_; | ||
| 100 | 149 | 3.32ms | 149 | 1.82ms | keys %{$self->$attr_reader}; # spent 1.82ms making 149 calls to Moose::Meta::Role::get_excluded_roles_map, avg 12µs/call |
| 101 | 2 | 24µs | 1 | 266µs | }) if exists $methods->{get_keys}; # spent 266µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 102 | |||||
| 103 | $META->add_method($methods->{get_values} => sub { | ||||
| 104 | 149 | 411µs | my ($self) = @_; | ||
| 105 | 149 | 3.42ms | 149 | 1.91ms | values %{$self->$attr_reader}; # spent 1.91ms making 149 calls to Moose::Meta::Role::get_required_methods_map, avg 13µs/call |
| 106 | 2 | 27µs | 1 | 294µs | }) if exists $methods->{get_values}; # spent 294µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 107 | |||||
| 108 | $META->add_method($methods->{get} => sub { | ||||
| 109 | my ($self, $name) = @_; | ||||
| 110 | $self->$attr_reader->{$name} | ||||
| 111 | 2 | 6µs | }) if exists $methods->{get}; | ||
| 112 | |||||
| 113 | $META->add_method($methods->{existence} => sub { | ||||
| 114 | 144 | 619µs | my ($self, $name) = @_; | ||
| 115 | 144 | 3.40ms | 144 | 1.95ms | exists $self->$attr_reader->{$name} ? 1 : 0; # spent 1.95ms making 144 calls to Moose::Meta::Role::get_excluded_roles_map, avg 14µs/call |
| 116 | 2 | 40µs | 2 | 556µs | }) if exists $methods->{existence}; # spent 556µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 278µs/call |
| 117 | |||||
| 118 | $META->add_method($methods->{remove} => sub { | ||||
| 119 | my ($self, @values) = @_; | ||||
| 120 | delete $self->$attr_reader->{$_} foreach @values; | ||||
| 121 | 2 | 35µs | 1 | 285µs | }) if exists $methods->{remove}; # spent 285µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 122 | } | ||||
| 123 | |||||
| 124 | $META->add_attribute( | ||||
| 125 | 1 | 13µs | 1 | 1.93ms | 'method_metaclass', # spent 1.93ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 126 | reader => 'method_metaclass', | ||||
| 127 | default => 'Moose::Meta::Role::Method', | ||||
| 128 | ); | ||||
| 129 | |||||
| 130 | 1 | 14µs | 1 | 1.91ms | $META->add_attribute( # spent 1.91ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 131 | 'required_method_metaclass', | ||||
| 132 | reader => 'required_method_metaclass', | ||||
| 133 | default => 'Moose::Meta::Role::Method::Required', | ||||
| 134 | ); | ||||
| 135 | |||||
| 136 | 1 | 14µs | 1 | 1.85ms | $META->add_attribute( # spent 1.85ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 137 | 'conflicting_method_metaclass', | ||||
| 138 | reader => 'conflicting_method_metaclass', | ||||
| 139 | default => 'Moose::Meta::Role::Method::Conflicting', | ||||
| 140 | ); | ||||
| 141 | |||||
| 142 | 1 | 13µs | 1 | 2.14ms | $META->add_attribute( # spent 2.14ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 143 | 'application_to_class_class', | ||||
| 144 | reader => 'application_to_class_class', | ||||
| 145 | default => 'Moose::Meta::Role::Application::ToClass', | ||||
| 146 | ); | ||||
| 147 | |||||
| 148 | 1 | 13µs | 1 | 1.96ms | $META->add_attribute( # spent 1.96ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 149 | 'application_to_role_class', | ||||
| 150 | reader => 'application_to_role_class', | ||||
| 151 | default => 'Moose::Meta::Role::Application::ToRole', | ||||
| 152 | ); | ||||
| 153 | |||||
| 154 | 1 | 13µs | 1 | 2.02ms | $META->add_attribute( # spent 2.02ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 155 | 'application_to_instance_class', | ||||
| 156 | reader => 'application_to_instance_class', | ||||
| 157 | default => 'Moose::Meta::Role::Application::ToInstance', | ||||
| 158 | ); | ||||
| 159 | |||||
| 160 | 1 | 14µs | 1 | 1.89ms | $META->add_attribute( # spent 1.89ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 161 | 'applied_attribute_metaclass', | ||||
| 162 | reader => 'applied_attribute_metaclass', | ||||
| 163 | default => 'Moose::Meta::Attribute', | ||||
| 164 | ); | ||||
| 165 | |||||
| 166 | # More or less copied from Moose::Meta::Class | ||||
| 167 | # spent 319ms (6.90+312) within Moose::Meta::Role::initialize which was called 82 times, avg 3.89ms/call:
# 42 times (3.94ms+274ms) by Moose::Meta::Role::create at line 543, avg 6.61ms/call
# 40 times (2.96ms+38.2ms) by Moose::Role::init_meta at line 131 of Moose/Role.pm, avg 1.03ms/call | ||||
| 168 | 82 | 305µs | my $class = shift; | ||
| 169 | 82 | 232µs | my $pkg = shift; | ||
| 170 | |||||
| 171 | 82 | 862µs | 82 | 695µs | if (defined(my $meta = Class::MOP::get_metaclass_by_name($pkg))) { # spent 695µs making 82 calls to Class::MOP::get_metaclass_by_name, avg 8µs/call |
| 172 | return $meta; | ||||
| 173 | } | ||||
| 174 | |||||
| 175 | 82 | 466µs | my %options = @_; | ||
| 176 | |||||
| 177 | 82 | 2.78ms | 82 | 310ms | my $meta = $class->SUPER::initialize( # spent 310ms making 82 calls to Class::MOP::Package::initialize, avg 3.78ms/call |
| 178 | $pkg, | ||||
| 179 | 'attribute_metaclass' => 'Moose::Meta::Role::Attribute', | ||||
| 180 | %options, | ||||
| 181 | ); | ||||
| 182 | |||||
| 183 | 82 | 643µs | 42 | 1.27ms | Class::MOP::weaken_metaclass($pkg) if $options{weaken}; # spent 1.27ms making 42 calls to Class::MOP::weaken_metaclass, avg 30µs/call |
| 184 | |||||
| 185 | 82 | 1.12ms | return $meta; | ||
| 186 | } | ||||
| 187 | |||||
| 188 | sub reinitialize { | ||||
| 189 | my $self = shift; | ||||
| 190 | my $pkg = shift; | ||||
| 191 | |||||
| 192 | my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg); | ||||
| 193 | |||||
| 194 | my %existing_classes; | ||||
| 195 | if ($meta) { | ||||
| 196 | %existing_classes = map { $_ => $meta->$_() } qw( | ||||
| 197 | attribute_metaclass | ||||
| 198 | method_metaclass | ||||
| 199 | wrapped_method_metaclass | ||||
| 200 | required_method_metaclass | ||||
| 201 | conflicting_method_metaclass | ||||
| 202 | application_to_class_class | ||||
| 203 | application_to_role_class | ||||
| 204 | application_to_instance_class | ||||
| 205 | applied_attribute_metaclass | ||||
| 206 | ); | ||||
| 207 | } | ||||
| 208 | |||||
| 209 | my %options = @_; | ||||
| 210 | $options{weaken} = Class::MOP::metaclass_is_weak($meta->name) | ||||
| 211 | if !exists $options{weaken} | ||||
| 212 | && blessed($meta) | ||||
| 213 | && $meta->isa('Moose::Meta::Role'); | ||||
| 214 | |||||
| 215 | # don't need to remove generated metaobjects here yet, since we don't | ||||
| 216 | # yet generate anything in roles. this may change in the future though... | ||||
| 217 | # keep an eye on that | ||||
| 218 | my $new_meta = $self->SUPER::reinitialize( | ||||
| 219 | $pkg, | ||||
| 220 | %existing_classes, | ||||
| 221 | %options, | ||||
| 222 | ); | ||||
| 223 | $new_meta->_restore_metaobjects_from($meta) | ||||
| 224 | if $meta && $meta->isa('Moose::Meta::Role'); | ||||
| 225 | return $new_meta; | ||||
| 226 | } | ||||
| 227 | |||||
| 228 | sub _restore_metaobjects_from { | ||||
| 229 | my $self = shift; | ||||
| 230 | my ($old_meta) = @_; | ||||
| 231 | |||||
| 232 | $self->_restore_metamethods_from($old_meta); | ||||
| 233 | $self->_restore_metaattributes_from($old_meta); | ||||
| 234 | } | ||||
| 235 | |||||
| 236 | # spent 9.88ms (1.71+8.17) within Moose::Meta::Role::add_attribute which was called 24 times, avg 412µs/call:
# 15 times (970µs+4.33ms) by Moose::Meta::Role::Application::ToRole::apply_attributes at line 71 of Moose/Meta/Role/Application/ToRole.pm, avg 353µs/call
# 9 times (740µs+3.84ms) by Moose::Role::has at line 47 of Moose/Role.pm, avg 509µs/call | ||||
| 237 | 24 | 72µs | my $self = shift; | ||
| 238 | |||||
| 239 | 24 | 1.12ms | 72 | 379µs | if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) { # spent 240µs making 48 calls to Scalar::Util::blessed, avg 5µs/call
# spent 92µs making 15 calls to UNIVERSAL::isa, avg 6µs/call
# spent 48µs making 9 calls to Moose::Meta::Role::CORE:match, avg 5µs/call |
| 240 | my $class = ref $_[0]; | ||||
| 241 | Moose->throw_error( "Cannot add a $class as an attribute to a role" ); | ||||
| 242 | } | ||||
| 243 | elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) { | ||||
| 244 | Moose->throw_error( "has '+attr' is not supported in roles" ); | ||||
| 245 | } | ||||
| 246 | |||||
| 247 | 24 | 896µs | 24 | 7.79ms | return $self->SUPER::add_attribute(@_); # spent 7.79ms making 24 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 325µs/call |
| 248 | } | ||||
| 249 | |||||
| 250 | # spent 1.97ms (521µs+1.45) within Moose::Meta::Role::_attach_attribute which was called 24 times, avg 82µs/call:
# 24 times (521µs+1.45ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 25 of Class/MOP/Mixin/HasAttributes.pm, avg 82µs/call | ||||
| 251 | 24 | 84µs | my ( $self, $attribute ) = @_; | ||
| 252 | |||||
| 253 | 24 | 432µs | 24 | 1.45ms | $attribute->attach_to_role($self); # spent 1.45ms making 24 calls to Moose::Meta::Role::Attribute::attach_to_role, avg 61µs/call |
| 254 | } | ||||
| 255 | |||||
| 256 | # spent 4.33ms (2.05+2.28) within Moose::Meta::Role::add_required_methods which was called 23 times, avg 188µs/call:
# 9 times (1.04ms+1.77ms) by Moose::Role::requires at line 32 of Moose/Role.pm, avg 312µs/call
# 9 times (571µs+284µs) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 95µs/call
# 3 times (295µs+157µs) by Moose::Meta::Role::Application::RoleSummation::check_required_methods at line 109 of Moose/Meta/Role/Application/RoleSummation.pm, avg 151µs/call
# 2 times (144µs+69µs) by Moose::Meta::Role::add_conflicting_method at line 281, avg 106µs/call | ||||
| 257 | 23 | 69µs | my $self = shift; | ||
| 258 | |||||
| 259 | 23 | 371µs | for (@_) { | ||
| 260 | 26 | 68µs | my $method = $_; | ||
| 261 | 26 | 747µs | 46 | 1.53ms | if (!blessed($method)) { # spent 1.22ms making 10 calls to Moose::Meta::Role::Method::Required::new, avg 122µs/call
# spent 156µs making 10 calls to Moose::Meta::Role::required_method_metaclass, avg 16µs/call
# spent 148µs making 26 calls to Scalar::Util::blessed, avg 6µs/call |
| 262 | $method = $self->required_method_metaclass->new( | ||||
| 263 | name => $method, | ||||
| 264 | ); | ||||
| 265 | } | ||||
| 266 | 26 | 812µs | 52 | 752µs | $self->get_required_methods_map->{$method->name} = $method; # spent 386µs making 26 calls to Moose::Meta::Role::get_required_methods_map, avg 15µs/call
# spent 367µs making 26 calls to Moose::Meta::Role::Method::Required::name, avg 14µs/call |
| 267 | } | ||||
| 268 | } | ||||
| 269 | |||||
| 270 | # spent 976µs (161+816) within Moose::Meta::Role::add_conflicting_method which was called 2 times, avg 488µs/call:
# 2 times (161µs+816µs) by Moose::Meta::Role::Application::RoleSummation::apply_methods at line 186 of Moose/Meta/Role/Application/RoleSummation.pm, avg 488µs/call | ||||
| 271 | 2 | 8µs | my $self = shift; | ||
| 272 | |||||
| 273 | 2 | 4µs | my $method; | ||
| 274 | 2 | 12µs | if (@_ == 1 && blessed($_[0])) { | ||
| 275 | $method = shift; | ||||
| 276 | } | ||||
| 277 | else { | ||||
| 278 | 2 | 70µs | 4 | 603µs | $method = $self->conflicting_method_metaclass->new(@_); # spent 569µs making 2 calls to Moose::Meta::Role::Method::Required::new, avg 284µs/call
# spent 34µs making 2 calls to Moose::Meta::Role::conflicting_method_metaclass, avg 17µs/call |
| 279 | } | ||||
| 280 | |||||
| 281 | 2 | 45µs | 2 | 213µs | $self->add_required_methods($method); # spent 213µs making 2 calls to Moose::Meta::Role::add_required_methods, avg 106µs/call |
| 282 | } | ||||
| 283 | |||||
| 284 | ## ------------------------------------------------------------------ | ||||
| 285 | ## method modifiers | ||||
| 286 | |||||
| 287 | # NOTE: | ||||
| 288 | # the before/around/after method modifiers are | ||||
| 289 | # stored by name, but there can be many methods | ||||
| 290 | # then associated with that name. So again we have | ||||
| 291 | # lots of similar functionality, so we can do some | ||||
| 292 | # meta-programmin' and save some time. | ||||
| 293 | # - SL | ||||
| 294 | |||||
| 295 | 1 | 7µs | foreach my $modifier_type (qw[ before around after ]) { | ||
| 296 | |||||
| 297 | 3 | 21µs | my $attr_reader = "get_${modifier_type}_method_modifiers_map"; | ||
| 298 | |||||
| 299 | # create the attribute ... | ||||
| 300 | $META->add_attribute("${modifier_type}_method_modifiers" => ( | ||||
| 301 | reader => $attr_reader, | ||||
| 302 | 255 | 3.22ms | # spent 2.60ms within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:302] which was called 255 times, avg 10µs/call:
# 132 times (1.42ms+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 11µs/call
# 41 times (450µs+0s) by Moose::Meta::Role::Composite::_new or Moose::Meta::Role::_new at line 18 of generated method (unknown origin), avg 11µs/call
# 38 times (366µs+0s) by Moose::Meta::Role::_new at line 69 of generated method (unknown origin), avg 10µs/call
# 38 times (318µs+0s) by Moose::Meta::Role::_new at line 48 of generated method (unknown origin), avg 8µs/call
# 3 times (26µs+0s) by Moose::Meta::Role::Composite::_new at line 54 of generated method (unknown origin), avg 9µs/call
# 3 times (25µs+0s) by Moose::Meta::Role::Composite::_new at line 75 of generated method (unknown origin), avg 8µs/call | ||
| 303 | 3 | 123µs | 3 | 5.90ms | )); # spent 5.90ms making 3 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 1.97ms/call |
| 304 | |||||
| 305 | # and some helper methods ... | ||||
| 306 | $META->add_method("get_${modifier_type}_method_modifiers" => sub { | ||||
| 307 | 139 | 591µs | my ($self, $method_name) = @_; | ||
| 308 | #return () unless exists $self->$attr_reader->{$method_name}; | ||||
| 309 | 139 | 1.75ms | 139 | 1.59ms | my $mm = $self->$attr_reader->{$method_name}; # spent 1.25ms making 107 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 12µs/call
# spent 228µs making 21 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call
# spent 113µs making 11 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 10µs/call |
| 310 | 139 | 2.05ms | $mm ? @$mm : (); | ||
| 311 | 3 | 81µs | 3 | 879µs | }); # spent 879µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 293µs/call |
| 312 | |||||
| 313 | $META->add_method("has_${modifier_type}_method_modifiers" => sub { | ||||
| 314 | my ($self, $method_name) = @_; | ||||
| 315 | # NOTE: | ||||
| 316 | # for now we assume that if it exists,.. | ||||
| 317 | # it has at least one modifier in it | ||||
| 318 | (exists $self->$attr_reader->{$method_name}) ? 1 : 0; | ||||
| 319 | 3 | 69µs | 3 | 853µs | }); # spent 853µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 284µs/call |
| 320 | |||||
| 321 | $META->add_method("add_${modifier_type}_method_modifier" => sub { | ||||
| 322 | 90 | 391µs | my ($self, $method_name, $method) = @_; | ||
| 323 | |||||
| 324 | 90 | 2.16ms | 180 | 1.94ms | $self->$attr_reader->{$method_name} = [] # spent 1.50ms making 140 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 291µs making 26 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call
# spent 152µs making 14 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 11µs/call |
| 325 | unless exists $self->$attr_reader->{$method_name}; | ||||
| 326 | |||||
| 327 | 90 | 1.05ms | 90 | 969µs | my $modifiers = $self->$attr_reader->{$method_name}; # spent 736µs making 70 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 135µs making 13 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 10µs/call
# spent 98µs making 7 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 14µs/call |
| 328 | |||||
| 329 | # NOTE: | ||||
| 330 | # check to see that we aren't adding the | ||||
| 331 | # same code twice. We err in favor of the | ||||
| 332 | # first on here, this may not be as expected | ||||
| 333 | 90 | 474µs | foreach my $modifier (@{$modifiers}) { | ||
| 334 | return if $modifier == $method; | ||||
| 335 | } | ||||
| 336 | |||||
| 337 | 90 | 1.35ms | push @{$modifiers} => $method; | ||
| 338 | 3 | 82µs | 3 | 843µs | }); # spent 843µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 281µs/call |
| 339 | |||||
| 340 | } | ||||
| 341 | |||||
| 342 | ## ------------------------------------------------------------------ | ||||
| 343 | ## override method mofidiers | ||||
| 344 | |||||
| 345 | $META->add_attribute('override_method_modifiers' => ( | ||||
| 346 | reader => 'get_override_method_modifiers_map', | ||||
| 347 | 85 | 1.10ms | # spent 896µs within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:347] which was called 85 times, avg 11µs/call:
# 44 times (516µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 12µs/call
# 38 times (352µs+0s) by Moose::Meta::Role::_new at line 96 of generated method (unknown origin), avg 9µs/call
# 3 times (28µs+0s) by Moose::Meta::Role::Composite::_new at line 105 of generated method (unknown origin), avg 9µs/call | ||
| 348 | 1 | 19µs | 1 | 1.95ms | )); # spent 1.95ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 349 | |||||
| 350 | # NOTE: | ||||
| 351 | # these are a little different because there | ||||
| 352 | # can only be one per name, whereas the other | ||||
| 353 | # method modifiers can have multiples. | ||||
| 354 | # - SL | ||||
| 355 | |||||
| 356 | # spent 10.8ms (2.52+8.31) within Moose::Meta::Role::add_override_method_modifier which was called 60 times, avg 181µs/call:
# 48 times (2.00ms+7.41ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 196µs/call
# 9 times (362µs+388µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 237 of Moose/Meta/Role/Application/RoleSummation.pm, avg 83µs/call
# 3 times (160µs+521µs) by Moose::Role::override at line 77 of Moose/Role.pm, avg 227µs/call | ||||
| 357 | 60 | 244µs | my ($self, $method_name, $method) = @_; | ||
| 358 | 60 | 609µs | 60 | 7.58ms | (!$self->has_method($method_name)) # spent 7.29ms making 51 calls to Class::MOP::Mixin::HasMethods::has_method, avg 143µs/call
# spent 290µs making 9 calls to Moose::Meta::Role::Composite::has_method, avg 32µs/call |
| 359 | || Moose->throw_error("Cannot add an override of method '$method_name' " . | ||||
| 360 | "because there is a local version of '$method_name'"); | ||||
| 361 | 60 | 1.41ms | 60 | 735µs | $self->get_override_method_modifiers_map->{$method_name} = $method; # spent 735µs making 60 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 12µs/call |
| 362 | } | ||||
| 363 | |||||
| 364 | # spent 1.81ms (1.28+532µs) within Moose::Meta::Role::has_override_method_modifier which was called 48 times, avg 38µs/call:
# 48 times (1.28ms+532µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 152 of Moose/Meta/Role/Application/ToRole.pm, avg 38µs/call | ||||
| 365 | 48 | 193µs | my ($self, $method_name) = @_; | ||
| 366 | # NOTE: | ||||
| 367 | # for now we assume that if it exists,.. | ||||
| 368 | # it has at least one modifier in it | ||||
| 369 | 48 | 982µs | 48 | 532µs | (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0; # spent 532µs making 48 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call |
| 370 | } | ||||
| 371 | |||||
| 372 | # spent 3.53ms (2.46+1.07) within Moose::Meta::Role::get_override_method_modifier which was called 93 times, avg 38µs/call:
# 48 times (1.21ms+516µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 36µs/call
# 36 times (1.03ms+462µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 205 of Moose/Meta/Role/Application/ToClass.pm, avg 41µs/call
# 9 times (220µs+89µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 208 of Moose/Meta/Role/Application/RoleSummation.pm, avg 34µs/call | ||||
| 373 | 93 | 372µs | my ($self, $method_name) = @_; | ||
| 374 | 93 | 1.94ms | 93 | 1.07ms | $self->get_override_method_modifiers_map->{$method_name}; # spent 1.07ms making 93 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call |
| 375 | } | ||||
| 376 | |||||
| 377 | ## general list accessor ... | ||||
| 378 | |||||
| 379 | # spent 26.3ms (18.2+8.11) within Moose::Meta::Role::get_method_modifier_list which was called 596 times, avg 44µs/call:
# 219 times (6.53ms+3.08ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 217 of Moose/Meta/Role/Application/ToClass.pm, avg 44µs/call
# 204 times (5.98ms+2.73ms) by Moose::Meta::Role::Application::ToRole::apply_method_modifiers at line 176 of Moose/Meta/Role/Application/ToRole.pm, avg 43µs/call
# 73 times (2.47ms+992µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 195 of Moose/Meta/Role/Application/ToClass.pm, avg 47µs/call
# 68 times (2.31ms+964µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 136 of Moose/Meta/Role/Application/ToRole.pm, avg 48µs/call
# 24 times (685µs+263µs) by Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers at line 246 of Moose/Meta/Role/Application/RoleSummation.pm, avg 40µs/call
# 8 times (243µs+88µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 209 of Moose/Meta/Role/Application/RoleSummation.pm, avg 41µs/call | ||||
| 380 | 596 | 1.84ms | my ($self, $modifier_type) = @_; | ||
| 381 | 596 | 2.06ms | my $accessor = "get_${modifier_type}_method_modifiers_map"; | ||
| 382 | 596 | 13.9ms | 596 | 8.11ms | keys %{$self->$accessor}; # spent 2.10ms making 149 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 14µs/call
# spent 2.04ms making 149 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 14µs/call
# spent 2.01ms making 149 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 13µs/call
# spent 1.96ms making 149 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 13µs/call |
| 383 | } | ||||
| 384 | |||||
| 385 | 82 | 1.01ms | # spent 822µs within Moose::Meta::Role::_meta_method_class which was called 82 times, avg 10µs/call:
# 82 times (822µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 28 of Class/MOP/Mixin/HasMethods.pm, avg 10µs/call | ||
| 386 | |||||
| 387 | ## ------------------------------------------------------------------ | ||||
| 388 | ## subroles | ||||
| 389 | |||||
| 390 | $META->add_attribute('roles' => ( | ||||
| 391 | reader => 'get_roles', | ||||
| 392 | 82 | 1.02ms | # spent 797µs within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:392] which was called 82 times, avg 10µs/call:
# 44 times (440µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 10µs/call
# 38 times (357µs+0s) by Moose::Meta::Role::_new at line 117 of generated method (unknown origin), avg 9µs/call | ||
| 393 | 1 | 20µs | 1 | 1.89ms | )); # spent 1.89ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 394 | |||||
| 395 | # spent 7.10ms (4.46+2.64) within Moose::Meta::Role::add_role which was called 68 times, avg 104µs/call:
# 68 times (4.46ms+2.64ms) by Moose::Meta::Role::Application::ToRole::apply at line 18 of Moose/Meta/Role/Application/ToRole.pm, avg 104µs/call | ||||
| 396 | 68 | 248µs | my ($self, $role) = @_; | ||
| 397 | 68 | 2.44ms | 136 | 943µs | (blessed($role) && $role->isa('Moose::Meta::Role')) # spent 527µs making 68 calls to Scalar::Util::blessed, avg 8µs/call
# spent 416µs making 68 calls to UNIVERSAL::isa, avg 6µs/call |
| 398 | || Moose->throw_error("Roles must be instances of Moose::Meta::Role"); | ||||
| 399 | 68 | 997µs | 68 | 933µs | push @{$self->get_roles} => $role; # spent 933µs making 68 calls to Moose::Meta::Role::get_roles, avg 14µs/call |
| 400 | 68 | 1.44ms | 68 | 761µs | $self->reset_package_cache_flag; # spent 761µs making 68 calls to Class::MOP::Mixin::HasMethods::reset_package_cache_flag, avg 11µs/call |
| 401 | } | ||||
| 402 | |||||
| 403 | # spent 982µs (755+227) within Moose::Meta::Role::calculate_all_roles which was called 12 times, avg 82µs/call:
# 6 times (480µs+502µs) by Moose::Meta::Class::calculate_all_roles at line 200 of Moose/Meta/Class.pm, avg 164µs/call
# 6 times (276µs+-276µs) by Moose::Meta::Role::calculate_all_roles at line 407, avg 0s/call | ||||
| 404 | 12 | 31µs | my $self = shift; | ||
| 405 | 12 | 21µs | my %seen; | ||
| 406 | 18 | 371µs | 18 | 96µs | grep { # spent 96µs making 18 calls to Class::MOP::Package::name, avg 5µs/call |
| 407 | 6 | 65µs | 6 | 0s | !$seen{$_->name}++ # spent 375µs making 6 calls to Moose::Meta::Role::calculate_all_roles, avg 63µs/call, recursion: max depth 1, sum of overlapping time 375µs |
| 408 | } ($self, map { | ||||
| 409 | $_->calculate_all_roles | ||||
| 410 | 12 | 328µs | 12 | 130µs | } @{ $self->get_roles }); # spent 130µs making 12 calls to Moose::Meta::Role::get_roles, avg 11µs/call |
| 411 | } | ||||
| 412 | |||||
| 413 | # spent 564µs (426+138) within Moose::Meta::Role::does_role which was called 6 times, avg 94µs/call:
# 6 times (426µs+138µs) by Moose::Meta::Class::does_role at line 227 of Moose/Meta/Class.pm, avg 94µs/call | ||||
| 414 | 6 | 30µs | my ($self, $role) = @_; | ||
| 415 | 6 | 13µs | (defined $role) | ||
| 416 | || Moose->throw_error("You must supply a role name to look for"); | ||||
| 417 | 6 | 110µs | 6 | 28µs | my $role_name = blessed $role ? $role->name : $role; # spent 28µs making 6 calls to Scalar::Util::blessed, avg 5µs/call |
| 418 | # if we are it,.. then return true | ||||
| 419 | 6 | 136µs | 6 | 36µs | return 1 if $role_name eq $self->name; # spent 36µs making 6 calls to Class::MOP::Package::name, avg 6µs/call |
| 420 | # otherwise.. check our children | ||||
| 421 | 6 | 90µs | 6 | 74µs | foreach my $role (@{$self->get_roles}) { # spent 74µs making 6 calls to Moose::Meta::Role::get_roles, avg 12µs/call |
| 422 | return 1 if $role->does_role($role_name); | ||||
| 423 | } | ||||
| 424 | 6 | 109µs | return 0; | ||
| 425 | } | ||||
| 426 | |||||
| 427 | 112 | 2.27ms | 112 | 27.8ms | # spent 30.2ms (2.38+27.8) within Moose::Meta::Role::find_method_by_name which was called 112 times, avg 269µs/call:
# 82 times (1.73ms+14.3ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 23 of Class/MOP/Mixin/HasMethods.pm, avg 195µs/call
# 30 times (655µs+13.5ms) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 472µs/call # spent 27.8ms making 112 calls to Class::MOP::Mixin::HasMethods::get_method, avg 248µs/call |
| 428 | |||||
| 429 | ## ------------------------------------------------------------------ | ||||
| 430 | ## role construction | ||||
| 431 | ## ------------------------------------------------------------------ | ||||
| 432 | |||||
| 433 | # spent 1.82s (16.8ms+1.80) within Moose::Meta::Role::apply which was called 141 times, avg 12.9ms/call:
# 54 times (6.58ms+1.23s) by Moose::Util::_apply_all_roles at line 137 of Moose/Util.pm, avg 22.8ms/call
# 42 times (5.04ms+379ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::apply at line 121 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 9.13ms/call
# 42 times (4.83ms+123ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::apply_parameterizable_role at line 127 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 3.04ms/call
# 3 times (352µs+70.6ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 23.6ms/call | ||||
| 434 | 141 | 718µs | my ($self, $other, %args) = @_; | ||
| 435 | |||||
| 436 | 141 | 2.71ms | 141 | 940µs | (blessed($other)) # spent 940µs making 141 calls to Scalar::Util::blessed, avg 7µs/call |
| 437 | || Moose->throw_error("You must pass in an blessed instance"); | ||||
| 438 | |||||
| 439 | 141 | 286µs | my $application_class; | ||
| 440 | 141 | 5.78ms | 355 | 3.99ms | if ($other->isa('Moose::Meta::Role')) { # spent 1.67ms making 214 calls to UNIVERSAL::isa, avg 8µs/call
# spent 1.18ms making 73 calls to Moose::Meta::Role::application_to_class_class, avg 16µs/call
# spent 1.14ms making 68 calls to Moose::Meta::Role::application_to_role_class, avg 17µs/call |
| 441 | $application_class = $self->application_to_role_class; | ||||
| 442 | } | ||||
| 443 | elsif ($other->isa('Moose::Meta::Class')) { | ||||
| 444 | $application_class = $self->application_to_class_class; | ||||
| 445 | } | ||||
| 446 | else { | ||||
| 447 | $application_class = $self->application_to_instance_class; | ||||
| 448 | } | ||||
| 449 | |||||
| 450 | 141 | 1.74ms | 141 | 27.8ms | Class::MOP::load_class($application_class); # spent 34.0ms making 141 calls to Class::MOP::load_class, avg 241µs/call, recursion: max depth 3, sum of overlapping time 6.21ms |
| 451 | |||||
| 452 | 141 | 397µs | my $deprecation_check = 0; | ||
| 453 | |||||
| 454 | 141 | 548µs | if ( exists $args{excludes} && !exists $args{'-excludes'} ) { | ||
| 455 | $args{'-excludes'} = delete $args{excludes}; | ||||
| 456 | $deprecation_check = 1; | ||||
| 457 | } | ||||
| 458 | 141 | 387µs | if ( exists $args{alias} && !exists $args{'-alias'} ) { | ||
| 459 | $args{'-alias'} = delete $args{alias}; | ||||
| 460 | $deprecation_check = 1; | ||||
| 461 | } | ||||
| 462 | |||||
| 463 | 141 | 271µs | if ( $deprecation_check ) { | ||
| 464 | Moose::Deprecated::deprecated( | ||||
| 465 | feature => 'alias or excludes', | ||||
| 466 | message => | ||||
| 467 | 'The alias and excludes options for role application'. | ||||
| 468 | ' have been renamed -alias and -excludes'. | ||||
| 469 | " (${\$other->name} is consuming ${\$self->name}". | ||||
| 470 | " - do you need to upgrade ${\$other->name}?)" | ||||
| 471 | ); | ||||
| 472 | } | ||||
| 473 | |||||
| 474 | 141 | 394µs | if ( exists $args{'-excludes'} ) { | ||
| 475 | # I wish we had coercion here :) | ||||
| 476 | $args{'-excludes'} = ( | ||||
| 477 | ref $args{'-excludes'} eq 'ARRAY' | ||||
| 478 | ? $args{'-excludes'} | ||||
| 479 | : [ $args{'-excludes'} ] | ||||
| 480 | ); | ||||
| 481 | } | ||||
| 482 | |||||
| 483 | 141 | 5.71ms | 282 | 1.76s | return $application_class->new(%args)->apply($self, $other, \%args); # spent 1.21s making 73 calls to Moose::Meta::Role::Application::ToClass::apply, avg 16.6ms/call
# spent 530ms making 68 calls to Moose::Meta::Role::Application::ToRole::apply, avg 7.80ms/call
# spent 21.0ms making 141 calls to Moose::Meta::Role::Application::new, avg 149µs/call |
| 484 | } | ||||
| 485 | |||||
| 486 | 8 | 81µs | # spent 50µs within Moose::Meta::Role::composition_class_roles which was called 8 times, avg 6µs/call:
# 8 times (50µs+0s) by Moose::Meta::Role::Composite::new at line 50 of Moose/Meta/Role/Composite.pm, avg 6µs/call | ||
| 487 | |||||
| 488 | # spent 73.4ms (565µs+72.8) within Moose::Meta::Role::combine which was called 3 times, avg 24.5ms/call:
# 3 times (565µs+72.8ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 24.5ms/call | ||||
| 489 | 3 | 17µs | my ($class, @role_specs) = @_; | ||
| 490 | |||||
| 491 | 3 | 12µs | require Moose::Meta::Role::Composite; | ||
| 492 | |||||
| 493 | 3 | 9µs | my (@roles, %role_params); | ||
| 494 | 3 | 26µs | while (@role_specs) { | ||
| 495 | 8 | 36µs | my ($role, $params) = @{ splice @role_specs, 0, 1 }; | ||
| 496 | 8 | 138µs | 8 | 44µs | my $requested_role # spent 44µs making 8 calls to Scalar::Util::blessed, avg 6µs/call |
| 497 | = blessed $role | ||||
| 498 | ? $role | ||||
| 499 | : Class::MOP::class_of($role); | ||||
| 500 | |||||
| 501 | 8 | 82µs | 8 | 86µs | my $actual_role = $requested_role->_role_for_combination($params); # spent 86µs making 8 calls to Moose::Meta::Role::_role_for_combination, avg 11µs/call |
| 502 | 8 | 22µs | push @roles => $actual_role; | ||
| 503 | |||||
| 504 | 8 | 22µs | next unless defined $params; | ||
| 505 | 3 | 87µs | 3 | 24µs | $role_params{$actual_role->name} = $params; # spent 24µs making 3 calls to Class::MOP::Package::name, avg 8µs/call |
| 506 | } | ||||
| 507 | |||||
| 508 | 3 | 57µs | 3 | 2.38ms | my $c = Moose::Meta::Role::Composite->new(roles => \@roles); # spent 2.38ms making 3 calls to Moose::Meta::Role::Composite::new, avg 793µs/call |
| 509 | 3 | 80µs | 3 | 70.3ms | return $c->apply_params(\%role_params); # spent 70.3ms making 3 calls to Moose::Meta::Role::Composite::apply_params, avg 23.4ms/call |
| 510 | } | ||||
| 511 | |||||
| 512 | # spent 86µs within Moose::Meta::Role::_role_for_combination which was called 8 times, avg 11µs/call:
# 8 times (86µs+0s) by Moose::Meta::Role::combine at line 501, avg 11µs/call | ||||
| 513 | 8 | 24µs | my ($self, $params) = @_; | ||
| 514 | 8 | 95µs | return $self; | ||
| 515 | } | ||||
| 516 | |||||
| 517 | # spent 397ms (5.52+392) within Moose::Meta::Role::create which was called 42 times, avg 9.45ms/call:
# 42 times (5.52ms+392ms) by Moose::Meta::Role::create_anon_role at line 607, avg 9.45ms/call | ||||
| 518 | 42 | 320µs | my ( $role, $package_name, %options ) = @_; | ||
| 519 | |||||
| 520 | 42 | 196µs | $options{package} = $package_name; | ||
| 521 | |||||
| 522 | 42 | 111µs | (ref $options{attributes} eq 'HASH') | ||
| 523 | || confess "You must pass a HASH ref of attributes" | ||||
| 524 | if exists $options{attributes}; | ||||
| 525 | |||||
| 526 | 42 | 104µs | (ref $options{methods} eq 'HASH') | ||
| 527 | || confess "You must pass a HASH ref of methods" | ||||
| 528 | if exists $options{methods}; | ||||
| 529 | |||||
| 530 | 42 | 224µs | $options{meta_name} = 'meta' | ||
| 531 | unless exists $options{meta_name}; | ||||
| 532 | |||||
| 533 | 42 | 496µs | my (%initialize_options) = %options; | ||
| 534 | 42 | 288µs | delete @initialize_options{qw( | ||
| 535 | package | ||||
| 536 | attributes | ||||
| 537 | methods | ||||
| 538 | meta_name | ||||
| 539 | version | ||||
| 540 | authority | ||||
| 541 | )}; | ||||
| 542 | |||||
| 543 | 42 | 735µs | 42 | 278ms | my $meta = $role->initialize( $package_name => %initialize_options ); # spent 278ms making 42 calls to Moose::Meta::Role::initialize, avg 6.61ms/call |
| 544 | |||||
| 545 | 42 | 994µs | 42 | 5.68ms | $meta->_instantiate_module( $options{version}, $options{authority} ); # spent 5.68ms making 42 calls to Class::MOP::Module::_instantiate_module, avg 135µs/call |
| 546 | |||||
| 547 | 42 | 771µs | 42 | 108ms | $meta->_add_meta_method($options{meta_name}) # spent 108ms making 42 calls to Class::MOP::Mixin::HasMethods::_add_meta_method, avg 2.58ms/call |
| 548 | if defined $options{meta_name}; | ||||
| 549 | |||||
| 550 | 42 | 204µs | if (exists $options{attributes}) { | ||
| 551 | foreach my $attribute_name (keys %{$options{attributes}}) { | ||||
| 552 | my $attr = $options{attributes}->{$attribute_name}; | ||||
| 553 | $meta->add_attribute( | ||||
| 554 | $attribute_name => blessed $attr ? $attr : %{$attr} ); | ||||
| 555 | } | ||||
| 556 | } | ||||
| 557 | |||||
| 558 | 42 | 101µs | if (exists $options{methods}) { | ||
| 559 | foreach my $method_name (keys %{$options{methods}}) { | ||||
| 560 | $meta->add_method($method_name, $options{methods}->{$method_name}); | ||||
| 561 | } | ||||
| 562 | } | ||||
| 563 | |||||
| 564 | 42 | 865µs | return $meta; | ||
| 565 | } | ||||
| 566 | |||||
| 567 | sub consumers { | ||||
| 568 | my $self = shift; | ||||
| 569 | my @consumers; | ||||
| 570 | for my $meta (Class::MOP::get_all_metaclass_instances) { | ||||
| 571 | next if $meta->name eq $self->name; | ||||
| 572 | next unless $meta->isa('Moose::Meta::Class') | ||||
| 573 | || $meta->isa('Moose::Meta::Role'); | ||||
| 574 | push @consumers, $meta->name | ||||
| 575 | if $meta->does_role($self->name); | ||||
| 576 | } | ||||
| 577 | return @consumers; | ||||
| 578 | } | ||||
| 579 | |||||
| 580 | # anonymous roles. most of it is copied straight out of Class::MOP::Class. | ||||
| 581 | # an intrepid hacker might find great riches if he unifies this code with that | ||||
| 582 | # code in Class::MOP::Module or Class::MOP::Package | ||||
| 583 | { | ||||
| 584 | # NOTE: | ||||
| 585 | # this should be sufficient, if you have a | ||||
| 586 | # use case where it is not, write a test and | ||||
| 587 | # I will change it. | ||||
| 588 | 2 | 7µs | my $ANON_ROLE_SERIAL = 0; | ||
| 589 | |||||
| 590 | # NOTE: | ||||
| 591 | # we need a sufficiently annoying prefix | ||||
| 592 | # this should suffice for now, this is | ||||
| 593 | # used in a couple of places below, so | ||||
| 594 | # need to put it up here for now. | ||||
| 595 | 1 | 4µs | my $ANON_ROLE_PREFIX = 'Moose::Meta::Role::__ANON__::SERIAL::'; | ||
| 596 | |||||
| 597 | sub is_anon_role { | ||||
| 598 | my $self = shift; | ||||
| 599 | 3 | 454µs | 2 | 210µs | # spent 133µs (56+77) within Moose::Meta::Role::BEGIN@599 which was called:
# once (56µs+77µs) by Moose::BEGIN@27 at line 599 # spent 133µs making 1 call to Moose::Meta::Role::BEGIN@599
# spent 77µs making 1 call to warnings::unimport |
| 600 | $self->name =~ /^$ANON_ROLE_PREFIX/; | ||||
| 601 | } | ||||
| 602 | |||||
| 603 | # spent 399ms (2.15+397) within Moose::Meta::Role::create_anon_role which was called 42 times, avg 9.51ms/call:
# 42 times (2.15ms+397ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::generate_role at line 85 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 9.51ms/call | ||||
| 604 | 42 | 372µs | my ($role, %options) = @_; | ||
| 605 | 42 | 231µs | $options{weaken} = 1 unless exists $options{weaken}; | ||
| 606 | 42 | 237µs | my $package_name = $ANON_ROLE_PREFIX . ++$ANON_ROLE_SERIAL; | ||
| 607 | 42 | 1.26ms | 42 | 397ms | return $role->create($package_name, %options); # spent 397ms making 42 calls to Moose::Meta::Role::create, avg 9.45ms/call |
| 608 | } | ||||
| 609 | |||||
| 610 | # NOTE: | ||||
| 611 | # this will only get called for | ||||
| 612 | # anon-roles, all other calls | ||||
| 613 | # are assumed to occur during | ||||
| 614 | # global destruction and so don't | ||||
| 615 | # really need to be handled explicitly | ||||
| 616 | sub DESTROY { | ||||
| 617 | my $self = shift; | ||||
| 618 | |||||
| 619 | return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated | ||||
| 620 | |||||
| 621 | 3 | 233µs | 2 | 165µs | # spent 105µs (45+60) within Moose::Meta::Role::BEGIN@621 which was called:
# once (45µs+60µs) by Moose::BEGIN@27 at line 621 # spent 105µs making 1 call to Moose::Meta::Role::BEGIN@621
# spent 60µs making 1 call to warnings::unimport |
| 622 | return unless $self->name =~ /^$ANON_ROLE_PREFIX/; | ||||
| 623 | |||||
| 624 | # XXX: is this necessary for us? I don't understand what it's doing | ||||
| 625 | # -sartak | ||||
| 626 | |||||
| 627 | # Moose does a weird thing where it replaces the metaclass for | ||||
| 628 | # class when fixing metaclass incompatibility. In that case, | ||||
| 629 | # we don't want to clean out the namespace now. We can detect | ||||
| 630 | # that because Moose will explicitly update the singleton | ||||
| 631 | # cache in Class::MOP. | ||||
| 632 | #my $current_meta = Class::MOP::get_metaclass_by_name($self->name); | ||||
| 633 | #return if $current_meta ne $self; | ||||
| 634 | |||||
| 635 | my ($serial_id) = ($self->name =~ /^$ANON_ROLE_PREFIX(\d+)/); | ||||
| 636 | 3 | 533µs | 2 | 170µs | # spent 104µs (39+65) within Moose::Meta::Role::BEGIN@636 which was called:
# once (39µs+65µs) by Moose::BEGIN@27 at line 636 # spent 104µs making 1 call to Moose::Meta::Role::BEGIN@636
# spent 65µs making 1 call to strict::unimport |
| 637 | foreach my $key (keys %{$ANON_ROLE_PREFIX . $serial_id}) { | ||||
| 638 | delete ${$ANON_ROLE_PREFIX . $serial_id}{$key}; | ||||
| 639 | } | ||||
| 640 | delete ${'main::' . $ANON_ROLE_PREFIX}{$serial_id . '::'}; | ||||
| 641 | } | ||||
| 642 | } | ||||
| 643 | |||||
| 644 | ##################################################################### | ||||
| 645 | ## NOTE: | ||||
| 646 | ## This is Moose::Meta::Role as defined by Moose (plus the use of | ||||
| 647 | ## MooseX::AttributeHelpers module). It is here as a reference to | ||||
| 648 | ## make it easier to see what is happening above with all the meta | ||||
| 649 | ## programming. - SL | ||||
| 650 | ##################################################################### | ||||
| 651 | # | ||||
| 652 | # has 'roles' => ( | ||||
| 653 | # metaclass => 'Array', | ||||
| 654 | # reader => 'get_roles', | ||||
| 655 | # isa => 'ArrayRef[Moose::Meta::Role]', | ||||
| 656 | # default => sub { [] }, | ||||
| 657 | # provides => { | ||||
| 658 | # 'push' => 'add_role', | ||||
| 659 | # } | ||||
| 660 | # ); | ||||
| 661 | # | ||||
| 662 | # has 'excluded_roles_map' => ( | ||||
| 663 | # metaclass => 'Hash', | ||||
| 664 | # reader => 'get_excluded_roles_map', | ||||
| 665 | # isa => 'HashRef[Str]', | ||||
| 666 | # provides => { | ||||
| 667 | # # Not exactly set, cause it sets multiple | ||||
| 668 | # 'set' => 'add_excluded_roles', | ||||
| 669 | # 'keys' => 'get_excluded_roles_list', | ||||
| 670 | # 'exists' => 'excludes_role', | ||||
| 671 | # } | ||||
| 672 | # ); | ||||
| 673 | # | ||||
| 674 | # has 'required_methods' => ( | ||||
| 675 | # metaclass => 'Hash', | ||||
| 676 | # reader => 'get_required_methods_map', | ||||
| 677 | # isa => 'HashRef[Moose::Meta::Role::Method::Required]', | ||||
| 678 | # provides => { | ||||
| 679 | # # not exactly set, or delete since it works for multiple | ||||
| 680 | # 'set' => 'add_required_methods', | ||||
| 681 | # 'delete' => 'remove_required_methods', | ||||
| 682 | # 'keys' => 'get_required_method_list', | ||||
| 683 | # 'exists' => 'requires_method', | ||||
| 684 | # } | ||||
| 685 | # ); | ||||
| 686 | # | ||||
| 687 | # # the before, around and after modifiers are | ||||
| 688 | # # HASH keyed by method-name, with ARRAY of | ||||
| 689 | # # CODE refs to apply in that order | ||||
| 690 | # | ||||
| 691 | # has 'before_method_modifiers' => ( | ||||
| 692 | # metaclass => 'Hash', | ||||
| 693 | # reader => 'get_before_method_modifiers_map', | ||||
| 694 | # isa => 'HashRef[ArrayRef[CodeRef]]', | ||||
| 695 | # provides => { | ||||
| 696 | # 'keys' => 'get_before_method_modifiers', | ||||
| 697 | # 'exists' => 'has_before_method_modifiers', | ||||
| 698 | # # This actually makes sure there is an | ||||
| 699 | # # ARRAY at the given key, and pushed onto | ||||
| 700 | # # it. It also checks for duplicates as well | ||||
| 701 | # # 'add' => 'add_before_method_modifier' | ||||
| 702 | # } | ||||
| 703 | # ); | ||||
| 704 | # | ||||
| 705 | # has 'after_method_modifiers' => ( | ||||
| 706 | # metaclass => 'Hash', | ||||
| 707 | # reader =>'get_after_method_modifiers_map', | ||||
| 708 | # isa => 'HashRef[ArrayRef[CodeRef]]', | ||||
| 709 | # provides => { | ||||
| 710 | # 'keys' => 'get_after_method_modifiers', | ||||
| 711 | # 'exists' => 'has_after_method_modifiers', | ||||
| 712 | # # This actually makes sure there is an | ||||
| 713 | # # ARRAY at the given key, and pushed onto | ||||
| 714 | # # it. It also checks for duplicates as well | ||||
| 715 | # # 'add' => 'add_after_method_modifier' | ||||
| 716 | # } | ||||
| 717 | # ); | ||||
| 718 | # | ||||
| 719 | # has 'around_method_modifiers' => ( | ||||
| 720 | # metaclass => 'Hash', | ||||
| 721 | # reader =>'get_around_method_modifiers_map', | ||||
| 722 | # isa => 'HashRef[ArrayRef[CodeRef]]', | ||||
| 723 | # provides => { | ||||
| 724 | # 'keys' => 'get_around_method_modifiers', | ||||
| 725 | # 'exists' => 'has_around_method_modifiers', | ||||
| 726 | # # This actually makes sure there is an | ||||
| 727 | # # ARRAY at the given key, and pushed onto | ||||
| 728 | # # it. It also checks for duplicates as well | ||||
| 729 | # # 'add' => 'add_around_method_modifier' | ||||
| 730 | # } | ||||
| 731 | # ); | ||||
| 732 | # | ||||
| 733 | # # override is similar to the other modifiers | ||||
| 734 | # # except that it is not an ARRAY of code refs | ||||
| 735 | # # but instead just a single name->code mapping | ||||
| 736 | # | ||||
| 737 | # has 'override_method_modifiers' => ( | ||||
| 738 | # metaclass => 'Hash', | ||||
| 739 | # reader =>'get_override_method_modifiers_map', | ||||
| 740 | # isa => 'HashRef[CodeRef]', | ||||
| 741 | # provides => { | ||||
| 742 | # 'keys' => 'get_override_method_modifier', | ||||
| 743 | # 'exists' => 'has_override_method_modifier', | ||||
| 744 | # 'add' => 'add_override_method_modifier', # checks for local method .. | ||||
| 745 | # } | ||||
| 746 | # ); | ||||
| 747 | # | ||||
| 748 | ##################################################################### | ||||
| 749 | |||||
| 750 | |||||
| 751 | 1 | 132µs | 1; | ||
| 752 | |||||
| 753 | __END__ |