| 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 14035 statements in 185ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 816 | 6 | 3 | 25.5ms | 35.5ms | Moose::Meta::Role::get_method_modifier_list |
| 184 | 4 | 2 | 21.9ms | 3.57s | Moose::Meta::Role::apply |
| 254 | 3 | 3 | 10.7ms | 56.1ms | Moose::Meta::Role::add_override_method_modifier |
| 125 | 2 | 2 | 10.0ms | 339ms | Moose::Meta::Role::initialize |
| 295 | 3 | 3 | 7.83ms | 11.0ms | Moose::Meta::Role::get_override_method_modifier |
| 111 | 1 | 1 | 7.25ms | 11.3ms | Moose::Meta::Role::add_role |
| 209 | 1 | 1 | 5.55ms | 7.79ms | Moose::Meta::Role::has_override_method_modifier |
| 42 | 1 | 1 | 5.44ms | 394ms | Moose::Meta::Role::create |
| 9 | 1 | 1 | 4.60ms | 264ms | Moose::Meta::Role::combine |
| 201 | 2 | 2 | 4.24ms | 82.4ms | Moose::Meta::Role::find_method_by_name |
| 402 | 7 | 2 | 3.86ms | 3.86ms | Moose::Meta::Role::__ANON__[:295] |
| 268 | 4 | 2 | 2.73ms | 2.73ms | Moose::Meta::Role::__ANON__[:89] |
| 1 | 1 | 1 | 2.47ms | 14.3ms | Moose::Meta::Role::BEGIN@17 |
| 42 | 1 | 1 | 2.05ms | 396ms | Moose::Meta::Role::create_anon_role |
| 22 | 3 | 3 | 1.88ms | 3.63ms | Moose::Meta::Role::add_required_methods |
| 24 | 2 | 2 | 1.76ms | 10.3ms | Moose::Meta::Role::add_attribute |
| 134 | 3 | 2 | 1.33ms | 1.33ms | Moose::Meta::Role::__ANON__[:340] |
| 1 | 1 | 1 | 1.28ms | 7.61ms | Moose::Meta::Role::BEGIN@19 |
| 125 | 2 | 2 | 1.26ms | 1.26ms | Moose::Meta::Role::__ANON__[:392] |
| 1 | 1 | 1 | 1.23ms | 6.70ms | Moose::Meta::Role::BEGIN@20 |
| 125 | 1 | 1 | 1.23ms | 1.23ms | Moose::Meta::Role::_meta_method_class |
| 111 | 1 | 1 | 1.16ms | 1.16ms | Moose::Meta::Role::reset_package_cache_flag |
| 1 | 1 | 1 | 956µs | 1.47ms | Moose::Meta::Role::BEGIN@18 |
| 12 | 2 | 2 | 794µs | 1.07ms | Moose::Meta::Role::calculate_all_roles (recurses: max depth 1, inclusive time 387µs) |
| 24 | 1 | 1 | 486µs | 1.89ms | Moose::Meta::Role::_attach_attribute |
| 6 | 1 | 1 | 394µs | 542µs | Moose::Meta::Role::does_role |
| 20 | 1 | 1 | 220µs | 220µs | Moose::Meta::Role::_role_for_combination |
| 20 | 1 | 1 | 133µs | 133µs | Moose::Meta::Role::composition_class_roles |
| 1 | 1 | 1 | 72µs | 91µs | Moose::Meta::Role::BEGIN@4 |
| 1 | 1 | 1 | 58µs | 135µs | Moose::Meta::Role::BEGIN@599 |
| 9 | 1 | 1 | 51µs | 51µs | Moose::Meta::Role::CORE:match (opcode) |
| 1 | 1 | 1 | 51µs | 110µs | Moose::Meta::Role::BEGIN@621 |
| 1 | 1 | 1 | 48µs | 112µs | Moose::Meta::Role::BEGIN@636 |
| 1 | 1 | 1 | 42µs | 875µs | Moose::Meta::Role::BEGIN@22 |
| 1 | 1 | 1 | 41µs | 279µs | Moose::Meta::Role::BEGIN@8 |
| 1 | 1 | 1 | 41µs | 3.01ms | Moose::Meta::Role::BEGIN@6 |
| 1 | 1 | 1 | 40µs | 894µs | Moose::Meta::Role::BEGIN@10 |
| 1 | 1 | 1 | 39µs | 173µs | Moose::Meta::Role::BEGIN@9 |
| 1 | 1 | 1 | 38µs | 106µs | Moose::Meta::Role::BEGIN@5 |
| 1 | 1 | 1 | 37µs | 639µs | Moose::Meta::Role::BEGIN@25 |
| 1 | 1 | 1 | 30µs | 30µs | Moose::Meta::Role::BEGIN@21 |
| 1 | 1 | 1 | 28µs | 28µs | Moose::Meta::Role::BEGIN@16 |
| 1 | 1 | 1 | 28µs | 28µ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::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 | 117µs | 2 | 110µs | # spent 91µs (72+19) within Moose::Meta::Role::BEGIN@4 which was called:
# once (72µs+19µs) by Moose::BEGIN@27 at line 4 # spent 91µs making 1 call to Moose::Meta::Role::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 113µs | 2 | 175µs | # spent 106µs (38+68) within Moose::Meta::Role::BEGIN@5 which was called:
# once (38µs+68µs) by Moose::BEGIN@27 at line 5 # spent 106µs making 1 call to Moose::Meta::Role::BEGIN@5
# spent 68µs making 1 call to warnings::import |
| 6 | 3 | 153µs | 2 | 5.98ms | # spent 3.01ms (41µs+2.97) within Moose::Meta::Role::BEGIN@6 which was called:
# once (41µs+2.97ms) by Moose::BEGIN@27 at line 6 # spent 3.01ms making 1 call to Moose::Meta::Role::BEGIN@6
# spent 2.97ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 3 | 120µs | 2 | 517µs | # spent 279µs (41+238) within Moose::Meta::Role::BEGIN@8 which was called:
# once (41µs+238µs) by Moose::BEGIN@27 at line 8 # spent 279µs making 1 call to Moose::Meta::Role::BEGIN@8
# spent 238µs making 1 call to Exporter::import |
| 9 | 3 | 105µs | 2 | 308µs | # spent 173µs (39+135) within Moose::Meta::Role::BEGIN@9 which was called:
# once (39µs+135µs) by Moose::BEGIN@27 at line 9 # spent 173µs making 1 call to Moose::Meta::Role::BEGIN@9
# spent 135µs making 1 call to Exporter::import |
| 10 | 3 | 244µs | 2 | 1.75ms | # spent 894µs (40+855) within Moose::Meta::Role::BEGIN@10 which was called:
# once (40µs+855µs) by Moose::BEGIN@27 at line 10 # spent 894µs making 1 call to Moose::Meta::Role::BEGIN@10
# spent 855µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 11 | |||||
| 12 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 13 | 1 | 82µs | $VERSION = eval $VERSION; # spent 12µs executing statements in string eval | ||
| 14 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 15 | |||||
| 16 | 3 | 93µ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 | 567µs | 1 | 14.3ms | # spent 14.3ms (2.47+11.8) within Moose::Meta::Role::BEGIN@17 which was called:
# once (2.47ms+11.8ms) by Moose::BEGIN@27 at line 17 # spent 14.3ms making 1 call to Moose::Meta::Role::BEGIN@17 |
| 18 | 3 | 480µs | 1 | 1.47ms | # spent 1.47ms (956µs+518µs) within Moose::Meta::Role::BEGIN@18 which was called:
# once (956µs+518µs) by Moose::BEGIN@27 at line 18 # spent 1.47ms making 1 call to Moose::Meta::Role::BEGIN@18 |
| 19 | 3 | 475µs | 1 | 7.61ms | # spent 7.61ms (1.28+6.33) within Moose::Meta::Role::BEGIN@19 which was called:
# once (1.28ms+6.33ms) by Moose::BEGIN@27 at line 19 # spent 7.61ms making 1 call to Moose::Meta::Role::BEGIN@19 |
| 20 | 3 | 520µs | 1 | 6.70ms | # spent 6.70ms (1.23+5.47) within Moose::Meta::Role::BEGIN@20 which was called:
# once (1.23ms+5.47ms) by Moose::BEGIN@27 at line 20 # spent 6.70ms making 1 call to Moose::Meta::Role::BEGIN@20 |
| 21 | 3 | 116µs | 1 | 30µs | # spent 30µs within Moose::Meta::Role::BEGIN@21 which was called:
# once (30µs+0s) by Moose::BEGIN@27 at line 21 # spent 30µs making 1 call to Moose::Meta::Role::BEGIN@21 |
| 22 | 3 | 132µs | 2 | 1.71ms | # spent 875µs (42+833) within Moose::Meta::Role::BEGIN@22 which was called:
# once (42µs+833µs) by Moose::BEGIN@27 at line 22 # spent 875µs making 1 call to Moose::Meta::Role::BEGIN@22
# spent 833µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 23 | 3 | 111µs | 1 | 28µs | # spent 28µs within Moose::Meta::Role::BEGIN@23 which was called:
# once (28µs+0s) by Moose::BEGIN@27 at line 23 # spent 28µs making 1 call to Moose::Meta::Role::BEGIN@23 |
| 24 | |||||
| 25 | 1 | 602µs | # spent 639µs (37+602) within Moose::Meta::Role::BEGIN@25 which was called:
# once (37µs+602µs) by Moose::BEGIN@27 at line 27 # spent 602µs making 1 call to base::import | ||
| 26 | 'Class::MOP::Mixin::HasAttributes', | ||||
| 27 | 3 | 8.80ms | 1 | 639µs | 'Class::MOP::Mixin::HasMethods'; # spent 639µs making 1 call to Moose::Meta::Role::BEGIN@25 |
| 28 | |||||
| 29 | 1 | 15µs | 1 | 8.81ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 8.81ms 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 | 89µs | my $META = __PACKAGE__->meta; # spent 89µ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 | 39µ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 | 9µs | my $attr_reader = $action->{attr_reader}; | ||
| 84 | 2 | 5µs | my $methods = $action->{methods}; | ||
| 85 | |||||
| 86 | # create the attribute | ||||
| 87 | $META->add_attribute($action->{name} => ( | ||||
| 88 | reader => $attr_reader, | ||||
| 89 | 268 | 3.61ms | # spent 2.73ms 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 268 times, avg 10µs/call:
# 90 times (923µs+0s) by Moose::Meta::Role::Composite::_new or Moose::Meta::Role::_new at line 11 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 88 times (975µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 11µs/call
# 81 times (754µs+0s) by Moose::Meta::Role::_new at line 88 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 9µs/call
# 9 times (76µs+0s) by Moose::Meta::Role::Composite::_new at line 96 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 8µs/call | ||
| 90 | 2 | 42µs | 2 | 4.85ms | )); # spent 4.85ms making 2 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.42ms/call |
| 91 | |||||
| 92 | # create some helper methods | ||||
| 93 | $META->add_method($methods->{add} => sub { | ||||
| 94 | 27 | 200µs | my ($self, @values) = @_; | ||
| 95 | $self->$attr_reader->{$_} = undef foreach @values; | ||||
| 96 | 2 | 39µs | 1 | 396µs | }) if exists $methods->{add}; # spent 396µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 97 | |||||
| 98 | $META->add_method($methods->{get_keys} => sub { | ||||
| 99 | 408 | 5.34ms | my ($self) = @_; | ||
| 100 | 204 | 2.33ms | keys %{$self->$attr_reader}; # spent 2.33ms making 204 calls to Moose::Meta::Role::get_excluded_roles_map, avg 11µs/call | ||
| 101 | 2 | 27µs | 1 | 328µs | }) if exists $methods->{get_keys}; # spent 328µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
| 102 | |||||
| 103 | $META->add_method($methods->{get_values} => sub { | ||||
| 104 | 408 | 5.30ms | my ($self) = @_; | ||
| 105 | 204 | 2.67ms | values %{$self->$attr_reader}; # spent 2.67ms making 204 calls to Moose::Meta::Role::get_required_methods_map, avg 13µs/call | ||
| 106 | 2 | 30µs | 1 | 374µs | }) if exists $methods->{get_values}; # spent 374µ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 | 7µs | }) if exists $methods->{get}; | ||
| 112 | |||||
| 113 | $META->add_method($methods->{existence} => sub { | ||||
| 114 | 374 | 5.43ms | my ($self, $name) = @_; | ||
| 115 | 187 | 2.53ms | exists $self->$attr_reader->{$name} ? 1 : 0; # spent 2.53ms making 187 calls to Moose::Meta::Role::get_excluded_roles_map, avg 14µs/call | ||
| 116 | 2 | 48µs | 2 | 718µs | }) if exists $methods->{existence}; # spent 718µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 359µs/call |
| 117 | |||||
| 118 | $META->add_method($methods->{remove} => sub { | ||||
| 119 | my ($self, @values) = @_; | ||||
| 120 | delete $self->$attr_reader->{$_} foreach @values; | ||||
| 121 | 2 | 39µs | 1 | 324µs | }) if exists $methods->{remove}; # spent 324µ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 | 14µs | 1 | 2.04ms | $META->add_attribute( # spent 2.04ms 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 | 17µs | 1 | 2.13ms | $META->add_attribute( # spent 2.13ms 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 | 14µs | 1 | 2.06ms | $META->add_attribute( # spent 2.06ms 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.05ms | $META->add_attribute( # spent 2.05ms 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 | 1.99ms | $META->add_attribute( # spent 1.99ms 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 339ms (10.0+329) within Moose::Meta::Role::initialize which was called 125 times, avg 2.72ms/call:
# 83 times (6.20ms+65.4ms) by Moose::Role::init_meta at line 131 of Moose/Role.pm, avg 862µs/call
# 42 times (3.85ms+264ms) by Moose::Meta::Role::create at line 543, avg 6.38ms/call | ||||
| 162 | 875 | 9.44ms | my $class = shift; | ||
| 163 | my $pkg = shift; | ||||
| 164 | |||||
| 165 | 125 | 1.03ms | if (defined(my $meta = Class::MOP::get_metaclass_by_name($pkg))) { # spent 1.03ms making 125 calls to Class::MOP::get_metaclass_by_name, avg 8µs/call | ||
| 166 | return $meta; | ||||
| 167 | } | ||||
| 168 | |||||
| 169 | my %options = @_; | ||||
| 170 | |||||
| 171 | 125 | 327ms | my $meta = $class->SUPER::initialize( # spent 327ms making 125 calls to Class::MOP::Package::initialize, avg 2.62ms/call | ||
| 172 | $pkg, | ||||
| 173 | 'attribute_metaclass' => 'Moose::Meta::Role::Attribute', | ||||
| 174 | %options, | ||||
| 175 | ); | ||||
| 176 | |||||
| 177 | 42 | 1.34ms | Class::MOP::weaken_metaclass($pkg) if $options{weaken}; # spent 1.34ms making 42 calls to Class::MOP::weaken_metaclass, avg 32µs/call | ||
| 178 | |||||
| 179 | 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 10.3ms (1.76+8.50) within Moose::Meta::Role::add_attribute which was called 24 times, avg 427µs/call:
# 15 times (981µs+4.62ms) by Moose::Meta::Role::Application::ToRole::apply_attributes at line 71 of Moose/Meta/Role/Application/ToRole.pm, avg 373µs/call
# 9 times (775µs+3.88ms) by Moose::Role::has at line 47 of Moose/Role.pm, avg 517µs/call | ||||
| 230 | 72 | 2.22ms | my $self = shift; | ||
| 231 | |||||
| 232 | 72 | 421µs | if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) { # spent 281µs making 48 calls to Scalar::Util::blessed, avg 6µs/call
# spent 89µs making 15 calls to UNIVERSAL::isa, avg 6µs/call
# spent 51µs making 9 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 | 24 | 8.08ms | return $self->SUPER::add_attribute(@_); # spent 8.08ms making 24 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 337µs/call | ||
| 241 | } | ||||
| 242 | |||||
| 243 | # spent 1.89ms (486µs+1.41) within Moose::Meta::Role::_attach_attribute which was called 24 times, avg 79µs/call:
# 24 times (486µs+1.41ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 28 of Class/MOP/Mixin/HasAttributes.pm, avg 79µs/call | ||||
| 244 | 48 | 496µs | my ( $self, $attribute ) = @_; | ||
| 245 | |||||
| 246 | 24 | 1.41ms | $attribute->attach_to_role($self); # spent 1.41ms making 24 calls to Moose::Meta::Role::Attribute::attach_to_role, avg 59µs/call | ||
| 247 | } | ||||
| 248 | |||||
| 249 | # spent 3.63ms (1.88+1.75) within Moose::Meta::Role::add_required_methods which was called 22 times, avg 165µs/call:
# 9 times (1.04ms+1.34ms) by Moose::Role::requires at line 32 of Moose/Role.pm, avg 265µs/call
# 9 times (581µs+284µs) by Moose::Meta::Role::Application::RoleSummation::check_required_methods at line 109 of Moose/Meta/Role/Application/RoleSummation.pm, avg 96µs/call
# 4 times (260µs+128µs) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 97µs/call | ||||
| 250 | 113 | 1.90ms | my $self = shift; | ||
| 251 | |||||
| 252 | for (@_) { | ||||
| 253 | my $method = $_; | ||||
| 254 | 43 | 1.15ms | if (!blessed($method)) { # spent 885µs making 10 calls to Moose::Meta::Role::Method::Required::new, avg 89µs/call
# spent 141µs making 10 calls to Moose::Meta::Role::required_method_metaclass, avg 14µs/call
# spent 123µs making 23 calls to Scalar::Util::blessed, avg 5µs/call | ||
| 255 | $method = $self->required_method_metaclass->new( | ||||
| 256 | name => $method, | ||||
| 257 | ); | ||||
| 258 | } | ||||
| 259 | 46 | 602µs | $self->get_required_methods_map->{$method->name} = $method; # spent 305µs making 23 calls to Moose::Meta::Role::Method::Required::name, avg 13µs/call
# spent 297µs making 23 calls to Moose::Meta::Role::get_required_methods_map, avg 13µ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 | 402 | 5.07ms | # spent 3.86ms 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 402 times, avg 10µs/call:
# 132 times (1.27ms+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 10µs/call
# 81 times (875µs+0s) by Moose::Meta::Role::_new at line 31 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 11µs/call
# 81 times (790µs+0s) by Moose::Meta::Role::_new at line 55 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 81 times (685µs+0s) by Moose::Meta::Role::_new at line 60 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 8µs/call
# 9 times (87µs+0s) by Moose::Meta::Role::Composite::_new at line 36 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 9 times (78µs+0s) by Moose::Meta::Role::Composite::_new at line 63 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 9µs/call
# 9 times (75µs+0s) by Moose::Meta::Role::Composite::_new at line 68 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 8µs/call | ||
| 296 | 3 | 61µs | 3 | 6.35ms | )); # spent 6.35ms 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 | 1026 | 10.5ms | my ($self, $method_name) = @_; | ||
| 301 | #return () unless exists $self->$attr_reader->{$method_name}; | ||||
| 302 | 342 | 3.73ms | my $mm = $self->$attr_reader->{$method_name}; # spent 3.35ms making 310 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 226µs making 21 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call
# spent 155µs making 11 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 14µs/call | ||
| 303 | $mm ? @$mm : (); | ||||
| 304 | 3 | 86µs | 3 | 1.06ms | }); # spent 1.06ms making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 352µ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 | 74µs | 3 | 962µs | }); # spent 962µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 321µs/call |
| 313 | |||||
| 314 | $META->add_method("add_${modifier_type}_method_modifier" => sub { | ||||
| 315 | 1492 | 18.0ms | my ($self, $method_name, $method) = @_; | ||
| 316 | |||||
| 317 | 581 | 6.24ms | $self->$attr_reader->{$method_name} = [] # spent 5.78ms making 541 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 302µs making 26 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 12µs/call
# spent 159µs making 14 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 11µs/call | ||
| 318 | unless exists $self->$attr_reader->{$method_name}; | ||||
| 319 | |||||
| 320 | 297 | 3.19ms | my $modifiers = $self->$attr_reader->{$method_name}; # spent 2.95ms making 277 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 168µs making 13 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 13µs/call
# spent 74µs making 7 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 11µ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 | foreach my $modifier (@{$modifiers}) { | ||||
| 327 | return if $modifier == $method; | ||||
| 328 | } | ||||
| 329 | |||||
| 330 | push @{$modifiers} => $method; | ||||
| 331 | 3 | 93µs | 3 | 982µs | }); # spent 982µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 327µ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 | 134 | 1.79ms | # spent 1.33ms 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 134 times, avg 10µs/call:
# 81 times (781µs+0s) by Moose::Meta::Role::_new at line 73 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 44 times (462µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 10µs/call
# 9 times (83µs+0s) by Moose::Meta::Role::Composite::_new at line 81 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 9µs/call | ||
| 341 | 1 | 21µs | 1 | 2.10ms | )); # spent 2.10ms 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 56.1ms (10.7+45.4) within Moose::Meta::Role::add_override_method_modifier which was called 254 times, avg 221µs/call:
# 209 times (8.76ms+42.3ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 244µs/call
# 41 times (1.74ms+1.92ms) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 237 of Moose/Meta/Role/Application/RoleSummation.pm, avg 89µs/call
# 4 times (176µs+1.23ms) by Moose::Role::override at line 77 of Moose/Role.pm, avg 352µs/call | ||||
| 350 | 762 | 9.62ms | my ($self, $method_name, $method) = @_; | ||
| 351 | 254 | 42.4ms | (!$self->has_method($method_name)) # spent 41.0ms making 213 calls to Class::MOP::Mixin::HasMethods::has_method, avg 192µs/call
# spent 1.44ms making 41 calls to Moose::Meta::Role::Composite::has_method, avg 35µ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 | 254 | 3.00ms | $self->get_override_method_modifiers_map->{$method_name} = $method; # spent 3.00ms making 254 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 12µs/call | ||
| 355 | } | ||||
| 356 | |||||
| 357 | # spent 7.79ms (5.55+2.24) within Moose::Meta::Role::has_override_method_modifier which was called 209 times, avg 37µs/call:
# 209 times (5.55ms+2.24ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 152 of Moose/Meta/Role/Application/ToRole.pm, avg 37µs/call | ||||
| 358 | 418 | 5.15ms | 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 | 209 | 2.24ms | (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0; # spent 2.24ms making 209 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call | ||
| 363 | } | ||||
| 364 | |||||
| 365 | # spent 11.0ms (7.83+3.17) within Moose::Meta::Role::get_override_method_modifier which was called 295 times, avg 37µs/call:
# 209 times (5.39ms+2.15ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 36µs/call
# 45 times (1.36ms+557µ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
# 41 times (1.07ms+456µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 208 of Moose/Meta/Role/Application/RoleSummation.pm, avg 37µs/call | ||||
| 366 | 590 | 7.25ms | my ($self, $method_name) = @_; | ||
| 367 | 295 | 3.17ms | $self->get_override_method_modifiers_map->{$method_name}; # spent 3.17ms making 295 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call | ||
| 368 | } | ||||
| 369 | |||||
| 370 | ## general list accessor ... | ||||
| 371 | |||||
| 372 | # spent 35.5ms (25.5+9.97) within Moose::Meta::Role::get_method_modifier_list which was called 816 times, avg 43µs/call:
# 333 times (9.89ms+3.98ms) by Moose::Meta::Role::Application::ToRole::apply_method_modifiers at line 176 of Moose/Meta/Role/Application/ToRole.pm, avg 42µs/call
# 219 times (6.56ms+2.72ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 217 of Moose/Meta/Role/Application/ToClass.pm, avg 42µs/call
# 111 times (3.95ms+1.40ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 136 of Moose/Meta/Role/Application/ToRole.pm, avg 48µs/call
# 73 times (2.57ms+925µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 195 of Moose/Meta/Role/Application/ToClass.pm, avg 48µs/call
# 60 times (1.86ms+681µs) by Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers at line 246 of Moose/Meta/Role/Application/RoleSummation.pm, avg 42µs/call
# 20 times (675µs+261µ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 | ||||
| 373 | 2448 | 24.5ms | my ($self, $modifier_type) = @_; | ||
| 374 | my $accessor = "get_${modifier_type}_method_modifiers_map"; | ||||
| 375 | 816 | 9.97ms | keys %{$self->$accessor}; # spent 2.59ms making 204 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 13µs/call
# spent 2.54ms making 204 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 12µs/call
# spent 2.43ms making 204 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 12µs/call
# spent 2.41ms making 204 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 12µs/call | ||
| 376 | } | ||||
| 377 | |||||
| 378 | 111 | 1.52ms | # spent 1.16ms within Moose::Meta::Role::reset_package_cache_flag which was called 111 times, avg 10µs/call:
# 111 times (1.16ms+0s) by Moose::Meta::Role::add_role at line 400, avg 10µ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 | 125 | 1.49ms | # spent 1.23ms within Moose::Meta::Role::_meta_method_class which was called 125 times, avg 10µs/call:
# 125 times (1.23ms+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 30 of Class/MOP/Mixin/HasMethods.pm, avg 10µs/call | ||
| 386 | |||||
| 387 | ## ------------------------------------------------------------------ | ||||
| 388 | ## subroles | ||||
| 389 | |||||
| 390 | $META->add_attribute('roles' => ( | ||||
| 391 | reader => 'get_roles', | ||||
| 392 | 125 | 1.64ms | # spent 1.26ms 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 125 times, avg 10µs/call:
# 81 times (809µs+0s) by Moose::Meta::Role::_new at line 36 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# 44 times (448µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 10µs/call | ||
| 393 | 1 | 19µs | 1 | 2.08ms | )); # spent 2.08ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 394 | |||||
| 395 | # spent 11.3ms (7.25+4.08) within Moose::Meta::Role::add_role which was called 111 times, avg 102µs/call:
# 111 times (7.25ms+4.08ms) by Moose::Meta::Role::Application::ToRole::apply at line 18 of Moose/Meta/Role/Application/ToRole.pm, avg 102µs/call | ||||
| 396 | 444 | 8.25ms | my ($self, $role) = @_; | ||
| 397 | 222 | 1.52ms | (blessed($role) && $role->isa('Moose::Meta::Role')) # spent 767µs making 111 calls to Scalar::Util::blessed, avg 7µs/call
# spent 749µs making 111 calls to UNIVERSAL::isa, avg 7µs/call | ||
| 398 | || Moose->throw_error("Roles must be instances of Moose::Meta::Role"); | ||||
| 399 | 111 | 1.40ms | push @{$self->get_roles} => $role; # spent 1.40ms making 111 calls to Moose::Meta::Role::get_roles, avg 13µs/call | ||
| 400 | 111 | 1.16ms | $self->reset_package_cache_flag; # spent 1.16ms making 111 calls to Moose::Meta::Role::reset_package_cache_flag, avg 10µs/call | ||
| 401 | } | ||||
| 402 | |||||
| 403 | # spent 1.07ms (794µs+273µs) within Moose::Meta::Role::calculate_all_roles which was called 12 times, avg 89µs/call:
# 6 times (513µs+555µs) by Moose::Meta::Class::calculate_all_roles at line 200 of Moose/Meta/Class.pm, avg 178µs/call
# 6 times (282µs+-282µs) by Moose::Meta::Role::calculate_all_roles at line 407, avg 0s/call | ||||
| 404 | 60 | 857µs | my $self = shift; | ||
| 405 | my %seen; | ||||
| 406 | 18 | 105µs | grep { # spent 105µs making 18 calls to Class::MOP::Package::name, avg 6µs/call | ||
| 407 | 6 | 0s | !$seen{$_->name}++ # spent 387µs making 6 calls to Moose::Meta::Role::calculate_all_roles, avg 64µs/call, recursion: max depth 1, sum of overlapping time 387µs | ||
| 408 | } ($self, map { | ||||
| 409 | $_->calculate_all_roles | ||||
| 410 | 12 | 168µs | } @{ $self->get_roles }); # spent 168µs making 12 calls to Moose::Meta::Role::get_roles, avg 14µs/call | ||
| 411 | } | ||||
| 412 | |||||
| 413 | # spent 542µs (394+148) within Moose::Meta::Role::does_role which was called 6 times, avg 90µs/call:
# 6 times (394µs+148µs) by Moose::Meta::Class::does_role at line 227 of Moose/Meta/Class.pm, avg 90µs/call | ||||
| 414 | 36 | 455µs | my ($self, $role) = @_; | ||
| 415 | (defined $role) | ||||
| 416 | || Moose->throw_error("You must supply a role name to look for"); | ||||
| 417 | 6 | 30µs | my $role_name = blessed $role ? $role->name : $role; # spent 30µs making 6 calls to Scalar::Util::blessed, avg 5µs/call | ||
| 418 | # if we are it,.. then return true | ||||
| 419 | 6 | 37µs | return 1 if $role_name eq $self->name; # spent 37µs making 6 calls to Class::MOP::Package::name, avg 6µs/call | ||
| 420 | # otherwise.. check our children | ||||
| 421 | 6 | 80µs | foreach my $role (@{$self->get_roles}) { # spent 80µs making 6 calls to Moose::Meta::Role::get_roles, avg 13µs/call | ||
| 422 | return 1 if $role->does_role($role_name); | ||||
| 423 | } | ||||
| 424 | return 0; | ||||
| 425 | } | ||||
| 426 | |||||
| 427 | 201 | 3.92ms | 201 | 78.2ms | # spent 82.4ms (4.24+78.2) within Moose::Meta::Role::find_method_by_name which was called 201 times, avg 410µs/call:
# 125 times (2.61ms+32.7ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 25 of Class/MOP/Mixin/HasMethods.pm, avg 283µs/call
# 76 times (1.63ms+45.5ms) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 620µs/call # spent 78.2ms making 201 calls to Class::MOP::Mixin::HasMethods::get_method, avg 389µs/call |
| 428 | |||||
| 429 | ## ------------------------------------------------------------------ | ||||
| 430 | ## role construction | ||||
| 431 | ## ------------------------------------------------------------------ | ||||
| 432 | |||||
| 433 | # spent 3.57s (21.9ms+3.55) within Moose::Meta::Role::apply which was called 184 times, avg 19.4ms/call:
# 91 times (10.8ms+2.67s) by Moose::Util::_apply_all_roles at line 137 of Moose/Util.pm, avg 29.5ms/call
# 42 times (5.21ms+485ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::apply at line 121 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 11.7ms/call
# 42 times (4.77ms+164ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::apply_parameterizable_role at line 127 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 4.01ms/call
# 9 times (1.09ms+231ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 25.8ms/call | ||||
| 434 | 2024 | 23.7ms | my ($self, $other, %args) = @_; | ||
| 435 | |||||
| 436 | 184 | 1.16ms | (blessed($other)) # spent 1.16ms making 184 calls to Scalar::Util::blessed, avg 6µs/call | ||
| 437 | || Moose->throw_error("You must pass in an blessed instance"); | ||||
| 438 | |||||
| 439 | my $application_class; | ||||
| 440 | 441 | 4.64ms | if ($other->isa('Moose::Meta::Role')) { # spent 1.80ms making 257 calls to UNIVERSAL::isa, avg 7µs/call
# spent 1.72ms making 111 calls to Moose::Meta::Role::application_to_role_class, avg 16µs/call
# spent 1.11ms making 73 calls to Moose::Meta::Role::application_to_class_class, avg 15µ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 | 184 | 27.0ms | Class::MOP::load_class($application_class); # spent 42.4ms making 184 calls to Class::MOP::load_class, avg 231µs/call, recursion: max depth 4, sum of overlapping time 15.4ms | ||
| 451 | |||||
| 452 | my $deprecation_check = 0; | ||||
| 453 | |||||
| 454 | if ( exists $args{excludes} && !exists $args{'-excludes'} ) { | ||||
| 455 | $args{'-excludes'} = delete $args{excludes}; | ||||
| 456 | $deprecation_check = 1; | ||||
| 457 | } | ||||
| 458 | if ( exists $args{alias} && !exists $args{'-alias'} ) { | ||||
| 459 | $args{'-alias'} = delete $args{alias}; | ||||
| 460 | $deprecation_check = 1; | ||||
| 461 | } | ||||
| 462 | |||||
| 463 | 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 | 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 | 368 | 3.50s | return $application_class->new(%args)->apply($self, $other, \%args); # spent 1.90s making 111 calls to Moose::Meta::Role::Application::ToRole::apply, avg 17.1ms/call
# spent 1.58s making 73 calls to Moose::Meta::Role::Application::ToClass::apply, avg 21.6ms/call
# spent 23.3ms making 184 calls to Moose::Meta::Role::Application::new, avg 127µs/call | ||
| 484 | } | ||||
| 485 | |||||
| 486 | 20 | 224µs | # spent 133µs within Moose::Meta::Role::composition_class_roles which was called 20 times, avg 7µs/call:
# 20 times (133µs+0s) by Moose::Meta::Role::Composite::new at line 50 of Moose/Meta/Role/Composite.pm, avg 7µs/call | ||
| 487 | |||||
| 488 | # spent 264ms (4.60+259) within Moose::Meta::Role::combine which was called 9 times, avg 29.3ms/call:
# 9 times (4.60ms+259ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 29.3ms/call | ||||
| 489 | 164 | 4.67ms | my ($class, @role_specs) = @_; | ||
| 490 | |||||
| 491 | require Moose::Meta::Role::Composite; | ||||
| 492 | |||||
| 493 | my (@roles, %role_params); | ||||
| 494 | while (@role_specs) { | ||||
| 495 | my ($role, $params) = @{ splice @role_specs, 0, 1 }; | ||||
| 496 | 20 | 114µs | my $requested_role # spent 114µs making 20 calls to Scalar::Util::blessed, avg 6µs/call | ||
| 497 | = blessed $role | ||||
| 498 | ? $role | ||||
| 499 | : Class::MOP::class_of($role); | ||||
| 500 | |||||
| 501 | 20 | 220µs | my $actual_role = $requested_role->_role_for_combination($params); # spent 220µs making 20 calls to Moose::Meta::Role::_role_for_combination, avg 11µs/call | ||
| 502 | push @roles => $actual_role; | ||||
| 503 | |||||
| 504 | next unless defined $params; | ||||
| 505 | 10 | 70µs | $role_params{$actual_role->name} = $params; # spent 70µs making 10 calls to Class::MOP::Package::name, avg 7µs/call | ||
| 506 | } | ||||
| 507 | |||||
| 508 | 9 | 6.15ms | my $c = Moose::Meta::Role::Composite->new(roles => \@roles); # spent 6.15ms making 9 calls to Moose::Meta::Role::Composite::new, avg 683µs/call | ||
| 509 | 9 | 252ms | return $c->apply_params(\%role_params); # spent 252ms making 9 calls to Moose::Meta::Role::Composite::apply_params, avg 28.0ms/call | ||
| 510 | } | ||||
| 511 | |||||
| 512 | # spent 220µs within Moose::Meta::Role::_role_for_combination which was called 20 times, avg 11µs/call:
# 20 times (220µs+0s) by Moose::Meta::Role::combine at line 501, avg 11µs/call | ||||
| 513 | 40 | 294µs | my ($self, $params) = @_; | ||
| 514 | return $self; | ||||
| 515 | } | ||||
| 516 | |||||
| 517 | # spent 394ms (5.44+389) within Moose::Meta::Role::create which was called 42 times, avg 9.38ms/call:
# 42 times (5.44ms+389ms) by Moose::Meta::Role::create_anon_role at line 607, avg 9.38ms/call | ||||
| 518 | 546 | 5.34ms | 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 | 42 | 268ms | my $meta = $role->initialize( $package_name => %initialize_options ); # spent 268ms making 42 calls to Moose::Meta::Role::initialize, avg 6.38ms/call | ||
| 544 | |||||
| 545 | 42 | 5.61ms | $meta->_instantiate_module( $options{version}, $options{authority} ); # spent 5.61ms making 42 calls to Class::MOP::Module::_instantiate_module, avg 133µs/call | ||
| 546 | |||||
| 547 | 42 | 115ms | $meta->_add_meta_method($options{meta_name}) # spent 115ms making 42 calls to Class::MOP::Mixin::HasMethods::_add_meta_method, avg 2.74ms/call | ||
| 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 | 457µs | 2 | 212µs | # spent 135µs (58+77) within Moose::Meta::Role::BEGIN@599 which was called:
# once (58µs+77µs) by Moose::BEGIN@27 at line 599 # spent 135µs making 1 call to Moose::Meta::Role::BEGIN@599
# spent 77µs making 1 call to warnings::unimport |
| 600 | $self->name =~ /^$ANON_ROLE_PREFIX/; | ||||
| 601 | } | ||||
| 602 | |||||
| 603 | # spent 396ms (2.05+394) within Moose::Meta::Role::create_anon_role which was called 42 times, avg 9.43ms/call:
# 42 times (2.05ms+394ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::generate_role at line 85 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 9.43ms/call | ||||
| 604 | 168 | 1.98ms | my ($role, %options) = @_; | ||
| 605 | $options{weaken} = 1 unless exists $options{weaken}; | ||||
| 606 | my $package_name = $ANON_ROLE_PREFIX . ++$ANON_ROLE_SERIAL; | ||||
| 607 | 42 | 394ms | return $role->create($package_name, %options); # spent 394ms making 42 calls to Moose::Meta::Role::create, avg 9.38ms/call | ||
| 608 | } | ||||
| 609 | |||||
| 610 | # NOTE: | ||||
| 611 | # this will only get called for | ||||
| 612 | # anon-roles, all other calls | ||||
| 613 | # are assumed to occur during | ||||
| 614 | # global destruction and so don't | ||||
| 615 | # really need to be handled explicitly | ||||
| 616 | sub DESTROY { | ||||
| 617 | my $self = shift; | ||||
| 618 | |||||
| 619 | return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated | ||||
| 620 | |||||
| 621 | 3 | 229µs | 2 | 170µs | # spent 110µs (51+59) within Moose::Meta::Role::BEGIN@621 which was called:
# once (51µs+59µs) by Moose::BEGIN@27 at line 621 # spent 110µs making 1 call to Moose::Meta::Role::BEGIN@621
# spent 59µ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 | 551µs | 2 | 176µs | # spent 112µs (48+64) within Moose::Meta::Role::BEGIN@636 which was called:
# once (48µs+64µs) by Moose::BEGIN@27 at line 636 # spent 112µs making 1 call to Moose::Meta::Role::BEGIN@636
# spent 64µ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 | 131µs | 1; | ||
| 752 | |||||
| 753 | __END__ | ||||
# spent 51µs within Moose::Meta::Role::CORE:match which was called 9 times, avg 6µs/call:
# 9 times (51µs+0s) by Moose::Meta::Role::add_attribute at line 232, avg 6µs/call |