| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Role.pm |
| Statements | Executed 7831 statements in 109ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 384 | 6 | 3 | 12.0ms | 16.9ms | Moose::Meta::Role::get_method_modifier_list |
| 72 | 2 | 1 | 8.82ms | 1.68s | Moose::Meta::Role::apply |
| 178 | 3 | 3 | 7.20ms | 38.1ms | Moose::Meta::Role::add_override_method_modifier |
| 32 | 3 | 3 | 5.29ms | 12.0ms | Moose::Meta::Role::add_required_methods |
| 69 | 1 | 1 | 4.99ms | 48.5ms | Moose::Meta::Role::initialize |
| 191 | 3 | 3 | 4.90ms | 6.92ms | Moose::Meta::Role::get_override_method_modifier |
| 140 | 1 | 1 | 3.75ms | 5.31ms | Moose::Meta::Role::has_override_method_modifier |
| 51 | 1 | 1 | 3.27ms | 5.23ms | Moose::Meta::Role::add_role |
| 131 | 2 | 2 | 2.70ms | 52.8ms | Moose::Meta::Role::find_method_by_name |
| 1 | 1 | 1 | 2.50ms | 16.4ms | Moose::Meta::Role::BEGIN@17 |
| 237 | 6 | 1 | 2.20ms | 2.20ms | Moose::Meta::Role::__ANON__[:295] |
| 10 | 1 | 1 | 1.72ms | 273ms | Moose::Meta::Role::combine |
| 158 | 3 | 1 | 1.58ms | 1.58ms | Moose::Meta::Role::__ANON__[:89] |
| 1 | 1 | 1 | 1.32ms | 7.76ms | Moose::Meta::Role::BEGIN@19 |
| 15 | 3 | 3 | 1.28ms | 8.05ms | Moose::Meta::Role::add_attribute |
| 1 | 1 | 1 | 1.23ms | 6.78ms | Moose::Meta::Role::BEGIN@20 |
| 1 | 1 | 1 | 986µs | 1.59ms | Moose::Meta::Role::BEGIN@18 |
| 79 | 2 | 1 | 820µs | 820µs | Moose::Meta::Role::__ANON__[:340] |
| 69 | 1 | 1 | 792µs | 792µs | Moose::Meta::Role::_meta_method_class |
| 69 | 1 | 1 | 690µs | 690µs | Moose::Meta::Role::__ANON__[:392] |
| 51 | 1 | 1 | 589µs | 589µs | Moose::Meta::Role::reset_package_cache_flag |
| 15 | 1 | 1 | 457µs | 1.62ms | Moose::Meta::Role::_attach_attribute |
| 4 | 2 | 2 | 289µs | 371µs | Moose::Meta::Role::calculate_all_roles (recurses: max depth 1, inclusive time 134µs) |
| 24 | 1 | 1 | 250µs | 250µs | Moose::Meta::Role::_role_for_combination |
| 24 | 1 | 1 | 163µs | 163µs | Moose::Meta::Role::composition_class_roles |
| 1 | 1 | 1 | 70µs | 89µs | Moose::Meta::Role::BEGIN@4 |
| 1 | 1 | 1 | 59µs | 3.04ms | Moose::Meta::Role::BEGIN@6 |
| 1 | 1 | 1 | 58µs | 137µs | Moose::Meta::Role::BEGIN@599 |
| 1 | 1 | 1 | 45µs | 107µs | Moose::Meta::Role::BEGIN@621 |
| 1 | 1 | 1 | 42µs | 203µs | Moose::Meta::Role::BEGIN@8 |
| 7 | 1 | 1 | 41µs | 41µs | Moose::Meta::Role::CORE:match (opcode) |
| 1 | 1 | 1 | 38µs | 101µs | Moose::Meta::Role::BEGIN@636 |
| 1 | 1 | 1 | 38µs | 884µs | Moose::Meta::Role::BEGIN@10 |
| 1 | 1 | 1 | 38µs | 106µs | Moose::Meta::Role::BEGIN@5 |
| 1 | 1 | 1 | 38µs | 629µs | Moose::Meta::Role::BEGIN@25 |
| 1 | 1 | 1 | 37µs | 966µs | Moose::Meta::Role::BEGIN@22 |
| 1 | 1 | 1 | 37µs | 206µs | Moose::Meta::Role::BEGIN@9 |
| 1 | 1 | 1 | 28µs | 28µs | Moose::Meta::Role::BEGIN@16 |
| 1 | 1 | 1 | 28µs | 28µs | Moose::Meta::Role::BEGIN@21 |
| 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__[:304] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:312] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:331] |
| 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::add_conflicting_method |
| 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 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::update_package_cache_flag |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Role; | ||||
| 3 | |||||
| 4 | 3 | 98µs | 2 | 108µs | # spent 89µs (70+19) within Moose::Meta::Role::BEGIN@4 which was called:
# once (70µs+19µs) by Moose::BEGIN@27 at line 4 # spent 89µs making 1 call to Moose::Meta::Role::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 92µs | 2 | 175µs | # spent 106µs (38+69) within Moose::Meta::Role::BEGIN@5 which was called:
# once (38µs+69µs) by Moose::BEGIN@27 at line 5 # spent 106µs making 1 call to Moose::Meta::Role::BEGIN@5
# spent 69µs making 1 call to warnings::import |
| 6 | 3 | 154µs | 2 | 6.02ms | # spent 3.04ms (59µs+2.98) within Moose::Meta::Role::BEGIN@6 which was called:
# once (59µs+2.98ms) by Moose::BEGIN@27 at line 6 # spent 3.04ms making 1 call to Moose::Meta::Role::BEGIN@6
# spent 2.98ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 3 | 108µs | 2 | 363µs | # spent 203µs (42+161) within Moose::Meta::Role::BEGIN@8 which was called:
# once (42µs+161µs) by Moose::BEGIN@27 at line 8 # spent 203µs making 1 call to Moose::Meta::Role::BEGIN@8
# spent 161µs making 1 call to Exporter::import |
| 9 | 3 | 106µs | 2 | 376µs | # spent 206µs (37+169) within Moose::Meta::Role::BEGIN@9 which was called:
# once (37µs+169µs) by Moose::BEGIN@27 at line 9 # spent 206µs making 1 call to Moose::Meta::Role::BEGIN@9
# spent 169µs making 1 call to Exporter::import |
| 10 | 3 | 243µs | 2 | 1.73ms | # spent 884µs (38+846) within Moose::Meta::Role::BEGIN@10 which was called:
# once (38µs+846µs) by Moose::BEGIN@27 at line 10 # spent 884µs making 1 call to Moose::Meta::Role::BEGIN@10
# spent 846µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 11 | |||||
| 12 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 13 | 1 | 78µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 14 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 15 | |||||
| 16 | 3 | 92µs | 1 | 28µs | # spent 28µs within Moose::Meta::Role::BEGIN@16 which was called:
# once (28µs+0s) by Moose::BEGIN@27 at line 16 # spent 28µs making 1 call to Moose::Meta::Role::BEGIN@16 |
| 17 | 3 | 506µs | 1 | 16.4ms | # spent 16.4ms (2.50+13.9) within Moose::Meta::Role::BEGIN@17 which was called:
# once (2.50ms+13.9ms) by Moose::BEGIN@27 at line 17 # spent 16.4ms making 1 call to Moose::Meta::Role::BEGIN@17 |
| 18 | 3 | 506µs | 1 | 1.59ms | # spent 1.59ms (986µs+608µs) within Moose::Meta::Role::BEGIN@18 which was called:
# once (986µs+608µs) by Moose::BEGIN@27 at line 18 # spent 1.59ms making 1 call to Moose::Meta::Role::BEGIN@18 |
| 19 | 3 | 471µs | 1 | 7.76ms | # spent 7.76ms (1.32+6.44) within Moose::Meta::Role::BEGIN@19 which was called:
# once (1.32ms+6.44ms) by Moose::BEGIN@27 at line 19 # spent 7.76ms making 1 call to Moose::Meta::Role::BEGIN@19 |
| 20 | 3 | 508µs | 1 | 6.78ms | # spent 6.78ms (1.23+5.55) within Moose::Meta::Role::BEGIN@20 which was called:
# once (1.23ms+5.55ms) by Moose::BEGIN@27 at line 20 # spent 6.78ms making 1 call to Moose::Meta::Role::BEGIN@20 |
| 21 | 3 | 100µs | 1 | 28µs | # spent 28µs within Moose::Meta::Role::BEGIN@21 which was called:
# once (28µs+0s) by Moose::BEGIN@27 at line 21 # spent 28µs making 1 call to Moose::Meta::Role::BEGIN@21 |
| 22 | 3 | 143µs | 2 | 1.90ms | # spent 966µs (37+929) within Moose::Meta::Role::BEGIN@22 which was called:
# once (37µs+929µs) by Moose::BEGIN@27 at line 22 # spent 966µs making 1 call to Moose::Meta::Role::BEGIN@22
# spent 929µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 23 | 3 | 113µ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 | 591µs | # spent 629µs (38+591) within Moose::Meta::Role::BEGIN@25 which was called:
# once (38µs+591µs) by Moose::BEGIN@27 at line 27 # spent 591µs making 1 call to base::import |
| 26 | 'Class::MOP::Mixin::HasAttributes', | ||||
| 27 | 2 | 8.51ms | 1 | 629µs | 'Class::MOP::Mixin::HasMethods'; # spent 629µs making 1 call to Moose::Meta::Role::BEGIN@25 |
| 28 | |||||
| 29 | 1 | 15µs | 1 | 8.76ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 8.76ms 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 | 92µs | my $META = __PACKAGE__->meta; # spent 92µ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 | 68µ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 | 12µs | my $attr_reader = $action->{attr_reader}; | ||
| 84 | 2 | 6µs | my $methods = $action->{methods}; | ||
| 85 | |||||
| 86 | # create the attribute | ||||
| 87 | $META->add_attribute($action->{name} => ( | ||||
| 88 | reader => $attr_reader, | ||||
| 89 | 158 | 2.16ms | # spent 1.58ms within Moose::Meta::Role::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Role.pm:89] which was called 158 times, avg 10µs/call:
# 79 times (851µs+0s) by Moose::Meta::Role::Composite::_new or Moose::Meta::Role::_new at line 11 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 11µs/call
# 69 times (645µs+0s) by Moose::Meta::Role::_new at line 88 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 9µs/call
# 10 times (83µs+0s) by Moose::Meta::Role::Composite::_new at line 96 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 8µs/call | ||
| 90 | 2 | 352µs | 2 | 4.87ms | )); # spent 4.87ms making 2 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.43ms/call |
| 91 | |||||
| 92 | # create some helper methods | ||||
| 93 | $META->add_method($methods->{add} => sub { | ||||
| 94 | 10 | 40µs | my ($self, @values) = @_; | ||
| 95 | 20 | 184µs | $self->$attr_reader->{$_} = undef foreach @values; | ||
| 96 | 2 | 32µs | 1 | 353µs | }) if exists $methods->{add}; # spent 353µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 97 | |||||
| 98 | $META->add_method($methods->{get_keys} => sub { | ||||
| 99 | 96 | 309µs | my ($self) = @_; | ||
| 100 | 96 | 2.10ms | 96 | 1.11ms | keys %{$self->$attr_reader}; # spent 1.11ms making 96 calls to Moose::Meta::Role::get_excluded_roles_map, avg 12µs/call |
| 101 | 2 | 57µs | 1 | 337µs | }) if exists $methods->{get_keys}; # spent 337µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 102 | |||||
| 103 | $META->add_method($methods->{get_values} => sub { | ||||
| 104 | 96 | 283µs | my ($self) = @_; | ||
| 105 | 96 | 2.32ms | 96 | 1.15ms | values %{$self->$attr_reader}; # spent 1.15ms making 96 calls to Moose::Meta::Role::get_required_methods_map, avg 12µs/call |
| 106 | 2 | 29µs | 1 | 337µs | }) if exists $methods->{get_values}; # spent 337µ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 | 51 | 234µs | my ($self, $name) = @_; | ||
| 115 | 51 | 1.27ms | 51 | 730µs | exists $self->$attr_reader->{$name} ? 1 : 0; # spent 730µs making 51 calls to Moose::Meta::Role::get_excluded_roles_map, avg 14µs/call |
| 116 | 2 | 53µs | 2 | 769µs | }) if exists $methods->{existence}; # spent 769µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 384µs/call |
| 117 | |||||
| 118 | $META->add_method($methods->{remove} => sub { | ||||
| 119 | my ($self, @values) = @_; | ||||
| 120 | delete $self->$attr_reader->{$_} foreach @values; | ||||
| 121 | 2 | 53µs | 1 | 390µs | }) if exists $methods->{remove}; # spent 390µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 122 | } | ||||
| 123 | |||||
| 124 | $META->add_attribute( | ||||
| 125 | 1 | 13µs | 1 | 2.06ms | 'method_metaclass', # spent 2.06ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 126 | reader => 'method_metaclass', | ||||
| 127 | default => 'Moose::Meta::Role::Method', | ||||
| 128 | ); | ||||
| 129 | |||||
| 130 | 1 | 15µs | 1 | 2.07ms | $META->add_attribute( # spent 2.07ms 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 | 13µs | 1 | 2.11ms | $META->add_attribute( # spent 2.11ms 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.10ms | $META->add_attribute( # spent 2.10ms 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 | 2.04ms | $META->add_attribute( # spent 2.04ms 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 | 14µs | 1 | 2.00ms | $META->add_attribute( # spent 2.00ms 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 | # More or less copied from Moose::Meta::Class | ||||
| 161 | # spent 48.5ms (4.99+43.5) within Moose::Meta::Role::initialize which was called 69 times, avg 702µs/call:
# 69 times (4.99ms+43.5ms) by Moose::Role::init_meta at line 131 of Moose/Role.pm, avg 702µs/call | ||||
| 162 | 69 | 259µs | my $class = shift; | ||
| 163 | 69 | 213µs | my $pkg = shift; | ||
| 164 | |||||
| 165 | 69 | 693µs | 69 | 575µs | if (defined(my $meta = Class::MOP::get_metaclass_by_name($pkg))) { # spent 575µs making 69 calls to Class::MOP::get_metaclass_by_name, avg 8µs/call |
| 166 | return $meta; | ||||
| 167 | } | ||||
| 168 | |||||
| 169 | 69 | 297µs | my %options = @_; | ||
| 170 | |||||
| 171 | 69 | 2.25ms | 69 | 42.9ms | my $meta = $class->SUPER::initialize( # spent 42.9ms making 69 calls to Class::MOP::Package::initialize, avg 622µs/call |
| 172 | $pkg, | ||||
| 173 | 'attribute_metaclass' => 'Moose::Meta::Role::Attribute', | ||||
| 174 | %options, | ||||
| 175 | ); | ||||
| 176 | |||||
| 177 | 69 | 205µs | Class::MOP::weaken_metaclass($pkg) if $options{weaken}; | ||
| 178 | |||||
| 179 | 69 | 934µs | return $meta; | ||
| 180 | } | ||||
| 181 | |||||
| 182 | sub reinitialize { | ||||
| 183 | my $self = shift; | ||||
| 184 | my $pkg = shift; | ||||
| 185 | |||||
| 186 | my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg); | ||||
| 187 | |||||
| 188 | my %existing_classes; | ||||
| 189 | if ($meta) { | ||||
| 190 | %existing_classes = map { $_ => $meta->$_() } qw( | ||||
| 191 | attribute_metaclass | ||||
| 192 | method_metaclass | ||||
| 193 | wrapped_method_metaclass | ||||
| 194 | required_method_metaclass | ||||
| 195 | conflicting_method_metaclass | ||||
| 196 | application_to_class_class | ||||
| 197 | application_to_role_class | ||||
| 198 | application_to_instance_class | ||||
| 199 | ); | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | my %options = @_; | ||||
| 203 | $options{weaken} = Class::MOP::metaclass_is_weak($meta->name) | ||||
| 204 | if !exists $options{weaken} | ||||
| 205 | && blessed($meta) | ||||
| 206 | && $meta->isa('Moose::Meta::Role'); | ||||
| 207 | |||||
| 208 | # don't need to remove generated metaobjects here yet, since we don't | ||||
| 209 | # yet generate anything in roles. this may change in the future though... | ||||
| 210 | # keep an eye on that | ||||
| 211 | my $new_meta = $self->SUPER::reinitialize( | ||||
| 212 | $pkg, | ||||
| 213 | %existing_classes, | ||||
| 214 | %options, | ||||
| 215 | ); | ||||
| 216 | $new_meta->_restore_metaobjects_from($meta) | ||||
| 217 | if $meta && $meta->isa('Moose::Meta::Role'); | ||||
| 218 | return $new_meta; | ||||
| 219 | } | ||||
| 220 | |||||
| 221 | sub _restore_metaobjects_from { | ||||
| 222 | my $self = shift; | ||||
| 223 | my ($old_meta) = @_; | ||||
| 224 | |||||
| 225 | $self->_restore_metamethods_from($old_meta); | ||||
| 226 | $self->_restore_metaattributes_from($old_meta); | ||||
| 227 | } | ||||
| 228 | |||||
| 229 | # spent 8.05ms (1.28+6.77) within Moose::Meta::Role::add_attribute which was called 15 times, avg 537µs/call:
# 7 times (745µs+3.89ms) by Moose::Role::has at line 47 of Moose/Role.pm, avg 662µs/call
# 6 times (396µs+2.15ms) by Moose::Meta::Role::Application::ToRole::apply_attributes at line 71 of Moose/Meta/Role/Application/ToRole.pm, avg 424µs/call
# 2 times (140µs+732µs) by Moose::Meta::Role::Application::RoleSummation::apply_attributes at line 148 of Moose/Meta/Role/Application/RoleSummation.pm, avg 436µs/call | ||||
| 230 | 15 | 44µs | my $self = shift; | ||
| 231 | |||||
| 232 | 15 | 759µs | 45 | 242µs | if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) { # spent 151µs making 30 calls to Scalar::Util::blessed, avg 5µs/call
# spent 50µs making 8 calls to UNIVERSAL::isa, avg 6µs/call
# spent 41µs making 7 calls to Moose::Meta::Role::CORE:match, avg 6µs/call |
| 233 | my $class = ref $_[0]; | ||||
| 234 | Moose->throw_error( "Cannot add a $class as an attribute to a role" ); | ||||
| 235 | } | ||||
| 236 | elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) { | ||||
| 237 | Moose->throw_error( "has '+attr' is not supported in roles" ); | ||||
| 238 | } | ||||
| 239 | |||||
| 240 | 15 | 728µs | 15 | 6.53ms | return $self->SUPER::add_attribute(@_); # spent 6.53ms making 15 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 435µs/call |
| 241 | } | ||||
| 242 | |||||
| 243 | # spent 1.62ms (457µs+1.17) within Moose::Meta::Role::_attach_attribute which was called 15 times, avg 108µs/call:
# 15 times (457µs+1.17ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 28 of Class/MOP/Mixin/HasAttributes.pm, avg 108µs/call | ||||
| 244 | 15 | 55µs | my ( $self, $attribute ) = @_; | ||
| 245 | |||||
| 246 | 15 | 277µs | 15 | 1.17ms | $attribute->attach_to_role($self); # spent 1.17ms making 15 calls to Moose::Meta::Role::Attribute::attach_to_role, avg 78µs/call |
| 247 | } | ||||
| 248 | |||||
| 249 | # spent 12.0ms (5.29+6.69) within Moose::Meta::Role::add_required_methods which was called 32 times, avg 375µs/call:
# 15 times (4.00ms+6.01ms) by Moose::Role::requires at line 32 of Moose/Role.pm, avg 667µs/call
# 10 times (882µs+482µs) by Moose::Meta::Role::Application::RoleSummation::check_required_methods at line 109 of Moose/Meta/Role/Application/RoleSummation.pm, avg 136µs/call
# 7 times (412µs+204µs) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 88µs/call | ||||
| 250 | 32 | 98µs | my $self = shift; | ||
| 251 | |||||
| 252 | 32 | 506µs | for (@_) { | ||
| 253 | 73 | 214µs | my $method = $_; | ||
| 254 | 73 | 2.20ms | 175 | 4.88ms | if (!blessed($method)) { # spent 3.82ms making 51 calls to Moose::Meta::Role::Method::Required::new, avg 75µs/call
# spent 682µs making 51 calls to Moose::Meta::Role::required_method_metaclass, avg 13µs/call
# spent 382µs making 73 calls to Scalar::Util::blessed, avg 5µs/call |
| 255 | $method = $self->required_method_metaclass->new( | ||||
| 256 | name => $method, | ||||
| 257 | ); | ||||
| 258 | } | ||||
| 259 | 73 | 2.00ms | 146 | 1.81ms | $self->get_required_methods_map->{$method->name} = $method; # spent 916µs making 73 calls to Moose::Meta::Role::Method::Required::name, avg 13µs/call
# spent 895µs making 73 calls to Moose::Meta::Role::get_required_methods_map, avg 12µs/call |
| 260 | } | ||||
| 261 | } | ||||
| 262 | |||||
| 263 | sub add_conflicting_method { | ||||
| 264 | my $self = shift; | ||||
| 265 | |||||
| 266 | my $method; | ||||
| 267 | if (@_ == 1 && blessed($_[0])) { | ||||
| 268 | $method = shift; | ||||
| 269 | } | ||||
| 270 | else { | ||||
| 271 | $method = $self->conflicting_method_metaclass->new(@_); | ||||
| 272 | } | ||||
| 273 | |||||
| 274 | $self->add_required_methods($method); | ||||
| 275 | } | ||||
| 276 | |||||
| 277 | ## ------------------------------------------------------------------ | ||||
| 278 | ## method modifiers | ||||
| 279 | |||||
| 280 | # NOTE: | ||||
| 281 | # the before/around/after method modifiers are | ||||
| 282 | # stored by name, but there can be many methods | ||||
| 283 | # then associated with that name. So again we have | ||||
| 284 | # lots of similar functionality, so we can do some | ||||
| 285 | # meta-programmin' and save some time. | ||||
| 286 | # - SL | ||||
| 287 | |||||
| 288 | 1 | 7µs | foreach my $modifier_type (qw[ before around after ]) { | ||
| 289 | |||||
| 290 | 3 | 19µs | my $attr_reader = "get_${modifier_type}_method_modifiers_map"; | ||
| 291 | |||||
| 292 | # create the attribute ... | ||||
| 293 | $META->add_attribute("${modifier_type}_method_modifiers" => ( | ||||
| 294 | reader => $attr_reader, | ||||
| 295 | 237 | 2.91ms | # spent 2.20ms within Moose::Meta::Role::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Role.pm:295] which was called 237 times, avg 9µs/call:
# 69 times (695µs+0s) by Moose::Meta::Role::_new at line 31 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 69 times (636µs+0s) by Moose::Meta::Role::_new at line 55 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 9µs/call
# 69 times (608µs+0s) by Moose::Meta::Role::_new at line 60 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 9µs/call
# 10 times (95µs+0s) by Moose::Meta::Role::Composite::_new at line 36 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 10 times (86µs+0s) by Moose::Meta::Role::Composite::_new at line 63 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 9µs/call
# 10 times (83µs+0s) by Moose::Meta::Role::Composite::_new at line 68 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 8µs/call | ||
| 296 | 3 | 61µs | 3 | 6.36ms | )); # spent 6.36ms making 3 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.12ms/call |
| 297 | |||||
| 298 | # and some helper methods ... | ||||
| 299 | $META->add_method("get_${modifier_type}_method_modifiers" => sub { | ||||
| 300 | 249 | 1.01ms | my ($self, $method_name) = @_; | ||
| 301 | #return () unless exists $self->$attr_reader->{$method_name}; | ||||
| 302 | 249 | 2.84ms | 249 | 2.50ms | my $mm = $self->$attr_reader->{$method_name}; # spent 2.37ms making 237 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 10µs/call
# spent 85µs making 8 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call
# spent 41µs making 4 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 10µs/call |
| 303 | 249 | 3.36ms | $mm ? @$mm : (); | ||
| 304 | 3 | 84µs | 3 | 1.09ms | }); # spent 1.09ms making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 362µs/call |
| 305 | |||||
| 306 | $META->add_method("has_${modifier_type}_method_modifiers" => sub { | ||||
| 307 | my ($self, $method_name) = @_; | ||||
| 308 | # NOTE: | ||||
| 309 | # for now we assume that if it exists,.. | ||||
| 310 | # it has at least one modifier in it | ||||
| 311 | (exists $self->$attr_reader->{$method_name}) ? 1 : 0; | ||||
| 312 | 3 | 78µs | 3 | 1.01ms | }); # spent 1.01ms making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 336µs/call |
| 313 | |||||
| 314 | $META->add_method("add_${modifier_type}_method_modifier" => sub { | ||||
| 315 | 239 | 975µs | my ($self, $method_name, $method) = @_; | ||
| 316 | |||||
| 317 | 239 | 5.60ms | 467 | 4.85ms | $self->$attr_reader->{$method_name} = [] # spent 4.65ms making 449 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 10µs/call
# spent 132µs making 12 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call
# spent 65µs making 6 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 11µs/call |
| 318 | unless exists $self->$attr_reader->{$method_name}; | ||||
| 319 | |||||
| 320 | 239 | 2.75ms | 239 | 2.57ms | my $modifiers = $self->$attr_reader->{$method_name}; # spent 2.48ms making 230 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 65µs making 6 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call
# spent 31µs making 3 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 10µs/call |
| 321 | |||||
| 322 | # NOTE: | ||||
| 323 | # check to see that we aren't adding the | ||||
| 324 | # same code twice. We err in favor of the | ||||
| 325 | # first on here, this may not be as expected | ||||
| 326 | 239 | 1.21ms | foreach my $modifier (@{$modifiers}) { | ||
| 327 | 11 | 98µs | return if $modifier == $method; | ||
| 328 | } | ||||
| 329 | |||||
| 330 | 235 | 3.43ms | push @{$modifiers} => $method; | ||
| 331 | 3 | 94µs | 3 | 1.02ms | }); # spent 1.02ms making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 340µs/call |
| 332 | |||||
| 333 | } | ||||
| 334 | |||||
| 335 | ## ------------------------------------------------------------------ | ||||
| 336 | ## override method mofidiers | ||||
| 337 | |||||
| 338 | $META->add_attribute('override_method_modifiers' => ( | ||||
| 339 | reader => 'get_override_method_modifiers_map', | ||||
| 340 | 79 | 1.09ms | # spent 820µs within Moose::Meta::Role::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Role.pm:340] which was called 79 times, avg 10µs/call:
# 69 times (705µs+0s) by Moose::Meta::Role::_new at line 73 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 10 times (116µs+0s) by Moose::Meta::Role::Composite::_new at line 81 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 12µs/call | ||
| 341 | 1 | 19µs | 1 | 2.14ms | )); # spent 2.14ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 342 | |||||
| 343 | # NOTE: | ||||
| 344 | # these are a little different because there | ||||
| 345 | # can only be one per name, whereas the other | ||||
| 346 | # method modifiers can have multiples. | ||||
| 347 | # - SL | ||||
| 348 | |||||
| 349 | # spent 38.1ms (7.20+30.9) within Moose::Meta::Role::add_override_method_modifier which was called 178 times, avg 214µs/call:
# 140 times (5.65ms+28.1ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 241µs/call
# 34 times (1.36ms+1.54ms) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 237 of Moose/Meta/Role/Application/RoleSummation.pm, avg 85µs/call
# 4 times (198µs+1.23ms) by Moose::Role::override at line 77 of Moose/Role.pm, avg 356µs/call | ||||
| 350 | 178 | 701µs | my ($self, $method_name, $method) = @_; | ||
| 351 | 178 | 1.76ms | 178 | 28.9ms | (!$self->has_method($method_name)) # spent 27.7ms making 144 calls to Class::MOP::Mixin::HasMethods::has_method, avg 192µs/call
# spent 1.16ms making 34 calls to Moose::Meta::Role::Composite::has_method, avg 34µs/call |
| 352 | || Moose->throw_error("Cannot add an override of method '$method_name' " . | ||||
| 353 | "because there is a local version of '$method_name'"); | ||||
| 354 | 178 | 3.91ms | 178 | 2.02ms | $self->get_override_method_modifiers_map->{$method_name} = $method; # spent 2.02ms making 178 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call |
| 355 | } | ||||
| 356 | |||||
| 357 | # spent 5.31ms (3.75+1.55) within Moose::Meta::Role::has_override_method_modifier which was called 140 times, avg 38µs/call:
# 140 times (3.75ms+1.55ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 152 of Moose/Meta/Role/Application/ToRole.pm, avg 38µs/call | ||||
| 358 | 140 | 555µs | my ($self, $method_name) = @_; | ||
| 359 | # NOTE: | ||||
| 360 | # for now we assume that if it exists,.. | ||||
| 361 | # it has at least one modifier in it | ||||
| 362 | 140 | 2.86ms | 140 | 1.55ms | (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0; # spent 1.55ms making 140 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call |
| 363 | } | ||||
| 364 | |||||
| 365 | # spent 6.92ms (4.90+2.02) within Moose::Meta::Role::get_override_method_modifier which was called 191 times, avg 36µs/call:
# 140 times (3.56ms+1.45ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 36µs/call
# 34 times (838µs+346µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 208 of Moose/Meta/Role/Application/RoleSummation.pm, avg 35µs/call
# 17 times (501µs+222µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 205 of Moose/Meta/Role/Application/ToClass.pm, avg 43µs/call | ||||
| 366 | 191 | 735µs | my ($self, $method_name) = @_; | ||
| 367 | 191 | 3.89ms | 191 | 2.02ms | $self->get_override_method_modifiers_map->{$method_name}; # spent 2.02ms making 191 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call |
| 368 | } | ||||
| 369 | |||||
| 370 | ## general list accessor ... | ||||
| 371 | |||||
| 372 | # spent 16.9ms (12.0+4.84) within Moose::Meta::Role::get_method_modifier_list which was called 384 times, avg 44µs/call:
# 153 times (4.64ms+1.84ms) by Moose::Meta::Role::Application::ToRole::apply_method_modifiers at line 176 of Moose/Meta/Role/Application/ToRole.pm, avg 42µs/call
# 72 times (2.12ms+807µs) by Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers at line 246 of Moose/Meta/Role/Application/RoleSummation.pm, avg 41µs/call
# 63 times (1.88ms+837µs) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 217 of Moose/Meta/Role/Application/ToClass.pm, avg 43µs/call
# 51 times (1.89ms+749µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 136 of Moose/Meta/Role/Application/ToRole.pm, avg 52µs/call
# 24 times (796µs+335µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 209 of Moose/Meta/Role/Application/RoleSummation.pm, avg 47µs/call
# 21 times (710µs+272µ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 | ||||
| 373 | 384 | 1.21ms | my ($self, $modifier_type) = @_; | ||
| 374 | 384 | 1.31ms | my $accessor = "get_${modifier_type}_method_modifiers_map"; | ||
| 375 | 384 | 9.36ms | 384 | 4.84ms | keys %{$self->$accessor}; # spent 1.36ms making 96 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 14µs/call
# spent 1.17ms making 96 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 12µs/call
# spent 1.16ms making 96 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 12µs/call
# spent 1.15ms making 96 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 12µs/call |
| 376 | } | ||||
| 377 | |||||
| 378 | 51 | 748µs | # spent 589µs within Moose::Meta::Role::reset_package_cache_flag which was called 51 times, avg 12µs/call:
# 51 times (589µs+0s) by Moose::Meta::Role::add_role at line 400, avg 12µs/call | ||
| 379 | sub update_package_cache_flag { | ||||
| 380 | my $self = shift; | ||||
| 381 | $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name); | ||||
| 382 | } | ||||
| 383 | |||||
| 384 | |||||
| 385 | 69 | 936µs | # spent 792µs within Moose::Meta::Role::_meta_method_class which was called 69 times, avg 11µs/call:
# 69 times (792µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 30 of Class/MOP/Mixin/HasMethods.pm, avg 11µs/call | ||
| 386 | |||||
| 387 | ## ------------------------------------------------------------------ | ||||
| 388 | ## subroles | ||||
| 389 | |||||
| 390 | $META->add_attribute('roles' => ( | ||||
| 391 | reader => 'get_roles', | ||||
| 392 | 69 | 911µs | # spent 690µs within Moose::Meta::Role::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Role.pm:392] which was called 69 times, avg 10µs/call:
# 69 times (690µs+0s) by Moose::Meta::Role::_new at line 36 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 10µs/call | ||
| 393 | 1 | 21µs | 1 | 2.04ms | )); # spent 2.04ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 394 | |||||
| 395 | # spent 5.23ms (3.27+1.96) within Moose::Meta::Role::add_role which was called 51 times, avg 103µs/call:
# 51 times (3.27ms+1.96ms) by Moose::Meta::Role::Application::ToRole::apply at line 18 of Moose/Meta/Role/Application/ToRole.pm, avg 103µs/call | ||||
| 396 | 51 | 178µs | my ($self, $role) = @_; | ||
| 397 | 51 | 1.89ms | 102 | 729µs | (blessed($role) && $role->isa('Moose::Meta::Role')) # spent 372µs making 51 calls to Scalar::Util::blessed, avg 7µs/call
# spent 357µs making 51 calls to UNIVERSAL::isa, avg 7µs/call |
| 398 | || Moose->throw_error("Roles must be instances of Moose::Meta::Role"); | ||||
| 399 | 51 | 692µs | 51 | 642µs | push @{$self->get_roles} => $role; # spent 642µs making 51 calls to Moose::Meta::Role::get_roles, avg 13µs/call |
| 400 | 51 | 1.01ms | 51 | 589µs | $self->reset_package_cache_flag; # spent 589µs making 51 calls to Moose::Meta::Role::reset_package_cache_flag, avg 12µs/call |
| 401 | } | ||||
| 402 | |||||
| 403 | # spent 371µs (289+82) within Moose::Meta::Role::calculate_all_roles which was called 4 times, avg 93µs/call:
# 2 times (189µs+182µs) by Moose::Meta::Class::calculate_all_roles at line 200 of Moose/Meta/Class.pm, avg 185µs/call
# 2 times (100µs+-100µs) by Moose::Meta::Role::calculate_all_roles at line 407, avg 0s/call | ||||
| 404 | 4 | 11µs | my $self = shift; | ||
| 405 | 4 | 7µs | my %seen; | ||
| 406 | 6 | 145µs | 6 | 39µs | grep { # spent 39µs making 6 calls to Class::MOP::Package::name, avg 6µs/call |
| 407 | 2 | 25µs | 2 | 0s | !$seen{$_->name}++ # spent 134µs making 2 calls to Moose::Meta::Role::calculate_all_roles, avg 67µs/call, recursion: max depth 1, sum of overlapping time 134µs |
| 408 | } ($self, map { | ||||
| 409 | $_->calculate_all_roles | ||||
| 410 | 4 | 128µs | 4 | 43µs | } @{ $self->get_roles }); # spent 43µs making 4 calls to Moose::Meta::Role::get_roles, avg 11µs/call |
| 411 | } | ||||
| 412 | |||||
| 413 | sub does_role { | ||||
| 414 | my ($self, $role) = @_; | ||||
| 415 | (defined $role) | ||||
| 416 | || Moose->throw_error("You must supply a role name to look for"); | ||||
| 417 | my $role_name = blessed $role ? $role->name : $role; | ||||
| 418 | # if we are it,.. then return true | ||||
| 419 | return 1 if $role_name eq $self->name; | ||||
| 420 | # otherwise.. check our children | ||||
| 421 | foreach my $role (@{$self->get_roles}) { | ||||
| 422 | return 1 if $role->does_role($role_name); | ||||
| 423 | } | ||||
| 424 | return 0; | ||||
| 425 | } | ||||
| 426 | |||||
| 427 | 131 | 2.61ms | 131 | 50.1ms | # spent 52.8ms (2.70+50.1) within Moose::Meta::Role::find_method_by_name which was called 131 times, avg 403µs/call:
# 69 times (1.38ms+13.5ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 25 of Class/MOP/Mixin/HasMethods.pm, avg 216µs/call
# 62 times (1.32ms+36.6ms) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 611µs/call # spent 50.1ms making 131 calls to Class::MOP::Mixin::HasMethods::get_method, avg 382µs/call |
| 428 | |||||
| 429 | ## ------------------------------------------------------------------ | ||||
| 430 | ## role construction | ||||
| 431 | ## ------------------------------------------------------------------ | ||||
| 432 | |||||
| 433 | # spent 1.68s (8.82ms+1.67) within Moose::Meta::Role::apply which was called 72 times, avg 23.3ms/call:
# 62 times (7.63ms+1.42s) by Moose::Util::_apply_all_roles at line 137 of Moose/Util.pm, avg 23.1ms/call
# 10 times (1.19ms+245ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 24.6ms/call | ||||
| 434 | 72 | 436µs | my ($self, $other, %args) = @_; | ||
| 435 | |||||
| 436 | 72 | 1.27ms | 72 | 429µs | (blessed($other)) # spent 429µs making 72 calls to Scalar::Util::blessed, avg 6µs/call |
| 437 | || Moose->throw_error("You must pass in an blessed instance"); | ||||
| 438 | |||||
| 439 | 72 | 145µs | my $application_class; | ||
| 440 | 72 | 2.61ms | 165 | 1.72ms | if ($other->isa('Moose::Meta::Role')) { # spent 766µs making 51 calls to Moose::Meta::Role::application_to_role_class, avg 15µs/call
# spent 614µs making 93 calls to UNIVERSAL::isa, avg 7µs/call
# spent 336µs making 21 calls to Moose::Meta::Role::application_to_class_class, avg 16µ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 | 72 | 758µs | 72 | 4.16ms | Class::MOP::load_class($application_class); # spent 16.3ms making 72 calls to Class::MOP::load_class, avg 227µs/call, recursion: max depth 4, sum of overlapping time 12.2ms |
| 451 | |||||
| 452 | 72 | 183µs | my $deprecation_check = 0; | ||
| 453 | |||||
| 454 | 72 | 229µs | if ( exists $args{excludes} && !exists $args{'-excludes'} ) { | ||
| 455 | $args{'-excludes'} = delete $args{excludes}; | ||||
| 456 | $deprecation_check = 1; | ||||
| 457 | } | ||||
| 458 | 72 | 191µs | if ( exists $args{alias} && !exists $args{'-alias'} ) { | ||
| 459 | $args{'-alias'} = delete $args{alias}; | ||||
| 460 | $deprecation_check = 1; | ||||
| 461 | } | ||||
| 462 | |||||
| 463 | 72 | 137µ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 | 72 | 415µ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 | 72 | 4.84ms | 144 | 1.65s | return $application_class->new(%args)->apply($self, $other, \%args); # spent 1.19s making 51 calls to Moose::Meta::Role::Application::ToRole::apply, avg 23.4ms/call
# spent 449ms making 21 calls to Moose::Meta::Role::Application::ToClass::apply, avg 21.4ms/call
# spent 8.75ms making 72 calls to Moose::Meta::Role::Application::new, avg 122µs/call |
| 484 | } | ||||
| 485 | |||||
| 486 | 24 | 244µs | # spent 163µs within Moose::Meta::Role::composition_class_roles which was called 24 times, avg 7µs/call:
# 24 times (163µs+0s) by Moose::Meta::Role::Composite::new at line 50 of Moose/Meta/Role/Composite.pm, avg 7µs/call | ||
| 487 | |||||
| 488 | # spent 273ms (1.72+271) within Moose::Meta::Role::combine which was called 10 times, avg 27.3ms/call:
# 10 times (1.72ms+271ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 27.3ms/call | ||||
| 489 | 10 | 55µs | my ($class, @role_specs) = @_; | ||
| 490 | |||||
| 491 | 10 | 40µs | require Moose::Meta::Role::Composite; | ||
| 492 | |||||
| 493 | 10 | 27µs | my (@roles, %role_params); | ||
| 494 | 10 | 80µs | while (@role_specs) { | ||
| 495 | 24 | 109µs | my ($role, $params) = @{ splice @role_specs, 0, 1 }; | ||
| 496 | 24 | 410µs | 24 | 137µs | my $requested_role # spent 137µs making 24 calls to Scalar::Util::blessed, avg 6µs/call |
| 497 | = blessed $role | ||||
| 498 | ? $role | ||||
| 499 | : Class::MOP::class_of($role); | ||||
| 500 | |||||
| 501 | 24 | 242µs | 24 | 250µs | my $actual_role = $requested_role->_role_for_combination($params); # spent 250µs making 24 calls to Moose::Meta::Role::_role_for_combination, avg 10µs/call |
| 502 | 24 | 71µs | push @roles => $actual_role; | ||
| 503 | |||||
| 504 | 24 | 69µs | next unless defined $params; | ||
| 505 | 9 | 247µs | 9 | 66µs | $role_params{$actual_role->name} = $params; # spent 66µs making 9 calls to Class::MOP::Package::name, avg 7µs/call |
| 506 | } | ||||
| 507 | |||||
| 508 | 10 | 178µs | 10 | 7.15ms | my $c = Moose::Meta::Role::Composite->new(roles => \@roles); # spent 7.15ms making 10 calls to Moose::Meta::Role::Composite::new, avg 715µs/call |
| 509 | 10 | 251µs | 10 | 263ms | return $c->apply_params(\%role_params); # spent 263ms making 10 calls to Moose::Meta::Role::Composite::apply_params, avg 26.3ms/call |
| 510 | } | ||||
| 511 | |||||
| 512 | # spent 250µs within Moose::Meta::Role::_role_for_combination which was called 24 times, avg 10µs/call:
# 24 times (250µs+0s) by Moose::Meta::Role::combine at line 501, avg 10µs/call | ||||
| 513 | 24 | 70µs | my ($self, $params) = @_; | ||
| 514 | 24 | 301µs | return $self; | ||
| 515 | } | ||||
| 516 | |||||
| 517 | sub create { | ||||
| 518 | my ( $role, $package_name, %options ) = @_; | ||||
| 519 | |||||
| 520 | $options{package} = $package_name; | ||||
| 521 | |||||
| 522 | (ref $options{attributes} eq 'HASH') | ||||
| 523 | || confess "You must pass a HASH ref of attributes" | ||||
| 524 | if exists $options{attributes}; | ||||
| 525 | |||||
| 526 | (ref $options{methods} eq 'HASH') | ||||
| 527 | || confess "You must pass a HASH ref of methods" | ||||
| 528 | if exists $options{methods}; | ||||
| 529 | |||||
| 530 | $options{meta_name} = 'meta' | ||||
| 531 | unless exists $options{meta_name}; | ||||
| 532 | |||||
| 533 | my (%initialize_options) = %options; | ||||
| 534 | delete @initialize_options{qw( | ||||
| 535 | package | ||||
| 536 | attributes | ||||
| 537 | methods | ||||
| 538 | meta_name | ||||
| 539 | version | ||||
| 540 | authority | ||||
| 541 | )}; | ||||
| 542 | |||||
| 543 | my $meta = $role->initialize( $package_name => %initialize_options ); | ||||
| 544 | |||||
| 545 | $meta->_instantiate_module( $options{version}, $options{authority} ); | ||||
| 546 | |||||
| 547 | $meta->_add_meta_method($options{meta_name}) | ||||
| 548 | if defined $options{meta_name}; | ||||
| 549 | |||||
| 550 | 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 | 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 | 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 | 478µs | 2 | 215µs | # spent 137µs (58+79) within Moose::Meta::Role::BEGIN@599 which was called:
# once (58µs+79µs) by Moose::BEGIN@27 at line 599 # spent 137µs making 1 call to Moose::Meta::Role::BEGIN@599
# spent 79µs making 1 call to warnings::unimport |
| 600 | $self->name =~ /^$ANON_ROLE_PREFIX/; | ||||
| 601 | } | ||||
| 602 | |||||
| 603 | sub create_anon_role { | ||||
| 604 | my ($role, %options) = @_; | ||||
| 605 | $options{weaken} = 1 unless exists $options{weaken}; | ||||
| 606 | my $package_name = $ANON_ROLE_PREFIX . ++$ANON_ROLE_SERIAL; | ||||
| 607 | return $role->create($package_name, %options); | ||||
| 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 | 227µs | 2 | 168µs | # spent 107µs (45+62) within Moose::Meta::Role::BEGIN@621 which was called:
# once (45µs+62µs) by Moose::BEGIN@27 at line 621 # spent 107µs making 1 call to Moose::Meta::Role::BEGIN@621
# spent 62µ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 | 523µs | 2 | 164µs | # spent 101µs (38+63) within Moose::Meta::Role::BEGIN@636 which was called:
# once (38µs+63µs) by Moose::BEGIN@27 at line 636 # spent 101µs making 1 call to Moose::Meta::Role::BEGIN@636
# spent 63µ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 | 129µs | 1; | ||
| 752 | |||||
| 753 | __END__ | ||||
# spent 41µs within Moose::Meta::Role::CORE:match which was called 7 times, avg 6µs/call:
# 7 times (41µs+0s) by Moose::Meta::Role::add_attribute at line 232, avg 6µs/call |