| Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/Role.pm |
| Statements | Executed 2188 statements in 9.68ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 38 | 3 | 3 | 3.88ms | 5.33ms | Moose::Meta::Role::add_attribute |
| 1 | 1 | 1 | 633µs | 2.48ms | Moose::Meta::Role::BEGIN@19 |
| 116 | 6 | 3 | 405µs | 532µs | Moose::Meta::Role::get_method_modifier_list |
| 1 | 1 | 1 | 339µs | 384µs | Moose::Meta::Role::BEGIN@16 |
| 1 | 1 | 1 | 306µs | 1.08ms | Moose::Meta::Role::BEGIN@22 |
| 21 | 2 | 1 | 290µs | 244ms | Moose::Meta::Role::apply (recurses: max depth 1, inclusive time 82.9ms) |
| 1 | 1 | 1 | 258µs | 1.07ms | Moose::Meta::Role::BEGIN@21 |
| 1 | 1 | 1 | 198µs | 288µs | Moose::Meta::Role::BEGIN@20 |
| 18 | 4 | 4 | 177µs | 345µs | Moose::Meta::Role::add_required_methods |
| 39 | 3 | 3 | 167µs | 698µs | Moose::Meta::Role::add_override_method_modifier |
| 19 | 1 | 1 | 157µs | 1.59ms | Moose::Meta::Role::initialize |
| 57 | 3 | 3 | 145µs | 193µs | Moose::Meta::Role::get_override_method_modifier |
| 11 | 1 | 1 | 92µs | 131µs | Moose::Meta::Role::add_role |
| 39 | 2 | 2 | 86µs | 1.38ms | Moose::Meta::Role::find_method_by_name |
| 30 | 1 | 1 | 84µs | 108µs | Moose::Meta::Role::has_override_method_modifier |
| 38 | 1 | 1 | 83µs | 333µs | Moose::Meta::Role::_attach_attribute |
| 8 | 2 | 2 | 76µs | 93µs | Moose::Meta::Role::calculate_all_roles (recurses: max depth 1, inclusive time 36µs) |
| 3 | 1 | 1 | 72µs | 12.8ms | Moose::Meta::Role::combine |
| 66 | 5 | 1 | 53µs | 53µs | Moose::Meta::Role::__ANON__[:308] |
| 44 | 4 | 1 | 32µs | 32µs | Moose::Meta::Role::__ANON__[:91] |
| 2 | 1 | 1 | 23µs | 125µs | Moose::Meta::Role::add_conflicting_method |
| 22 | 2 | 1 | 16µs | 16µs | Moose::Meta::Role::__ANON__[:354] |
| 19 | 1 | 1 | 16µs | 16µs | Moose::Meta::Role::__ANON__[:400] |
| 19 | 1 | 1 | 16µs | 16µs | Moose::Meta::Role::_meta_method_class |
| 8 | 1 | 1 | 9µs | 9µs | Moose::Meta::Role::_role_for_combination |
| 1 | 1 | 1 | 8µs | 8µs | Moose::Meta::Role::BEGIN@2 |
| 1 | 1 | 1 | 7µs | 31µs | Moose::Meta::Role::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 25µs | Moose::Meta::Role::BEGIN@15 |
| 1 | 1 | 1 | 6µs | 24µs | Moose::Meta::Role::BEGIN@14 |
| 1 | 1 | 1 | 6µs | 9µs | Moose::Meta::Role::BEGIN@10 |
| 19 | 1 | 1 | 6µs | 6µs | Moose::Meta::Role::CORE:match (opcode) |
| 1 | 1 | 1 | 6µs | 135µs | Moose::Meta::Role::BEGIN@24 |
| 1 | 1 | 1 | 5µs | 346µs | Moose::Meta::Role::BEGIN@11 |
| 8 | 1 | 1 | 5µs | 5µs | Moose::Meta::Role::composition_class_roles |
| 1 | 1 | 1 | 5µs | 15µs | Moose::Meta::Role::BEGIN@9 |
| 1 | 1 | 1 | 5µs | 130µs | Moose::Meta::Role::BEGIN@27 |
| 1 | 1 | 1 | 4µs | 4µs | Moose::Meta::Role::BEGIN@23 |
| 1 | 1 | 1 | 4µs | 4µs | Moose::Meta::Role::BEGIN@18 |
| 1 | 1 | 1 | 3µs | 3µs | Moose::Meta::Role::BEGIN@25 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:104] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:109] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:114] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:119] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:124] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:318] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:326] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:345] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:583] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:99] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::_anon_cache_key |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::_anon_package_prefix |
| 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::create |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::create_anon_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::does_role |
| 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 | package Moose::Meta::Role; | ||||
| 2 | # spent 8µs within Moose::Meta::Role::BEGIN@2 which was called:
# once (8µs+0s) by Moose::BEGIN@35 at line 4 | ||||
| 3 | 1 | 4µs | $Moose::Meta::Role::AUTHORITY = 'cpan:STEVAN'; | ||
| 4 | 1 | 26µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::Role::BEGIN@2 |
| 5 | { | ||||
| 6 | 2 | 900ns | $Moose::Meta::Role::VERSION = '2.1005'; | ||
| 7 | } | ||||
| 8 | |||||
| 9 | 2 | 20µs | 2 | 25µs | # spent 15µs (5+10) within Moose::Meta::Role::BEGIN@9 which was called:
# once (5µs+10µs) by Moose::BEGIN@35 at line 9 # spent 15µs making 1 call to Moose::Meta::Role::BEGIN@9
# spent 10µs making 1 call to strict::import |
| 10 | 2 | 20µs | 2 | 12µs | # spent 9µs (6+3) within Moose::Meta::Role::BEGIN@10 which was called:
# once (6µs+3µs) by Moose::BEGIN@35 at line 10 # spent 9µs making 1 call to Moose::Meta::Role::BEGIN@10
# spent 3µs making 1 call to warnings::import |
| 11 | 2 | 25µs | 2 | 686µs | # spent 346µs (5+340) within Moose::Meta::Role::BEGIN@11 which was called:
# once (5µs+340µs) by Moose::BEGIN@35 at line 11 # spent 346µs making 1 call to Moose::Meta::Role::BEGIN@11
# spent 340µs making 1 call to metaclass::import |
| 12 | |||||
| 13 | 2 | 22µs | 2 | 55µs | # spent 31µs (7+24) within Moose::Meta::Role::BEGIN@13 which was called:
# once (7µs+24µs) by Moose::BEGIN@35 at line 13 # spent 31µs making 1 call to Moose::Meta::Role::BEGIN@13
# spent 24µs making 1 call to Exporter::import |
| 14 | 2 | 23µs | 2 | 42µs | # spent 24µs (6+18) within Moose::Meta::Role::BEGIN@14 which was called:
# once (6µs+18µs) by Moose::BEGIN@35 at line 14 # spent 24µs making 1 call to Moose::Meta::Role::BEGIN@14
# spent 18µs making 1 call to Exporter::import |
| 15 | 2 | 23µs | 2 | 44µs | # spent 25µs (6+19) within Moose::Meta::Role::BEGIN@15 which was called:
# once (6µs+19µs) by Moose::BEGIN@35 at line 15 # spent 25µs making 1 call to Moose::Meta::Role::BEGIN@15
# spent 19µs making 1 call to Exporter::import |
| 16 | 2 | 26µs | 2 | 412µs | # spent 384µs (339+45) within Moose::Meta::Role::BEGIN@16 which was called:
# once (339µs+45µs) by Moose::BEGIN@35 at line 16 # spent 384µs making 1 call to Moose::Meta::Role::BEGIN@16
# spent 28µs making 1 call to Sub::Exporter::Progressive::__ANON__[Sub/Exporter/Progressive.pm:40] |
| 17 | |||||
| 18 | 2 | 18µs | 1 | 4µs | # spent 4µs within Moose::Meta::Role::BEGIN@18 which was called:
# once (4µs+0s) by Moose::BEGIN@35 at line 18 # spent 4µs making 1 call to Moose::Meta::Role::BEGIN@18 |
| 19 | 2 | 95µs | 1 | 2.48ms | # spent 2.48ms (633µs+1.85) within Moose::Meta::Role::BEGIN@19 which was called:
# once (633µs+1.85ms) by Moose::BEGIN@35 at line 19 # spent 2.48ms making 1 call to Moose::Meta::Role::BEGIN@19 |
| 20 | 2 | 95µs | 1 | 288µs | # spent 288µs (198+90) within Moose::Meta::Role::BEGIN@20 which was called:
# once (198µs+90µs) by Moose::BEGIN@35 at line 20 # spent 288µs making 1 call to Moose::Meta::Role::BEGIN@20 |
| 21 | 2 | 93µs | 1 | 1.07ms | # spent 1.07ms (258µs+814µs) within Moose::Meta::Role::BEGIN@21 which was called:
# once (258µs+814µs) by Moose::BEGIN@35 at line 21 # spent 1.07ms making 1 call to Moose::Meta::Role::BEGIN@21 |
| 22 | 2 | 121µs | 1 | 1.08ms | # spent 1.08ms (306µs+774µs) within Moose::Meta::Role::BEGIN@22 which was called:
# once (306µs+774µs) by Moose::BEGIN@35 at line 22 # spent 1.08ms making 1 call to Moose::Meta::Role::BEGIN@22 |
| 23 | 2 | 22µs | 1 | 4µs | # spent 4µs within Moose::Meta::Role::BEGIN@23 which was called:
# once (4µs+0s) by Moose::BEGIN@35 at line 23 # spent 4µs making 1 call to Moose::Meta::Role::BEGIN@23 |
| 24 | 2 | 23µs | 2 | 264µs | # spent 135µs (6+129) within Moose::Meta::Role::BEGIN@24 which was called:
# once (6µs+129µs) by Moose::BEGIN@35 at line 24 # spent 135µs making 1 call to Moose::Meta::Role::BEGIN@24
# spent 129µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 25 | 2 | 25µs | 1 | 3µs | # spent 3µs within Moose::Meta::Role::BEGIN@25 which was called:
# once (3µs+0s) by Moose::BEGIN@35 at line 25 # spent 3µs making 1 call to Moose::Meta::Role::BEGIN@25 |
| 26 | |||||
| 27 | 1 | 100ns | # spent 130µs (5+125) within Moose::Meta::Role::BEGIN@27 which was called:
# once (5µs+125µs) by Moose::BEGIN@35 at line 29 | ||
| 28 | 'Class::MOP::Mixin::HasAttributes', | ||||
| 29 | 1 | 2.47ms | 2 | 255µs | 'Class::MOP::Mixin::HasMethods'; # spent 130µs making 1 call to Moose::Meta::Role::BEGIN@27
# spent 125µs making 1 call to base::import |
| 30 | |||||
| 31 | 1 | 2µs | 1 | 5.05ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 5.05ms making 1 call to Class::MOP::MiniTrait::apply |
| 32 | |||||
| 33 | ## ------------------------------------------------------------------ | ||||
| 34 | ## NOTE: | ||||
| 35 | ## I normally don't do this, but I am doing | ||||
| 36 | ## a whole bunch of meta-programmin' in this | ||||
| 37 | ## module, so it just makes sense. For a clearer | ||||
| 38 | ## picture of what is going on in the next | ||||
| 39 | ## several lines of code, look at the really | ||||
| 40 | ## big comment at the end of this file (right | ||||
| 41 | ## before the POD). | ||||
| 42 | ## - SL | ||||
| 43 | ## ------------------------------------------------------------------ | ||||
| 44 | |||||
| 45 | 1 | 1µs | 1 | 10µs | my $META = __PACKAGE__->meta; # spent 10µs making 1 call to Moose::Meta::Role::meta |
| 46 | |||||
| 47 | ## ------------------------------------------------------------------ | ||||
| 48 | ## attributes ... | ||||
| 49 | |||||
| 50 | # NOTE: | ||||
| 51 | # since roles are lazy, we hold all the attributes | ||||
| 52 | # of the individual role in 'stasis' until which | ||||
| 53 | # time when it is applied to a class. This means | ||||
| 54 | # keeping a lot of things in hash maps, so we are | ||||
| 55 | # using a little of that meta-programmin' magic | ||||
| 56 | # here and saving lots of extra typin'. And since | ||||
| 57 | # many of these attributes above require similar | ||||
| 58 | # functionality to support them, so we again use | ||||
| 59 | # the wonders of meta-programmin' to deliver a | ||||
| 60 | # very compact solution to this normally verbose | ||||
| 61 | # problem. | ||||
| 62 | # - SL | ||||
| 63 | |||||
| 64 | 1 | 6µs | foreach my $action ( | ||
| 65 | { | ||||
| 66 | name => 'excluded_roles_map', | ||||
| 67 | attr_reader => 'get_excluded_roles_map' , | ||||
| 68 | methods => { | ||||
| 69 | add => 'add_excluded_roles', | ||||
| 70 | get_keys => 'get_excluded_roles_list', | ||||
| 71 | existence => 'excludes_role', | ||||
| 72 | } | ||||
| 73 | }, | ||||
| 74 | { | ||||
| 75 | name => 'required_methods', | ||||
| 76 | attr_reader => 'get_required_methods_map', | ||||
| 77 | methods => { | ||||
| 78 | remove => 'remove_required_methods', | ||||
| 79 | get_values => 'get_required_method_list', | ||||
| 80 | existence => 'requires_method', | ||||
| 81 | } | ||||
| 82 | }, | ||||
| 83 | ) { | ||||
| 84 | |||||
| 85 | 2 | 700ns | my $attr_reader = $action->{attr_reader}; | ||
| 86 | 2 | 200ns | my $methods = $action->{methods}; | ||
| 87 | |||||
| 88 | # create the attribute | ||||
| 89 | $META->add_attribute($action->{name} => ( | ||||
| 90 | reader => $attr_reader, | ||||
| 91 | 44 | 74µs | # spent 32µs within Moose::Meta::Role::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/Role.pm:91] which was called 44 times, avg 730ns/call:
# 19 times (14µs+0s) by Moose::Meta::Role::_new at line 114 of (eval 74)[Eval/Closure.pm:135], avg 763ns/call
# 19 times (14µs+0s) by Moose::Meta::Role::_new at line 84 of (eval 74)[Eval/Closure.pm:135], avg 732ns/call
# 3 times (2µs+0s) by Moose::Meta::Role::Composite::_new at line 90 of (eval 74)[Eval/Closure.pm:135], avg 667ns/call
# 3 times (2µs+0s) by Moose::Meta::Role::Composite::_new at line 123 of (eval 74)[Eval/Closure.pm:135], avg 567ns/call | ||
| 92 | 2 | 6µs | 4 | 538µs | Class::MOP::_definition_context(), # spent 529µs making 2 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 264µs/call
# spent 9µs making 2 calls to Class::MOP::_definition_context, avg 5µs/call |
| 93 | )); | ||||
| 94 | |||||
| 95 | # create some helper methods | ||||
| 96 | $META->add_method($methods->{add} => sub { | ||||
| 97 | 3 | 1µs | my ($self, @values) = @_; | ||
| 98 | 3 | 8µs | $self->$attr_reader->{$_} = undef foreach @values; | ||
| 99 | 2 | 3µs | 1 | 39µs | }) if exists $methods->{add}; # spent 39µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 100 | |||||
| 101 | $META->add_method($methods->{get_keys} => sub { | ||||
| 102 | 29 | 5µs | my ($self) = @_; | ||
| 103 | 29 | 75µs | 29 | 28µs | keys %{$self->$attr_reader}; # spent 28µs making 29 calls to Moose::Meta::Role::get_excluded_roles_map, avg 959ns/call |
| 104 | 2 | 3µs | 1 | 37µs | }) if exists $methods->{get_keys}; # spent 37µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 105 | |||||
| 106 | $META->add_method($methods->{get_values} => sub { | ||||
| 107 | 29 | 4µs | my ($self) = @_; | ||
| 108 | 29 | 79µs | 29 | 28µs | values %{$self->$attr_reader}; # spent 28µs making 29 calls to Moose::Meta::Role::get_required_methods_map, avg 969ns/call |
| 109 | 2 | 3µs | 1 | 38µs | }) if exists $methods->{get_values}; # spent 38µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 110 | |||||
| 111 | $META->add_method($methods->{get} => sub { | ||||
| 112 | my ($self, $name) = @_; | ||||
| 113 | $self->$attr_reader->{$name} | ||||
| 114 | 2 | 400ns | }) if exists $methods->{get}; | ||
| 115 | |||||
| 116 | $META->add_method($methods->{existence} => sub { | ||||
| 117 | 11 | 3µs | my ($self, $name) = @_; | ||
| 118 | 11 | 32µs | 11 | 14µs | exists $self->$attr_reader->{$name} ? 1 : 0; # spent 14µs making 11 calls to Moose::Meta::Role::get_excluded_roles_map, avg 1µs/call |
| 119 | 2 | 5µs | 2 | 71µs | }) if exists $methods->{existence}; # spent 71µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 35µs/call |
| 120 | |||||
| 121 | $META->add_method($methods->{remove} => sub { | ||||
| 122 | my ($self, @values) = @_; | ||||
| 123 | delete $self->$attr_reader->{$_} foreach @values; | ||||
| 124 | 2 | 4µs | 1 | 37µs | }) if exists $methods->{remove}; # spent 37µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 125 | } | ||||
| 126 | |||||
| 127 | $META->add_attribute( | ||||
| 128 | 1 | 2µs | 2 | 247µs | 'method_metaclass', # spent 242µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 129 | reader => 'method_metaclass', | ||||
| 130 | default => 'Moose::Meta::Role::Method', | ||||
| 131 | Class::MOP::_definition_context(), | ||||
| 132 | ); | ||||
| 133 | |||||
| 134 | 1 | 2µs | 2 | 249µs | $META->add_attribute( # spent 244µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 135 | 'required_method_metaclass', | ||||
| 136 | reader => 'required_method_metaclass', | ||||
| 137 | default => 'Moose::Meta::Role::Method::Required', | ||||
| 138 | Class::MOP::_definition_context(), | ||||
| 139 | ); | ||||
| 140 | |||||
| 141 | 1 | 2µs | 2 | 248µs | $META->add_attribute( # spent 244µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 142 | 'conflicting_method_metaclass', | ||||
| 143 | reader => 'conflicting_method_metaclass', | ||||
| 144 | default => 'Moose::Meta::Role::Method::Conflicting', | ||||
| 145 | Class::MOP::_definition_context(), | ||||
| 146 | ); | ||||
| 147 | |||||
| 148 | 1 | 2µs | 2 | 246µs | $META->add_attribute( # spent 242µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 149 | 'application_to_class_class', | ||||
| 150 | reader => 'application_to_class_class', | ||||
| 151 | default => 'Moose::Meta::Role::Application::ToClass', | ||||
| 152 | Class::MOP::_definition_context(), | ||||
| 153 | ); | ||||
| 154 | |||||
| 155 | 1 | 2µs | 2 | 261µs | $META->add_attribute( # spent 256µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 156 | 'application_to_role_class', | ||||
| 157 | reader => 'application_to_role_class', | ||||
| 158 | default => 'Moose::Meta::Role::Application::ToRole', | ||||
| 159 | Class::MOP::_definition_context(), | ||||
| 160 | ); | ||||
| 161 | |||||
| 162 | 1 | 2µs | 2 | 286µs | $META->add_attribute( # spent 281µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 163 | 'application_to_instance_class', | ||||
| 164 | reader => 'application_to_instance_class', | ||||
| 165 | default => 'Moose::Meta::Role::Application::ToInstance', | ||||
| 166 | Class::MOP::_definition_context(), | ||||
| 167 | ); | ||||
| 168 | |||||
| 169 | 1 | 2µs | 2 | 242µs | $META->add_attribute( # spent 237µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 170 | 'applied_attribute_metaclass', | ||||
| 171 | reader => 'applied_attribute_metaclass', | ||||
| 172 | default => 'Moose::Meta::Attribute', | ||||
| 173 | Class::MOP::_definition_context(), | ||||
| 174 | ); | ||||
| 175 | |||||
| 176 | # More or less copied from Moose::Meta::Class | ||||
| 177 | # spent 1.59ms (157µs+1.43) within Moose::Meta::Role::initialize which was called 19 times, avg 83µs/call:
# 19 times (157µs+1.43ms) by Moose::Role::init_meta at line 140 of Moose/Role.pm, avg 83µs/call | ||||
| 178 | 19 | 4µs | my $class = shift; | ||
| 179 | 19 | 9µs | my @args = @_; | ||
| 180 | 19 | 16µs | unshift @args, 'package' if @args % 2; | ||
| 181 | 19 | 12µs | my %opts = @args; | ||
| 182 | 19 | 12µs | my $package = delete $opts{package}; | ||
| 183 | 19 | 72µs | 38 | 1.43ms | return Class::MOP::get_metaclass_by_name($package) # spent 1.42ms making 19 calls to Class::MOP::Package::initialize, avg 75µs/call
# spent 12µs making 19 calls to Class::MOP::get_metaclass_by_name, avg 637ns/call |
| 184 | || $class->SUPER::initialize($package, | ||||
| 185 | 'attribute_metaclass' => 'Moose::Meta::Role::Attribute', | ||||
| 186 | %opts, | ||||
| 187 | ); | ||||
| 188 | } | ||||
| 189 | |||||
| 190 | sub reinitialize { | ||||
| 191 | my $self = shift; | ||||
| 192 | my $pkg = shift; | ||||
| 193 | |||||
| 194 | my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg); | ||||
| 195 | |||||
| 196 | my %existing_classes; | ||||
| 197 | if ($meta) { | ||||
| 198 | %existing_classes = map { $_ => $meta->$_() } qw( | ||||
| 199 | attribute_metaclass | ||||
| 200 | method_metaclass | ||||
| 201 | wrapped_method_metaclass | ||||
| 202 | required_method_metaclass | ||||
| 203 | conflicting_method_metaclass | ||||
| 204 | application_to_class_class | ||||
| 205 | application_to_role_class | ||||
| 206 | application_to_instance_class | ||||
| 207 | applied_attribute_metaclass | ||||
| 208 | ); | ||||
| 209 | } | ||||
| 210 | |||||
| 211 | my %options = @_; | ||||
| 212 | $options{weaken} = Class::MOP::metaclass_is_weak($meta->name) | ||||
| 213 | if !exists $options{weaken} | ||||
| 214 | && blessed($meta) | ||||
| 215 | && $meta->isa('Moose::Meta::Role'); | ||||
| 216 | |||||
| 217 | # don't need to remove generated metaobjects here yet, since we don't | ||||
| 218 | # yet generate anything in roles. this may change in the future though... | ||||
| 219 | # keep an eye on that | ||||
| 220 | my $new_meta = $self->SUPER::reinitialize( | ||||
| 221 | $pkg, | ||||
| 222 | %existing_classes, | ||||
| 223 | %options, | ||||
| 224 | ); | ||||
| 225 | $new_meta->_restore_metaobjects_from($meta) | ||||
| 226 | if $meta && $meta->isa('Moose::Meta::Role'); | ||||
| 227 | return $new_meta; | ||||
| 228 | } | ||||
| 229 | |||||
| 230 | sub _restore_metaobjects_from { | ||||
| 231 | my $self = shift; | ||||
| 232 | my ($old_meta) = @_; | ||||
| 233 | |||||
| 234 | $self->_restore_metamethods_from($old_meta); | ||||
| 235 | $self->_restore_metaattributes_from($old_meta); | ||||
| 236 | |||||
| 237 | for my $role ( @{ $old_meta->get_roles } ) { | ||||
| 238 | $self->add_role($role); | ||||
| 239 | } | ||||
| 240 | } | ||||
| 241 | |||||
| 242 | # spent 5.33ms (3.88+1.45) within Moose::Meta::Role::add_attribute which was called 38 times, avg 140µs/call:
# 19 times (3.76ms+845µs) by Moose::Role::has at line 53 of Moose/Role.pm, avg 242µs/call
# 17 times (107µs+546µs) by Moose::Meta::Role::Application::RoleSummation::apply_attributes at line 151 of Moose/Meta/Role/Application/RoleSummation.pm, avg 38µs/call
# 2 times (14µs+61µs) by Moose::Meta::Role::Application::ToRole::apply_attributes at line 73 of Moose/Meta/Role/Application/ToRole.pm, avg 38µs/call | ||||
| 243 | 38 | 4µs | my $self = shift; | ||
| 244 | |||||
| 245 | 38 | 3.82ms | 114 | 49µs | if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) { # spent 33µs making 76 calls to Scalar::Util::blessed, avg 430ns/call
# spent 10µs making 19 calls to UNIVERSAL::isa, avg 532ns/call
# spent 6µs making 19 calls to Moose::Meta::Role::CORE:match, avg 305ns/call |
| 246 | my $class = ref $_[0]; | ||||
| 247 | Moose->throw_error( "Cannot add a $class as an attribute to a role" ); | ||||
| 248 | } | ||||
| 249 | elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) { | ||||
| 250 | Moose->throw_error( "has '+attr' is not supported in roles" ); | ||||
| 251 | } | ||||
| 252 | |||||
| 253 | 38 | 82µs | 38 | 1.40ms | return $self->SUPER::add_attribute(@_); # spent 1.40ms making 38 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 37µs/call |
| 254 | } | ||||
| 255 | |||||
| 256 | # spent 333µs (83+251) within Moose::Meta::Role::_attach_attribute which was called 38 times, avg 9µs/call:
# 38 times (83µs+251µs) by Class::MOP::Mixin::HasAttributes::add_attribute at line 27 of Class/MOP/Mixin/HasAttributes.pm, avg 9µs/call | ||||
| 257 | 38 | 6µs | my ( $self, $attribute ) = @_; | ||
| 258 | |||||
| 259 | 38 | 66µs | 38 | 251µs | $attribute->attach_to_role($self); # spent 251µs making 38 calls to Moose::Meta::Role::Attribute::attach_to_role, avg 7µs/call |
| 260 | } | ||||
| 261 | |||||
| 262 | # spent 345µs (177+168) within Moose::Meta::Role::add_required_methods which was called 18 times, avg 19µs/call:
# 7 times (54µs+20µs) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 45 of Moose/Meta/Role/Application/ToRole.pm, avg 10µs/call
# 6 times (85µs+134µs) by Moose::Role::requires at line 35 of Moose/Role.pm, avg 37µs/call
# 3 times (22µs+8µs) by Moose::Meta::Role::Application::RoleSummation::check_required_methods at line 112 of Moose/Meta/Role/Application/RoleSummation.pm, avg 10µs/call
# 2 times (16µs+6µs) by Moose::Meta::Role::add_conflicting_method at line 287, avg 11µs/call | ||||
| 263 | 18 | 2µs | my $self = shift; | ||
| 264 | |||||
| 265 | 18 | 36µs | for (@_) { | ||
| 266 | 18 | 3µs | my $method = $_; | ||
| 267 | 18 | 56µs | 30 | 123µs | if (!blessed($method)) { # spent 103µs making 6 calls to Moose::Meta::Role::Method::Required::new, avg 17µs/call
# spent 11µs making 6 calls to Moose::Meta::Role::required_method_metaclass, avg 2µs/call
# spent 9µs making 18 calls to Scalar::Util::blessed, avg 517ns/call |
| 268 | $method = $self->required_method_metaclass->new( | ||||
| 269 | name => $method, | ||||
| 270 | ); | ||||
| 271 | } | ||||
| 272 | 18 | 52µs | 36 | 45µs | $self->get_required_methods_map->{$method->name} = $method; # spent 24µs making 18 calls to Moose::Meta::Role::Method::Required::name, avg 1µs/call
# spent 21µs making 18 calls to Moose::Meta::Role::get_required_methods_map, avg 1µs/call |
| 273 | } | ||||
| 274 | } | ||||
| 275 | |||||
| 276 | # spent 125µs (23+102) within Moose::Meta::Role::add_conflicting_method which was called 2 times, avg 63µs/call:
# 2 times (23µs+102µs) by Moose::Meta::Role::Application::RoleSummation::apply_methods at line 190 of Moose/Meta/Role/Application/RoleSummation.pm, avg 63µs/call | ||||
| 277 | 2 | 400ns | my $self = shift; | ||
| 278 | |||||
| 279 | 2 | 100ns | my $method; | ||
| 280 | 2 | 1µs | if (@_ == 1 && blessed($_[0])) { | ||
| 281 | $method = shift; | ||||
| 282 | } | ||||
| 283 | else { | ||||
| 284 | 2 | 10µs | 4 | 80µs | $method = $self->conflicting_method_metaclass->new(@_); # spent 76µs making 2 calls to Moose::Meta::Role::Method::Required::new, avg 38µs/call
# spent 4µs making 2 calls to Moose::Meta::Role::conflicting_method_metaclass, avg 2µs/call |
| 285 | } | ||||
| 286 | |||||
| 287 | 2 | 5µs | 2 | 22µs | $self->add_required_methods($method); # spent 22µs making 2 calls to Moose::Meta::Role::add_required_methods, avg 11µs/call |
| 288 | } | ||||
| 289 | |||||
| 290 | ## ------------------------------------------------------------------ | ||||
| 291 | ## method modifiers | ||||
| 292 | |||||
| 293 | # NOTE: | ||||
| 294 | # the before/around/after method modifiers are | ||||
| 295 | # stored by name, but there can be many methods | ||||
| 296 | # then associated with that name. So again we have | ||||
| 297 | # lots of similar functionality, so we can do some | ||||
| 298 | # meta-programmin' and save some time. | ||||
| 299 | # - SL | ||||
| 300 | |||||
| 301 | 1 | 500ns | foreach my $modifier_type (qw[ before around after ]) { | ||
| 302 | |||||
| 303 | 3 | 2µs | my $attr_reader = "get_${modifier_type}_method_modifiers_map"; | ||
| 304 | |||||
| 305 | # create the attribute ... | ||||
| 306 | $META->add_attribute("${modifier_type}_method_modifiers" => ( | ||||
| 307 | reader => $attr_reader, | ||||
| 308 | 66 | 104µs | # spent 53µs within Moose::Meta::Role::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/Role.pm:308] which was called 66 times, avg 797ns/call:
# 22 times (21µs+0s) by Moose::Meta::Role::Composite::_new or Moose::Meta::Role::_new at line 21 of (eval 74)[Eval/Closure.pm:135], avg 950ns/call
# 19 times (14µs+0s) by Moose::Meta::Role::_new at line 51 of (eval 74)[Eval/Closure.pm:135], avg 763ns/call
# 19 times (13µs+0s) by Moose::Meta::Role::_new at line 72 of (eval 74)[Eval/Closure.pm:135], avg 695ns/call
# 3 times (2µs+0s) by Moose::Meta::Role::Composite::_new at line 78 of (eval 74)[Eval/Closure.pm:135], avg 733ns/call
# 3 times (2µs+0s) by Moose::Meta::Role::Composite::_new at line 57 of (eval 74)[Eval/Closure.pm:135], avg 600ns/call | ||
| 309 | 3 | 9µs | 6 | 762µs | Class::MOP::_definition_context(), # spent 749µs making 3 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 250µs/call
# spent 13µs making 3 calls to Class::MOP::_definition_context, avg 4µs/call |
| 310 | )); | ||||
| 311 | |||||
| 312 | # and some helper methods ... | ||||
| 313 | $META->add_method("get_${modifier_type}_method_modifiers" => sub { | ||||
| 314 | 59 | 12µs | my ($self, $method_name) = @_; | ||
| 315 | #return () unless exists $self->$attr_reader->{$method_name}; | ||||
| 316 | 59 | 50µs | 59 | 52µs | my $mm = $self->$attr_reader->{$method_name}; # spent 44µs making 53 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 834ns/call
# spent 6µs making 4 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 1µs/call
# spent 2µs making 2 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 850ns/call |
| 317 | 59 | 109µs | $mm ? @$mm : (); | ||
| 318 | 3 | 8µs | 3 | 112µs | }); # spent 112µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 37µs/call |
| 319 | |||||
| 320 | $META->add_method("has_${modifier_type}_method_modifiers" => sub { | ||||
| 321 | my ($self, $method_name) = @_; | ||||
| 322 | # NOTE: | ||||
| 323 | # for now we assume that if it exists,.. | ||||
| 324 | # it has at least one modifier in it | ||||
| 325 | (exists $self->$attr_reader->{$method_name}) ? 1 : 0; | ||||
| 326 | 3 | 8µs | 3 | 111µs | }); # spent 111µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 37µs/call |
| 327 | |||||
| 328 | $META->add_method("add_${modifier_type}_method_modifier" => sub { | ||||
| 329 | 44 | 11µs | my ($self, $method_name, $method) = @_; | ||
| 330 | |||||
| 331 | 44 | 90µs | 88 | 74µs | $self->$attr_reader->{$method_name} = [] # spent 63µs making 76 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 832ns/call
# spent 8µs making 8 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 950ns/call
# spent 4µs making 4 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 900ns/call |
| 332 | unless exists $self->$attr_reader->{$method_name}; | ||||
| 333 | |||||
| 334 | 44 | 38µs | 44 | 35µs | my $modifiers = $self->$attr_reader->{$method_name}; # spent 30µs making 38 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 792ns/call
# spent 3µs making 4 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 850ns/call
# spent 2µs making 2 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 800ns/call |
| 335 | |||||
| 336 | # NOTE: | ||||
| 337 | # check to see that we aren't adding the | ||||
| 338 | # same code twice. We err in favor of the | ||||
| 339 | # first on here, this may not be as expected | ||||
| 340 | 44 | 15µs | foreach my $modifier (@{$modifiers}) { | ||
| 341 | return if $modifier == $method; | ||||
| 342 | } | ||||
| 343 | |||||
| 344 | 44 | 78µs | push @{$modifiers} => $method; | ||
| 345 | 3 | 9µs | 3 | 106µs | }); # spent 106µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 35µs/call |
| 346 | |||||
| 347 | } | ||||
| 348 | |||||
| 349 | ## ------------------------------------------------------------------ | ||||
| 350 | ## override method modifiers | ||||
| 351 | |||||
| 352 | $META->add_attribute('override_method_modifiers' => ( | ||||
| 353 | reader => 'get_override_method_modifiers_map', | ||||
| 354 | 22 | 35µs | # spent 16µs within Moose::Meta::Role::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/Role.pm:354] which was called 22 times, avg 718ns/call:
# 19 times (14µs+0s) by Moose::Meta::Role::_new at line 99 of (eval 74)[Eval/Closure.pm:135], avg 737ns/call
# 3 times (2µs+0s) by Moose::Meta::Role::Composite::_new at line 108 of (eval 74)[Eval/Closure.pm:135], avg 600ns/call | ||
| 355 | 1 | 3µs | 2 | 285µs | Class::MOP::_definition_context(), # spent 280µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 356 | )); | ||||
| 357 | |||||
| 358 | # NOTE: | ||||
| 359 | # these are a little different because there | ||||
| 360 | # can only be one per name, whereas the other | ||||
| 361 | # method modifiers can have multiples. | ||||
| 362 | # - SL | ||||
| 363 | |||||
| 364 | # spent 698µs (167+531) within Moose::Meta::Role::add_override_method_modifier which was called 39 times, avg 18µs/call:
# 30 times (123µs+445µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 162 of Moose/Meta/Role/Application/ToRole.pm, avg 19µs/call
# 6 times (27µs+22µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 242 of Moose/Meta/Role/Application/RoleSummation.pm, avg 8µs/call
# 3 times (18µs+64µs) by Moose::Role::override at line 83 of Moose/Role.pm, avg 27µs/call | ||||
| 365 | 39 | 9µs | my ($self, $method_name, $method) = @_; | ||
| 366 | 39 | 18µs | 39 | 493µs | (!$self->has_method($method_name)) # spent 475µs making 33 calls to Class::MOP::Mixin::HasMethods::has_method, avg 14µs/call
# spent 18µs making 6 calls to Moose::Meta::Role::Composite::has_method, avg 3µs/call |
| 367 | || Moose->throw_error("Cannot add an override of method '$method_name' " . | ||||
| 368 | "because there is a local version of '$method_name'"); | ||||
| 369 | 39 | 104µs | 39 | 38µs | $self->get_override_method_modifiers_map->{$method_name} = $method; # spent 38µs making 39 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 985ns/call |
| 370 | } | ||||
| 371 | |||||
| 372 | # spent 108µs (84+25) within Moose::Meta::Role::has_override_method_modifier which was called 30 times, avg 4µs/call:
# 30 times (84µs+25µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 151 of Moose/Meta/Role/Application/ToRole.pm, avg 4µs/call | ||||
| 373 | 30 | 6µs | my ($self, $method_name) = @_; | ||
| 374 | # NOTE: | ||||
| 375 | # for now we assume that if it exists,.. | ||||
| 376 | # it has at least one modifier in it | ||||
| 377 | 30 | 61µs | 30 | 25µs | (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0; # spent 25µs making 30 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 823ns/call |
| 378 | } | ||||
| 379 | |||||
| 380 | # spent 193µs (145+48) within Moose::Meta::Role::get_override_method_modifier which was called 57 times, avg 3µs/call:
# 30 times (71µs+22µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 162 of Moose/Meta/Role/Application/ToRole.pm, avg 3µs/call
# 21 times (60µs+21µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 215 of Moose/Meta/Role/Application/ToClass.pm, avg 4µs/call
# 6 times (14µs+5µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 213 of Moose/Meta/Role/Application/RoleSummation.pm, avg 3µs/call | ||||
| 381 | 57 | 10µs | my ($self, $method_name) = @_; | ||
| 382 | 57 | 113µs | 57 | 48µs | $self->get_override_method_modifiers_map->{$method_name}; # spent 48µs making 57 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 842ns/call |
| 383 | } | ||||
| 384 | |||||
| 385 | ## general list accessor ... | ||||
| 386 | |||||
| 387 | # spent 532µs (405+127) within Moose::Meta::Role::get_method_modifier_list which was called 116 times, avg 5µs/call:
# 33 times (106µs+35µs) by Moose::Meta::Role::Application::ToRole::apply_method_modifiers at line 175 of Moose/Meta/Role/Application/ToRole.pm, avg 4µs/call
# 30 times (109µs+36µs) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 227 of Moose/Meta/Role/Application/ToClass.pm, avg 5µs/call
# 24 times (72µs+23µs) by Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers at line 251 of Moose/Meta/Role/Application/RoleSummation.pm, avg 4µs/call
# 11 times (46µs+12µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 135 of Moose/Meta/Role/Application/ToRole.pm, avg 5µs/call
# 10 times (44µs+13µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 205 of Moose/Meta/Role/Application/ToClass.pm, avg 6µs/call
# 8 times (28µs+8µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 214 of Moose/Meta/Role/Application/RoleSummation.pm, avg 5µs/call | ||||
| 388 | 116 | 16µs | my ($self, $modifier_type) = @_; | ||
| 389 | 116 | 28µs | my $accessor = "get_${modifier_type}_method_modifiers_map"; | ||
| 390 | 116 | 311µs | 116 | 127µs | keys %{$self->$accessor}; # spent 33µs making 29 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 1µs/call
# spent 32µs making 29 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 1µs/call
# spent 32µs making 29 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 1µs/call
# spent 30µs making 29 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 1µs/call |
| 391 | } | ||||
| 392 | |||||
| 393 | 19 | 26µs | # spent 16µs within Moose::Meta::Role::_meta_method_class which was called 19 times, avg 826ns/call:
# 19 times (16µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 33 of Class/MOP/Mixin/HasMethods.pm, avg 826ns/call | ||
| 394 | |||||
| 395 | ## ------------------------------------------------------------------ | ||||
| 396 | ## subroles | ||||
| 397 | |||||
| 398 | $META->add_attribute('roles' => ( | ||||
| 399 | reader => 'get_roles', | ||||
| 400 | 19 | 30µs | # spent 16µs within Moose::Meta::Role::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/Role.pm:400] which was called 19 times, avg 832ns/call:
# 19 times (16µs+0s) by Moose::Meta::Role::_new at line 120 of (eval 74)[Eval/Closure.pm:135], avg 832ns/call | ||
| 401 | 1 | 3µs | 2 | 251µs | Class::MOP::_definition_context(), # spent 246µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 402 | )); | ||||
| 403 | |||||
| 404 | # spent 131µs (92+39) within Moose::Meta::Role::add_role which was called 11 times, avg 12µs/call:
# 11 times (92µs+39µs) by Moose::Meta::Role::Application::ToRole::apply at line 20 of Moose/Meta/Role/Application/ToRole.pm, avg 12µs/call | ||||
| 405 | 11 | 2µs | my ($self, $role) = @_; | ||
| 406 | 11 | 44µs | 22 | 14µs | (blessed($role) && $role->isa('Moose::Meta::Role')) # spent 7µs making 11 calls to Scalar::Util::blessed, avg 636ns/call
# spent 6µs making 11 calls to UNIVERSAL::isa, avg 591ns/call |
| 407 | || Moose->throw_error("Roles must be instances of Moose::Meta::Role"); | ||||
| 408 | 11 | 14µs | 11 | 13µs | push @{$self->get_roles} => $role; # spent 13µs making 11 calls to Moose::Meta::Role::get_roles, avg 1µs/call |
| 409 | 11 | 32µs | 11 | 12µs | $self->reset_package_cache_flag; # spent 12µs making 11 calls to Class::MOP::Mixin::HasMethods::reset_package_cache_flag, avg 1µs/call |
| 410 | } | ||||
| 411 | |||||
| 412 | # spent 93µs (76+16) within Moose::Meta::Role::calculate_all_roles which was called 8 times, avg 12µs/call:
# 4 times (46µs+47µs) by Moose::Meta::Class::calculate_all_roles at line 218 of Moose/Meta/Class.pm, avg 23µs/call
# 4 times (30µs+-30µs) by Moose::Meta::Role::calculate_all_roles at line 416, avg 0s/call | ||||
| 413 | 8 | 2µs | my $self = shift; | ||
| 414 | 8 | 500ns | my %seen; | ||
| 415 | 12 | 32µs | 12 | 6µs | grep { # spent 6µs making 12 calls to Class::MOP::Package::name, avg 525ns/call |
| 416 | 4 | 7µs | 4 | 0s | !$seen{$_->name}++ # spent 36µs making 4 calls to Moose::Meta::Role::calculate_all_roles, avg 9µs/call, recursion: max depth 1, sum of overlapping time 36µs |
| 417 | } ($self, map { | ||||
| 418 | $_->calculate_all_roles | ||||
| 419 | 8 | 31µs | 8 | 10µs | } @{ $self->get_roles }); # spent 10µs making 8 calls to Moose::Meta::Role::get_roles, avg 1µs/call |
| 420 | } | ||||
| 421 | |||||
| 422 | sub does_role { | ||||
| 423 | my ($self, $role) = @_; | ||||
| 424 | (defined $role) | ||||
| 425 | || Moose->throw_error("You must supply a role name to look for"); | ||||
| 426 | my $role_name = blessed $role ? $role->name : $role; | ||||
| 427 | # if we are it,.. then return true | ||||
| 428 | return 1 if $role_name eq $self->name; | ||||
| 429 | # otherwise.. check our children | ||||
| 430 | foreach my $role (@{$self->get_roles}) { | ||||
| 431 | return 1 if $role->does_role($role_name); | ||||
| 432 | } | ||||
| 433 | return 0; | ||||
| 434 | } | ||||
| 435 | |||||
| 436 | 39 | 70µs | 39 | 1.30ms | # spent 1.38ms (86µs+1.30) within Moose::Meta::Role::find_method_by_name which was called 39 times, avg 35µs/call:
# 20 times (42µs+1.01ms) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 45 of Moose/Meta/Role/Application/ToRole.pm, avg 53µs/call
# 19 times (44µs+286µs) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 28 of Class/MOP/Mixin/HasMethods.pm, avg 17µs/call # spent 1.30ms making 39 calls to Class::MOP::Mixin::HasMethods::get_method, avg 33µs/call |
| 437 | |||||
| 438 | ## ------------------------------------------------------------------ | ||||
| 439 | ## role construction | ||||
| 440 | ## ------------------------------------------------------------------ | ||||
| 441 | |||||
| 442 | # spent 244ms (290µs+243) within Moose::Meta::Role::apply which was called 21 times, avg 11.6ms/call:
# 18 times (246µs+9.51ms) by Moose::Util::_apply_all_roles at line 160 of Moose/Util.pm, avg 542µs/call
# 3 times (44µs+234ms) by Moose::Util::_apply_all_roles at line 163 of Moose/Util.pm, avg 78.0ms/call | ||||
| 443 | 21 | 9µs | my ($self, $other, %args) = @_; | ||
| 444 | |||||
| 445 | 21 | 40µs | 21 | 10µs | (blessed($other)) # spent 10µs making 21 calls to Scalar::Util::blessed, avg 486ns/call |
| 446 | || Moose->throw_error("You must pass in an blessed instance"); | ||||
| 447 | |||||
| 448 | 21 | 2µs | my $application_class; | ||
| 449 | 21 | 93µs | 52 | 61µs | if ($other->isa('Moose::Meta::Role')) { # spent 21µs making 31 calls to UNIVERSAL::isa, avg 684ns/call
# spent 20µs making 10 calls to Moose::Meta::Role::application_to_class_class, avg 2µs/call
# spent 20µs making 11 calls to Moose::Meta::Role::application_to_role_class, avg 2µs/call |
| 450 | $application_class = $self->application_to_role_class; | ||||
| 451 | } | ||||
| 452 | elsif ($other->isa('Moose::Meta::Class')) { | ||||
| 453 | $application_class = $self->application_to_class_class; | ||||
| 454 | } | ||||
| 455 | else { | ||||
| 456 | $application_class = $self->application_to_instance_class; | ||||
| 457 | } | ||||
| 458 | |||||
| 459 | 21 | 14µs | 21 | 184µs | load_class($application_class); # spent 400µs making 21 calls to Class::Load::load_class, avg 19µs/call, recursion: max depth 3, sum of overlapping time 216µs |
| 460 | |||||
| 461 | 21 | 6µs | if ( exists $args{'-excludes'} ) { | ||
| 462 | # I wish we had coercion here :) | ||||
| 463 | $args{'-excludes'} = ( | ||||
| 464 | ref $args{'-excludes'} eq 'ARRAY' | ||||
| 465 | ? $args{'-excludes'} | ||||
| 466 | : [ $args{'-excludes'} ] | ||||
| 467 | ); | ||||
| 468 | } | ||||
| 469 | |||||
| 470 | 21 | 103µs | 42 | 281ms | return $application_class->new(%args)->apply($self, $other, \%args); # spent 285ms making 10 calls to Moose::Meta::Role::Application::ToClass::apply, avg 28.5ms/call, recursion: max depth 1, sum of overlapping time 45.1ms
# spent 40.5ms making 11 calls to Moose::Meta::Role::Application::ToRole::apply, avg 3.68ms/call
# spent 386µs making 21 calls to Moose::Meta::Role::Application::new, avg 18µs/call |
| 471 | } | ||||
| 472 | |||||
| 473 | 8 | 11µs | # spent 5µs within Moose::Meta::Role::composition_class_roles which was called 8 times, avg 662ns/call:
# 8 times (5µs+0s) by Moose::Meta::Role::Composite::new at line 58 of Moose/Meta/Role/Composite.pm, avg 662ns/call | ||
| 474 | |||||
| 475 | # spent 12.8ms (72µs+12.7) within Moose::Meta::Role::combine which was called 3 times, avg 4.26ms/call:
# 3 times (72µs+12.7ms) by Moose::Util::_apply_all_roles at line 163 of Moose/Util.pm, avg 4.26ms/call | ||||
| 476 | 3 | 2µs | my ($class, @role_specs) = @_; | ||
| 477 | |||||
| 478 | 3 | 2µs | require Moose::Meta::Role::Composite; | ||
| 479 | |||||
| 480 | 3 | 300ns | my (@roles, %role_params); | ||
| 481 | 3 | 2µs | while (@role_specs) { | ||
| 482 | 8 | 4µs | my ($role, $params) = @{ splice @role_specs, 0, 1 }; | ||
| 483 | 8 | 17µs | 8 | 4µs | my $requested_role # spent 4µs making 8 calls to Scalar::Util::blessed, avg 562ns/call |
| 484 | = blessed $role | ||||
| 485 | ? $role | ||||
| 486 | : Class::MOP::class_of($role); | ||||
| 487 | |||||
| 488 | 8 | 9µs | 8 | 9µs | my $actual_role = $requested_role->_role_for_combination($params); # spent 9µs making 8 calls to Moose::Meta::Role::_role_for_combination, avg 1µs/call |
| 489 | 8 | 2µs | push @roles => $actual_role; | ||
| 490 | |||||
| 491 | 8 | 3µs | next unless defined $params; | ||
| 492 | $role_params{$actual_role->name} = $params; | ||||
| 493 | } | ||||
| 494 | |||||
| 495 | 3 | 10µs | 3 | 322µs | my $c = Moose::Meta::Role::Composite->new(roles => \@roles); # spent 322µs making 3 calls to Moose::Meta::Role::Composite::new, avg 107µs/call |
| 496 | 3 | 11µs | 3 | 12.4ms | return $c->apply_params(\%role_params); # spent 12.4ms making 3 calls to Moose::Meta::Role::Composite::apply_params, avg 4.13ms/call |
| 497 | } | ||||
| 498 | |||||
| 499 | # spent 9µs within Moose::Meta::Role::_role_for_combination which was called 8 times, avg 1µs/call:
# 8 times (9µs+0s) by Moose::Meta::Role::combine at line 488, avg 1µs/call | ||||
| 500 | 8 | 1µs | my ($self, $params) = @_; | ||
| 501 | 8 | 12µs | return $self; | ||
| 502 | } | ||||
| 503 | |||||
| 504 | sub create { | ||||
| 505 | my $class = shift; | ||||
| 506 | my @args = @_; | ||||
| 507 | |||||
| 508 | unshift @args, 'package' if @args % 2 == 1; | ||||
| 509 | my %options = @args; | ||||
| 510 | |||||
| 511 | (ref $options{attributes} eq 'HASH') | ||||
| 512 | || confess "You must pass a HASH ref of attributes" | ||||
| 513 | if exists $options{attributes}; | ||||
| 514 | |||||
| 515 | (ref $options{methods} eq 'HASH') | ||||
| 516 | || confess "You must pass a HASH ref of methods" | ||||
| 517 | if exists $options{methods}; | ||||
| 518 | |||||
| 519 | (ref $options{roles} eq 'ARRAY') | ||||
| 520 | || confess "You must pass an ARRAY ref of roles" | ||||
| 521 | if exists $options{roles}; | ||||
| 522 | |||||
| 523 | my $package = delete $options{package}; | ||||
| 524 | my $roles = delete $options{roles}; | ||||
| 525 | my $attributes = delete $options{attributes}; | ||||
| 526 | my $methods = delete $options{methods}; | ||||
| 527 | my $meta_name = exists $options{meta_name} | ||||
| 528 | ? delete $options{meta_name} | ||||
| 529 | : 'meta'; | ||||
| 530 | |||||
| 531 | my $meta = $class->SUPER::create($package => %options); | ||||
| 532 | |||||
| 533 | $meta->_add_meta_method($meta_name) | ||||
| 534 | if defined $meta_name; | ||||
| 535 | |||||
| 536 | if (defined $attributes) { | ||||
| 537 | foreach my $attribute_name (keys %{$attributes}) { | ||||
| 538 | my $attr = $attributes->{$attribute_name}; | ||||
| 539 | $meta->add_attribute( | ||||
| 540 | $attribute_name => blessed $attr ? $attr : %{$attr} ); | ||||
| 541 | } | ||||
| 542 | } | ||||
| 543 | |||||
| 544 | if (defined $methods) { | ||||
| 545 | foreach my $method_name (keys %{$methods}) { | ||||
| 546 | $meta->add_method($method_name, $methods->{$method_name}); | ||||
| 547 | } | ||||
| 548 | } | ||||
| 549 | |||||
| 550 | if ($roles) { | ||||
| 551 | Moose::Util::apply_all_roles($meta, @$roles); | ||||
| 552 | } | ||||
| 553 | |||||
| 554 | return $meta; | ||||
| 555 | } | ||||
| 556 | |||||
| 557 | sub consumers { | ||||
| 558 | my $self = shift; | ||||
| 559 | my @consumers; | ||||
| 560 | for my $meta (Class::MOP::get_all_metaclass_instances) { | ||||
| 561 | next if $meta->name eq $self->name; | ||||
| 562 | next unless $meta->isa('Moose::Meta::Class') | ||||
| 563 | || $meta->isa('Moose::Meta::Role'); | ||||
| 564 | push @consumers, $meta->name | ||||
| 565 | if $meta->does_role($self->name); | ||||
| 566 | } | ||||
| 567 | return @consumers; | ||||
| 568 | } | ||||
| 569 | |||||
| 570 | # XXX: something more intelligent here? | ||||
| 571 | sub _anon_package_prefix { 'Moose::Meta::Role::__ANON__::SERIAL::' } | ||||
| 572 | |||||
| 573 | sub create_anon_role { shift->create_anon(@_) } | ||||
| 574 | sub is_anon_role { shift->is_anon(@_) } | ||||
| 575 | |||||
| 576 | sub _anon_cache_key { | ||||
| 577 | my $class = shift; | ||||
| 578 | my %options = @_; | ||||
| 579 | |||||
| 580 | # XXX fix this duplication (see MMC::_anon_cache_key | ||||
| 581 | my $roles = Data::OptList::mkopt(($options{roles} || []), { | ||||
| 582 | moniker => 'role', | ||||
| 583 | val_test => sub { ref($_[0]) eq 'HASH' }, | ||||
| 584 | }); | ||||
| 585 | |||||
| 586 | my @role_keys; | ||||
| 587 | for my $role_spec (@$roles) { | ||||
| 588 | my ($role, $params) = @$role_spec; | ||||
| 589 | $params = { %$params }; | ||||
| 590 | |||||
| 591 | my $key = blessed($role) ? $role->name : $role; | ||||
| 592 | |||||
| 593 | if ($params && %$params) { | ||||
| 594 | my $alias = delete $params->{'-alias'} | ||||
| 595 | || delete $params->{'alias'} | ||||
| 596 | || {}; | ||||
| 597 | my $excludes = delete $params->{'-excludes'} | ||||
| 598 | || delete $params->{'excludes'} | ||||
| 599 | || []; | ||||
| 600 | $excludes = [$excludes] unless ref($excludes) eq 'ARRAY'; | ||||
| 601 | |||||
| 602 | if (%$params) { | ||||
| 603 | warn "Roles with parameters cannot be cached. Consider " | ||||
| 604 | . "applying the parameters before calling " | ||||
| 605 | . "create_anon_class, or using 'weaken => 0' instead"; | ||||
| 606 | return; | ||||
| 607 | } | ||||
| 608 | |||||
| 609 | my $alias_key = join('%', | ||||
| 610 | map { $_ => $alias->{$_} } sort keys %$alias | ||||
| 611 | ); | ||||
| 612 | my $excludes_key = join('%', | ||||
| 613 | sort @$excludes | ||||
| 614 | ); | ||||
| 615 | $key .= '<' . join('+', 'a', $alias_key, 'e', $excludes_key) . '>'; | ||||
| 616 | } | ||||
| 617 | |||||
| 618 | push @role_keys, $key; | ||||
| 619 | } | ||||
| 620 | |||||
| 621 | # Makes something like Role|Role::1 | ||||
| 622 | return join('|', sort @role_keys); | ||||
| 623 | } | ||||
| 624 | |||||
| 625 | ##################################################################### | ||||
| 626 | ## NOTE: | ||||
| 627 | ## This is Moose::Meta::Role as defined by Moose (plus the use of | ||||
| 628 | ## MooseX::AttributeHelpers module). It is here as a reference to | ||||
| 629 | ## make it easier to see what is happening above with all the meta | ||||
| 630 | ## programming. - SL | ||||
| 631 | ##################################################################### | ||||
| 632 | # | ||||
| 633 | # has 'roles' => ( | ||||
| 634 | # metaclass => 'Array', | ||||
| 635 | # reader => 'get_roles', | ||||
| 636 | # isa => 'ArrayRef[Moose::Meta::Role]', | ||||
| 637 | # default => sub { [] }, | ||||
| 638 | # provides => { | ||||
| 639 | # 'push' => 'add_role', | ||||
| 640 | # } | ||||
| 641 | # ); | ||||
| 642 | # | ||||
| 643 | # has 'excluded_roles_map' => ( | ||||
| 644 | # metaclass => 'Hash', | ||||
| 645 | # reader => 'get_excluded_roles_map', | ||||
| 646 | # isa => 'HashRef[Str]', | ||||
| 647 | # provides => { | ||||
| 648 | # # Not exactly set, cause it sets multiple | ||||
| 649 | # 'set' => 'add_excluded_roles', | ||||
| 650 | # 'keys' => 'get_excluded_roles_list', | ||||
| 651 | # 'exists' => 'excludes_role', | ||||
| 652 | # } | ||||
| 653 | # ); | ||||
| 654 | # | ||||
| 655 | # has 'required_methods' => ( | ||||
| 656 | # metaclass => 'Hash', | ||||
| 657 | # reader => 'get_required_methods_map', | ||||
| 658 | # isa => 'HashRef[Moose::Meta::Role::Method::Required]', | ||||
| 659 | # provides => { | ||||
| 660 | # # not exactly set, or delete since it works for multiple | ||||
| 661 | # 'set' => 'add_required_methods', | ||||
| 662 | # 'delete' => 'remove_required_methods', | ||||
| 663 | # 'keys' => 'get_required_method_list', | ||||
| 664 | # 'exists' => 'requires_method', | ||||
| 665 | # } | ||||
| 666 | # ); | ||||
| 667 | # | ||||
| 668 | # # the before, around and after modifiers are | ||||
| 669 | # # HASH keyed by method-name, with ARRAY of | ||||
| 670 | # # CODE refs to apply in that order | ||||
| 671 | # | ||||
| 672 | # has 'before_method_modifiers' => ( | ||||
| 673 | # metaclass => 'Hash', | ||||
| 674 | # reader => 'get_before_method_modifiers_map', | ||||
| 675 | # isa => 'HashRef[ArrayRef[CodeRef]]', | ||||
| 676 | # provides => { | ||||
| 677 | # 'keys' => 'get_before_method_modifiers', | ||||
| 678 | # 'exists' => 'has_before_method_modifiers', | ||||
| 679 | # # This actually makes sure there is an | ||||
| 680 | # # ARRAY at the given key, and pushed onto | ||||
| 681 | # # it. It also checks for duplicates as well | ||||
| 682 | # # 'add' => 'add_before_method_modifier' | ||||
| 683 | # } | ||||
| 684 | # ); | ||||
| 685 | # | ||||
| 686 | # has 'after_method_modifiers' => ( | ||||
| 687 | # metaclass => 'Hash', | ||||
| 688 | # reader =>'get_after_method_modifiers_map', | ||||
| 689 | # isa => 'HashRef[ArrayRef[CodeRef]]', | ||||
| 690 | # provides => { | ||||
| 691 | # 'keys' => 'get_after_method_modifiers', | ||||
| 692 | # 'exists' => 'has_after_method_modifiers', | ||||
| 693 | # # This actually makes sure there is an | ||||
| 694 | # # ARRAY at the given key, and pushed onto | ||||
| 695 | # # it. It also checks for duplicates as well | ||||
| 696 | # # 'add' => 'add_after_method_modifier' | ||||
| 697 | # } | ||||
| 698 | # ); | ||||
| 699 | # | ||||
| 700 | # has 'around_method_modifiers' => ( | ||||
| 701 | # metaclass => 'Hash', | ||||
| 702 | # reader =>'get_around_method_modifiers_map', | ||||
| 703 | # isa => 'HashRef[ArrayRef[CodeRef]]', | ||||
| 704 | # provides => { | ||||
| 705 | # 'keys' => 'get_around_method_modifiers', | ||||
| 706 | # 'exists' => 'has_around_method_modifiers', | ||||
| 707 | # # This actually makes sure there is an | ||||
| 708 | # # ARRAY at the given key, and pushed onto | ||||
| 709 | # # it. It also checks for duplicates as well | ||||
| 710 | # # 'add' => 'add_around_method_modifier' | ||||
| 711 | # } | ||||
| 712 | # ); | ||||
| 713 | # | ||||
| 714 | # # override is similar to the other modifiers | ||||
| 715 | # # except that it is not an ARRAY of code refs | ||||
| 716 | # # but instead just a single name->code mapping | ||||
| 717 | # | ||||
| 718 | # has 'override_method_modifiers' => ( | ||||
| 719 | # metaclass => 'Hash', | ||||
| 720 | # reader =>'get_override_method_modifiers_map', | ||||
| 721 | # isa => 'HashRef[CodeRef]', | ||||
| 722 | # provides => { | ||||
| 723 | # 'keys' => 'get_override_method_modifier', | ||||
| 724 | # 'exists' => 'has_override_method_modifier', | ||||
| 725 | # 'add' => 'add_override_method_modifier', # checks for local method .. | ||||
| 726 | # } | ||||
| 727 | # ); | ||||
| 728 | # | ||||
| 729 | ##################################################################### | ||||
| 730 | |||||
| 731 | |||||
| 732 | 1 | 22µs | 1; | ||
| 733 | |||||
| 734 | # ABSTRACT: The Moose Role metaclass | ||||
| 735 | |||||
| 736 | __END__ | ||||
# spent 6µs within Moose::Meta::Role::CORE:match which was called 19 times, avg 305ns/call:
# 19 times (6µs+0s) by Moose::Meta::Role::add_attribute at line 245, avg 305ns/call |