| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm |
| Statements | Executed 3052 statements in 51.4ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 192 | 6 | 3 | 5.94ms | 8.43ms | Moose::Meta::Role::get_method_modifier_list |
| 27 | 4 | 4 | 4.98ms | 12.4ms | Moose::Meta::Role::add_required_methods |
| 39 | 2 | 1 | 4.82ms | 609ms | Moose::Meta::Role::apply |
| 35 | 1 | 1 | 2.51ms | 25.5ms | Moose::Meta::Role::initialize |
| 1 | 1 | 1 | 2.43ms | 13.5ms | Moose::Meta::Role::BEGIN@17 |
| 30 | 3 | 3 | 1.25ms | 5.44ms | Moose::Meta::Role::add_override_method_modifier |
| 1 | 1 | 1 | 1.24ms | 7.18ms | Moose::Meta::Role::BEGIN@19 |
| 1 | 1 | 1 | 1.20ms | 6.44ms | Moose::Meta::Role::BEGIN@20 |
| 18 | 1 | 1 | 1.19ms | 1.87ms | Moose::Meta::Role::add_role |
| 57 | 2 | 2 | 1.17ms | 15.9ms | Moose::Meta::Role::find_method_by_name |
| 15 | 3 | 3 | 1.12ms | 6.64ms | Moose::Meta::Role::add_attribute |
| 42 | 3 | 3 | 1.09ms | 1.54ms | Moose::Meta::Role::get_override_method_modifier |
| 114 | 5 | 1 | 1.01ms | 1.01ms | Moose::Meta::Role::__ANON__[:302] |
| 1 | 1 | 1 | 993µs | 1.50ms | Moose::Meta::Role::BEGIN@18 |
| 76 | 4 | 1 | 678µs | 678µs | Moose::Meta::Role::__ANON__[:89] |
| 24 | 1 | 1 | 626µs | 878µs | Moose::Meta::Role::has_override_method_modifier |
| 3 | 1 | 1 | 621µs | 75.2ms | Moose::Meta::Role::combine |
| 35 | 1 | 1 | 428µs | 428µs | Moose::Meta::Role::_meta_method_class |
| 38 | 2 | 1 | 379µs | 379µs | Moose::Meta::Role::__ANON__[:347] |
| 35 | 1 | 1 | 374µs | 374µs | Moose::Meta::Role::__ANON__[:392] |
| 15 | 1 | 1 | 336µs | 1.29ms | Moose::Meta::Role::_attach_attribute |
| 4 | 2 | 2 | 290µs | 367µs | Moose::Meta::Role::calculate_all_roles (recurses: max depth 1, inclusive time 132µs) |
| 1 | 1 | 1 | 128µs | 943µs | Moose::Meta::Role::add_conflicting_method |
| 9 | 1 | 1 | 97µs | 97µs | Moose::Meta::Role::_role_for_combination |
| 1 | 1 | 1 | 67µs | 230µs | Moose::Meta::Role::BEGIN@8 |
| 1 | 1 | 1 | 67µs | 85µs | Moose::Meta::Role::BEGIN@4 |
| 1 | 1 | 1 | 58µs | 133µs | Moose::Meta::Role::BEGIN@599 |
| 9 | 1 | 1 | 57µs | 57µs | Moose::Meta::Role::composition_class_roles |
| 1 | 1 | 1 | 43µs | 132µs | Moose::Meta::Role::BEGIN@5 |
| 1 | 1 | 1 | 42µs | 101µs | Moose::Meta::Role::BEGIN@621 |
| 1 | 1 | 1 | 41µs | 104µs | Moose::Meta::Role::BEGIN@636 |
| 1 | 1 | 1 | 41µs | 886µs | Moose::Meta::Role::BEGIN@10 |
| 1 | 1 | 1 | 39µs | 2.71ms | Moose::Meta::Role::BEGIN@6 |
| 1 | 1 | 1 | 39µs | 208µs | Moose::Meta::Role::BEGIN@9 |
| 1 | 1 | 1 | 38µs | 859µs | Moose::Meta::Role::BEGIN@22 |
| 1 | 1 | 1 | 38µs | 641µs | Moose::Meta::Role::BEGIN@25 |
| 1 | 1 | 1 | 29µs | 29µs | Moose::Meta::Role::BEGIN@21 |
| 1 | 1 | 1 | 29µs | 29µs | Moose::Meta::Role::BEGIN@16 |
| 1 | 1 | 1 | 26µs | 26µs | Moose::Meta::Role::BEGIN@23 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::DESTROY |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:101] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:106] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:111] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:116] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:121] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:311] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:319] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:338] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::__ANON__[:96] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::_restore_metaobjects_from |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::consumers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::create |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::create_anon_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::does_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::is_anon_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::reinitialize |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Role; | ||||
| 3 | |||||
| 4 | 3 | 96µs | 2 | 104µs | # spent 85µs (67+18) within Moose::Meta::Role::BEGIN@4 which was called:
# once (67µs+18µs) by Moose::BEGIN@27 at line 4 # spent 85µs making 1 call to Moose::Meta::Role::BEGIN@4
# spent 18µs making 1 call to strict::import |
| 5 | 3 | 103µs | 2 | 221µs | # spent 132µs (43+89) within Moose::Meta::Role::BEGIN@5 which was called:
# once (43µs+89µs) by Moose::BEGIN@27 at line 5 # spent 132µs making 1 call to Moose::Meta::Role::BEGIN@5
# spent 89µs making 1 call to warnings::import |
| 6 | 3 | 148µs | 2 | 5.38ms | # spent 2.71ms (39µs+2.67) within Moose::Meta::Role::BEGIN@6 which was called:
# once (39µs+2.67ms) by Moose::BEGIN@27 at line 6 # spent 2.71ms making 1 call to Moose::Meta::Role::BEGIN@6
# spent 2.67ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 3 | 115µs | 2 | 393µs | # spent 230µs (67+163) within Moose::Meta::Role::BEGIN@8 which was called:
# once (67µs+163µs) by Moose::BEGIN@27 at line 8 # spent 230µs making 1 call to Moose::Meta::Role::BEGIN@8
# spent 163µs making 1 call to Exporter::import |
| 9 | 3 | 120µs | 2 | 376µs | # spent 208µs (39+169) within Moose::Meta::Role::BEGIN@9 which was called:
# once (39µs+169µs) by Moose::BEGIN@27 at line 9 # spent 208µs making 1 call to Moose::Meta::Role::BEGIN@9
# spent 169µs making 1 call to Exporter::import |
| 10 | 3 | 266µs | 2 | 1.73ms | # spent 886µs (41+845) within Moose::Meta::Role::BEGIN@10 which was called:
# once (41µs+845µs) by Moose::BEGIN@27 at line 10 # spent 886µs making 1 call to Moose::Meta::Role::BEGIN@10
# spent 845µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 11 | |||||
| 12 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 13 | 1 | 76µ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 | 29µs | # spent 29µs within Moose::Meta::Role::BEGIN@16 which was called:
# once (29µs+0s) by Moose::BEGIN@27 at line 16 # spent 29µs making 1 call to Moose::Meta::Role::BEGIN@16 |
| 17 | 3 | 505µs | 1 | 13.5ms | # spent 13.5ms (2.43+11.1) within Moose::Meta::Role::BEGIN@17 which was called:
# once (2.43ms+11.1ms) by Moose::BEGIN@27 at line 17 # spent 13.5ms making 1 call to Moose::Meta::Role::BEGIN@17 |
| 18 | 3 | 493µs | 1 | 1.50ms | # spent 1.50ms (993µs+509µs) within Moose::Meta::Role::BEGIN@18 which was called:
# once (993µs+509µs) by Moose::BEGIN@27 at line 18 # spent 1.50ms making 1 call to Moose::Meta::Role::BEGIN@18 |
| 19 | 3 | 478µs | 1 | 7.18ms | # spent 7.18ms (1.24+5.93) within Moose::Meta::Role::BEGIN@19 which was called:
# once (1.24ms+5.93ms) by Moose::BEGIN@27 at line 19 # spent 7.18ms making 1 call to Moose::Meta::Role::BEGIN@19 |
| 20 | 3 | 546µs | 1 | 6.44ms | # spent 6.44ms (1.20+5.24) within Moose::Meta::Role::BEGIN@20 which was called:
# once (1.20ms+5.24ms) by Moose::BEGIN@27 at line 20 # spent 6.44ms making 1 call to Moose::Meta::Role::BEGIN@20 |
| 21 | 3 | 101µs | 1 | 29µs | # spent 29µs within Moose::Meta::Role::BEGIN@21 which was called:
# once (29µs+0s) by Moose::BEGIN@27 at line 21 # spent 29µs making 1 call to Moose::Meta::Role::BEGIN@21 |
| 22 | 3 | 130µs | 2 | 1.68ms | # spent 859µs (38+821) within Moose::Meta::Role::BEGIN@22 which was called:
# once (38µs+821µs) by Moose::BEGIN@27 at line 22 # spent 859µs making 1 call to Moose::Meta::Role::BEGIN@22
# spent 821µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 23 | 3 | 110µs | 1 | 26µs | # spent 26µs within Moose::Meta::Role::BEGIN@23 which was called:
# once (26µs+0s) by Moose::BEGIN@27 at line 23 # spent 26µs making 1 call to Moose::Meta::Role::BEGIN@23 |
| 24 | |||||
| 25 | 1 | 603µs | # spent 641µs (38+603) within Moose::Meta::Role::BEGIN@25 which was called:
# once (38µs+603µs) by Moose::BEGIN@27 at line 27 # spent 603µs making 1 call to base::import | ||
| 26 | 'Class::MOP::Mixin::HasAttributes', | ||||
| 27 | 3 | 8.47ms | 1 | 641µs | 'Class::MOP::Mixin::HasMethods'; # spent 641µs making 1 call to Moose::Meta::Role::BEGIN@25 |
| 28 | |||||
| 29 | 1 | 16µs | 1 | 6.73ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 6.73ms 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 | 18 | 214µs | my $attr_reader = $action->{attr_reader}; | ||
| 84 | my $methods = $action->{methods}; | ||||
| 85 | |||||
| 86 | # create the attribute | ||||
| 87 | $META->add_attribute($action->{name} => ( | ||||
| 88 | reader => $attr_reader, | ||||
| 89 | 76 | 917µs | # spent 678µs within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:89] which was called 76 times, avg 9µs/call:
# 35 times (317µs+0s) by Moose::Meta::Role::_new at line 111 of generated method (unknown origin), avg 9µs/call
# 35 times (309µs+0s) by Moose::Meta::Role::_new at line 81 of generated method (unknown origin), avg 9µs/call
# 3 times (27µs+0s) by Moose::Meta::Role::Composite::_new at line 87 of generated method (unknown origin), avg 9µs/call
# 3 times (24µs+0s) by Moose::Meta::Role::Composite::_new at line 120 of generated method (unknown origin), avg 8µs/call | ||
| 90 | 2 | 4.13ms | )); # spent 4.13ms making 2 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.07ms/call | ||
| 91 | |||||
| 92 | # create some helper methods | ||||
| 93 | $META->add_method($methods->{add} => sub { | ||||
| 94 | 9 | 70µs | my ($self, @values) = @_; | ||
| 95 | $self->$attr_reader->{$_} = undef foreach @values; | ||||
| 96 | 1 | 279µs | }) if exists $methods->{add}; # spent 279µs making 1 call to Class::MOP::Mixin::HasMethods::add_method | ||
| 97 | |||||
| 98 | $META->add_method($methods->{get_keys} => sub { | ||||
| 99 | 96 | 1.32ms | my ($self) = @_; | ||
| 100 | 48 | 590µs | keys %{$self->$attr_reader}; # spent 590µs making 48 calls to Moose::Meta::Role::get_excluded_roles_map, avg 12µs/call | ||
| 101 | 1 | 264µs | }) if exists $methods->{get_keys}; # spent 264µs making 1 call to Class::MOP::Mixin::HasMethods::add_method | ||
| 102 | |||||
| 103 | $META->add_method($methods->{get_values} => sub { | ||||
| 104 | 96 | 1.34ms | my ($self) = @_; | ||
| 105 | 48 | 616µs | values %{$self->$attr_reader}; # spent 616µs making 48 calls to Moose::Meta::Role::get_required_methods_map, avg 13µs/call | ||
| 106 | 1 | 300µs | }) if exists $methods->{get_values}; # spent 300µ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 | }) if exists $methods->{get}; | ||||
| 112 | |||||
| 113 | $META->add_method($methods->{existence} => sub { | ||||
| 114 | 36 | 550µs | my ($self, $name) = @_; | ||
| 115 | 18 | 274µs | exists $self->$attr_reader->{$name} ? 1 : 0; # spent 274µs making 18 calls to Moose::Meta::Role::get_excluded_roles_map, avg 15µs/call | ||
| 116 | 2 | 532µs | }) if exists $methods->{existence}; # spent 532µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 266µs/call | ||
| 117 | |||||
| 118 | $META->add_method($methods->{remove} => sub { | ||||
| 119 | my ($self, @values) = @_; | ||||
| 120 | delete $self->$attr_reader->{$_} foreach @values; | ||||
| 121 | 1 | 261µs | }) if exists $methods->{remove}; # spent 261µs making 1 call to Class::MOP::Mixin::HasMethods::add_method | ||
| 122 | } | ||||
| 123 | |||||
| 124 | $META->add_attribute( | ||||
| 125 | 1 | 13µs | 1 | 1.91ms | 'method_metaclass', # spent 1.91ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 126 | reader => 'method_metaclass', | ||||
| 127 | default => 'Moose::Meta::Role::Method', | ||||
| 128 | ); | ||||
| 129 | |||||
| 130 | 1 | 13µs | 1 | 1.98ms | $META->add_attribute( # spent 1.98ms 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 | 1.93ms | $META->add_attribute( # spent 1.93ms 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 | 1.99ms | $META->add_attribute( # spent 1.99ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 143 | 'application_to_class_class', | ||||
| 144 | reader => 'application_to_class_class', | ||||
| 145 | default => 'Moose::Meta::Role::Application::ToClass', | ||||
| 146 | ); | ||||
| 147 | |||||
| 148 | 1 | 13µs | 1 | 1.95ms | $META->add_attribute( # spent 1.95ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 149 | 'application_to_role_class', | ||||
| 150 | reader => 'application_to_role_class', | ||||
| 151 | default => 'Moose::Meta::Role::Application::ToRole', | ||||
| 152 | ); | ||||
| 153 | |||||
| 154 | 1 | 13µs | 1 | 1.97ms | $META->add_attribute( # spent 1.97ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 155 | 'application_to_instance_class', | ||||
| 156 | reader => 'application_to_instance_class', | ||||
| 157 | default => 'Moose::Meta::Role::Application::ToInstance', | ||||
| 158 | ); | ||||
| 159 | |||||
| 160 | 1 | 14µs | 1 | 1.89ms | $META->add_attribute( # spent 1.89ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 161 | 'applied_attribute_metaclass', | ||||
| 162 | reader => 'applied_attribute_metaclass', | ||||
| 163 | default => 'Moose::Meta::Attribute', | ||||
| 164 | ); | ||||
| 165 | |||||
| 166 | # More or less copied from Moose::Meta::Class | ||||
| 167 | # spent 25.5ms (2.51+23.0) within Moose::Meta::Role::initialize which was called 35 times, avg 728µs/call:
# 35 times (2.51ms+23.0ms) by Moose::Role::init_meta at line 131 of Moose/Role.pm, avg 728µs/call | ||||
| 168 | 245 | 2.37ms | my $class = shift; | ||
| 169 | my $pkg = shift; | ||||
| 170 | |||||
| 171 | 35 | 340µs | if (defined(my $meta = Class::MOP::get_metaclass_by_name($pkg))) { # spent 340µs making 35 calls to Class::MOP::get_metaclass_by_name, avg 10µs/call | ||
| 172 | return $meta; | ||||
| 173 | } | ||||
| 174 | |||||
| 175 | my %options = @_; | ||||
| 176 | |||||
| 177 | 35 | 22.6ms | my $meta = $class->SUPER::initialize( # spent 22.6ms making 35 calls to Class::MOP::Package::initialize, avg 646µs/call | ||
| 178 | $pkg, | ||||
| 179 | 'attribute_metaclass' => 'Moose::Meta::Role::Attribute', | ||||
| 180 | %options, | ||||
| 181 | ); | ||||
| 182 | |||||
| 183 | Class::MOP::weaken_metaclass($pkg) if $options{weaken}; | ||||
| 184 | |||||
| 185 | return $meta; | ||||
| 186 | } | ||||
| 187 | |||||
| 188 | sub reinitialize { | ||||
| 189 | my $self = shift; | ||||
| 190 | my $pkg = shift; | ||||
| 191 | |||||
| 192 | my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg); | ||||
| 193 | |||||
| 194 | my %existing_classes; | ||||
| 195 | if ($meta) { | ||||
| 196 | %existing_classes = map { $_ => $meta->$_() } qw( | ||||
| 197 | attribute_metaclass | ||||
| 198 | method_metaclass | ||||
| 199 | wrapped_method_metaclass | ||||
| 200 | required_method_metaclass | ||||
| 201 | conflicting_method_metaclass | ||||
| 202 | application_to_class_class | ||||
| 203 | application_to_role_class | ||||
| 204 | application_to_instance_class | ||||
| 205 | applied_attribute_metaclass | ||||
| 206 | ); | ||||
| 207 | } | ||||
| 208 | |||||
| 209 | my %options = @_; | ||||
| 210 | $options{weaken} = Class::MOP::metaclass_is_weak($meta->name) | ||||
| 211 | if !exists $options{weaken} | ||||
| 212 | && blessed($meta) | ||||
| 213 | && $meta->isa('Moose::Meta::Role'); | ||||
| 214 | |||||
| 215 | # don't need to remove generated metaobjects here yet, since we don't | ||||
| 216 | # yet generate anything in roles. this may change in the future though... | ||||
| 217 | # keep an eye on that | ||||
| 218 | my $new_meta = $self->SUPER::reinitialize( | ||||
| 219 | $pkg, | ||||
| 220 | %existing_classes, | ||||
| 221 | %options, | ||||
| 222 | ); | ||||
| 223 | $new_meta->_restore_metaobjects_from($meta) | ||||
| 224 | if $meta && $meta->isa('Moose::Meta::Role'); | ||||
| 225 | return $new_meta; | ||||
| 226 | } | ||||
| 227 | |||||
| 228 | sub _restore_metaobjects_from { | ||||
| 229 | my $self = shift; | ||||
| 230 | my ($old_meta) = @_; | ||||
| 231 | |||||
| 232 | $self->_restore_metamethods_from($old_meta); | ||||
| 233 | $self->_restore_metaattributes_from($old_meta); | ||||
| 234 | } | ||||
| 235 | |||||
| 236 | # spent 6.64ms (1.12+5.52) within Moose::Meta::Role::add_attribute which was called 15 times, avg 443µs/call:
# 7 times (529µs+2.88ms) by Moose::Role::has at line 47 of Moose/Role.pm, avg 487µs/call
# 6 times (444µs+1.94ms) by Moose::Meta::Role::Application::ToRole::apply_attributes at line 71 of Moose/Meta/Role/Application/ToRole.pm, avg 397µs/call
# 2 times (145µs+711µs) by Moose::Meta::Role::Application::RoleSummation::apply_attributes at line 148 of Moose/Meta/Role/Application/RoleSummation.pm, avg 428µs/call | ||||
| 237 | 45 | 1.36ms | my $self = shift; | ||
| 238 | |||||
| 239 | 45 | 247µs | if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) { # spent 154µs making 30 calls to Scalar::Util::blessed, avg 5µs/call
# spent 54µs making 8 calls to UNIVERSAL::isa, avg 7µs/call
# spent 40µs making 7 calls to Moose::Meta::Role::CORE:match, avg 6µs/call | ||
| 240 | my $class = ref $_[0]; | ||||
| 241 | Moose->throw_error( "Cannot add a $class as an attribute to a role" ); | ||||
| 242 | } | ||||
| 243 | elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) { | ||||
| 244 | Moose->throw_error( "has '+attr' is not supported in roles" ); | ||||
| 245 | } | ||||
| 246 | |||||
| 247 | 15 | 5.28ms | return $self->SUPER::add_attribute(@_); # spent 5.28ms making 15 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 352µs/call | ||
| 248 | } | ||||
| 249 | |||||
| 250 | # spent 1.29ms (336µs+953µs) within Moose::Meta::Role::_attach_attribute which was called 15 times, avg 86µs/call:
# 15 times (336µs+953µs) by Class::MOP::Mixin::HasAttributes::add_attribute at line 25 of Class/MOP/Mixin/HasAttributes.pm, avg 86µs/call | ||||
| 251 | 30 | 334µs | my ( $self, $attribute ) = @_; | ||
| 252 | |||||
| 253 | 15 | 954µs | $attribute->attach_to_role($self); # spent 954µs making 15 calls to Moose::Meta::Role::Attribute::attach_to_role, avg 64µs/call | ||
| 254 | } | ||||
| 255 | |||||
| 256 | # spent 12.4ms (4.98+7.41) within Moose::Meta::Role::add_required_methods which was called 27 times, avg 459µs/call:
# 15 times (3.92ms+6.81ms) by Moose::Role::requires at line 32 of Moose/Role.pm, avg 715µs/call
# 8 times (494µs+246µs) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 92µs/call
# 3 times (484µs+318µs) by Moose::Meta::Role::Application::RoleSummation::check_required_methods at line 109 of Moose/Meta/Role/Application/RoleSummation.pm, avg 267µs/call
# once (85µs+39µs) by Moose::Meta::Role::add_conflicting_method at line 281 | ||||
| 257 | 54 | 506µs | my $self = shift; | ||
| 258 | |||||
| 259 | for (@_) { | ||||
| 260 | 207 | 4.25ms | my $method = $_; | ||
| 261 | 171 | 5.66ms | if (!blessed($method)) { # spent 4.65ms making 51 calls to Moose::Meta::Role::Method::Required::new, avg 91µs/call
# spent 655µs making 51 calls to Moose::Meta::Role::required_method_metaclass, avg 13µs/call
# spent 358µs making 69 calls to Scalar::Util::blessed, avg 5µs/call | ||
| 262 | $method = $self->required_method_metaclass->new( | ||||
| 263 | name => $method, | ||||
| 264 | ); | ||||
| 265 | } | ||||
| 266 | 138 | 1.75ms | $self->get_required_methods_map->{$method->name} = $method; # spent 884µs making 69 calls to Moose::Meta::Role::get_required_methods_map, avg 13µs/call
# spent 866µs making 69 calls to Moose::Meta::Role::Method::Required::name, avg 13µs/call | ||
| 267 | } | ||||
| 268 | } | ||||
| 269 | |||||
| 270 | # spent 943µs (128+815) within Moose::Meta::Role::add_conflicting_method which was called:
# once (128µs+815µs) by Moose::Meta::Role::Application::RoleSummation::apply_methods at line 186 of Moose/Meta/Role/Application/RoleSummation.pm | ||||
| 271 | 4 | 45µs | my $self = shift; | ||
| 272 | |||||
| 273 | my $method; | ||||
| 274 | 1 | 63µs | if (@_ == 1 && blessed($_[0])) { | ||
| 275 | $method = shift; | ||||
| 276 | } | ||||
| 277 | else { | ||||
| 278 | 2 | 691µs | $method = $self->conflicting_method_metaclass->new(@_); # spent 668µs making 1 call to Moose::Meta::Role::Method::Required::new
# spent 23µs making 1 call to Moose::Meta::Role::conflicting_method_metaclass | ||
| 279 | } | ||||
| 280 | |||||
| 281 | 1 | 124µs | $self->add_required_methods($method); # spent 124µs making 1 call to Moose::Meta::Role::add_required_methods | ||
| 282 | } | ||||
| 283 | |||||
| 284 | ## ------------------------------------------------------------------ | ||||
| 285 | ## method modifiers | ||||
| 286 | |||||
| 287 | # NOTE: | ||||
| 288 | # the before/around/after method modifiers are | ||||
| 289 | # stored by name, but there can be many methods | ||||
| 290 | # then associated with that name. So again we have | ||||
| 291 | # lots of similar functionality, so we can do some | ||||
| 292 | # meta-programmin' and save some time. | ||||
| 293 | # - SL | ||||
| 294 | |||||
| 295 | 1 | 7µs | foreach my $modifier_type (qw[ before around after ]) { | ||
| 296 | |||||
| 297 | 15 | 327µs | my $attr_reader = "get_${modifier_type}_method_modifiers_map"; | ||
| 298 | |||||
| 299 | # create the attribute ... | ||||
| 300 | $META->add_attribute("${modifier_type}_method_modifiers" => ( | ||||
| 301 | reader => $attr_reader, | ||||
| 302 | 114 | 1.31ms | # spent 1.01ms within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:302] which was called 114 times, avg 9µs/call:
# 38 times (368µs+0s) by Moose::Meta::Role::Composite::_new or Moose::Meta::Role::_new at line 18 of generated method (unknown origin), avg 10µs/call
# 35 times (298µs+0s) by Moose::Meta::Role::_new at line 69 of generated method (unknown origin), avg 9µs/call
# 35 times (290µs+0s) by Moose::Meta::Role::_new at line 48 of generated method (unknown origin), avg 8µs/call
# 3 times (29µs+0s) by Moose::Meta::Role::Composite::_new at line 75 of generated method (unknown origin), avg 10µs/call
# 3 times (25µs+0s) by Moose::Meta::Role::Composite::_new at line 54 of generated method (unknown origin), avg 8µs/call | ||
| 303 | 3 | 6.08ms | )); # spent 6.08ms making 3 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.03ms/call | ||
| 304 | |||||
| 305 | # and some helper methods ... | ||||
| 306 | $META->add_method("get_${modifier_type}_method_modifiers" => sub { | ||||
| 307 | 156 | 1.67ms | my ($self, $method_name) = @_; | ||
| 308 | #return () unless exists $self->$attr_reader->{$method_name}; | ||||
| 309 | 52 | 576µs | my $mm = $self->$attr_reader->{$method_name}; # spent 437µs making 40 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 93µs making 8 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 12µs/call
# spent 46µs making 4 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 12µs/call | ||
| 310 | $mm ? @$mm : (); | ||||
| 311 | 3 | 882µs | }); # spent 882µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 294µs/call | ||
| 312 | |||||
| 313 | $META->add_method("has_${modifier_type}_method_modifiers" => sub { | ||||
| 314 | my ($self, $method_name) = @_; | ||||
| 315 | # NOTE: | ||||
| 316 | # for now we assume that if it exists,.. | ||||
| 317 | # it has at least one modifier in it | ||||
| 318 | (exists $self->$attr_reader->{$method_name}) ? 1 : 0; | ||||
| 319 | 3 | 925µs | }); # spent 925µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 308µs/call | ||
| 320 | |||||
| 321 | $META->add_method("add_${modifier_type}_method_modifier" => sub { | ||||
| 322 | 200 | 2.45ms | my ($self, $method_name, $method) = @_; | ||
| 323 | |||||
| 324 | 80 | 860µs | $self->$attr_reader->{$method_name} = [] # spent 668µs making 62 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 126µ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 | ||
| 325 | unless exists $self->$attr_reader->{$method_name}; | ||||
| 326 | |||||
| 327 | 40 | 421µs | my $modifiers = $self->$attr_reader->{$method_name}; # spent 329µs making 31 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call
# spent 61µs making 6 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 10µs/call
# spent 31µs making 3 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 10µs/call | ||
| 328 | |||||
| 329 | # NOTE: | ||||
| 330 | # check to see that we aren't adding the | ||||
| 331 | # same code twice. We err in favor of the | ||||
| 332 | # first on here, this may not be as expected | ||||
| 333 | foreach my $modifier (@{$modifiers}) { | ||||
| 334 | return if $modifier == $method; | ||||
| 335 | } | ||||
| 336 | |||||
| 337 | push @{$modifiers} => $method; | ||||
| 338 | 3 | 811µs | }); # spent 811µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 270µs/call | ||
| 339 | |||||
| 340 | } | ||||
| 341 | |||||
| 342 | ## ------------------------------------------------------------------ | ||||
| 343 | ## override method mofidiers | ||||
| 344 | |||||
| 345 | $META->add_attribute('override_method_modifiers' => ( | ||||
| 346 | reader => 'get_override_method_modifiers_map', | ||||
| 347 | 38 | 520µs | # spent 379µs within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:347] which was called 38 times, avg 10µs/call:
# 35 times (352µs+0s) by Moose::Meta::Role::_new at line 96 of generated method (unknown origin), avg 10µs/call
# 3 times (27µs+0s) by Moose::Meta::Role::Composite::_new at line 105 of generated method (unknown origin), avg 9µs/call | ||
| 348 | 1 | 18µs | 1 | 2.07ms | )); # spent 2.07ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 349 | |||||
| 350 | # NOTE: | ||||
| 351 | # these are a little different because there | ||||
| 352 | # can only be one per name, whereas the other | ||||
| 353 | # method modifiers can have multiples. | ||||
| 354 | # - SL | ||||
| 355 | |||||
| 356 | # spent 5.44ms (1.25+4.19) within Moose::Meta::Role::add_override_method_modifier which was called 30 times, avg 181µs/call:
# 24 times (944µs+3.53ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 187µs/call
# 3 times (158µs+523µs) by Moose::Role::override at line 77 of Moose/Role.pm, avg 227µs/call
# 3 times (151µs+131µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 237 of Moose/Meta/Role/Application/RoleSummation.pm, avg 94µs/call | ||||
| 357 | 90 | 1.13ms | my ($self, $method_name, $method) = @_; | ||
| 358 | 30 | 3.85ms | (!$self->has_method($method_name)) # spent 3.75ms making 27 calls to Class::MOP::Mixin::HasMethods::has_method, avg 139µs/call
# spent 97µs making 3 calls to Moose::Meta::Role::Composite::has_method, avg 32µs/call | ||
| 359 | || Moose->throw_error("Cannot add an override of method '$method_name' " . | ||||
| 360 | "because there is a local version of '$method_name'"); | ||||
| 361 | 30 | 344µs | $self->get_override_method_modifiers_map->{$method_name} = $method; # spent 344µs making 30 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call | ||
| 362 | } | ||||
| 363 | |||||
| 364 | # spent 878µs (626+252) within Moose::Meta::Role::has_override_method_modifier which was called 24 times, avg 37µs/call:
# 24 times (626µs+252µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 152 of Moose/Meta/Role/Application/ToRole.pm, avg 37µs/call | ||||
| 365 | 48 | 570µs | my ($self, $method_name) = @_; | ||
| 366 | # NOTE: | ||||
| 367 | # for now we assume that if it exists,.. | ||||
| 368 | # it has at least one modifier in it | ||||
| 369 | 24 | 252µs | (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0; # spent 252µs making 24 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 10µs/call | ||
| 370 | } | ||||
| 371 | |||||
| 372 | # spent 1.54ms (1.09+446µs) within Moose::Meta::Role::get_override_method_modifier which was called 42 times, avg 37µs/call:
# 24 times (587µs+235µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 34µs/call
# 15 times (429µs+182µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 205 of Moose/Meta/Role/Application/ToClass.pm, avg 41µs/call
# 3 times (75µs+29µ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 | ||||
| 373 | 84 | 1.01ms | my ($self, $method_name) = @_; | ||
| 374 | 42 | 446µs | $self->get_override_method_modifiers_map->{$method_name}; # spent 446µs making 42 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call | ||
| 375 | } | ||||
| 376 | |||||
| 377 | ## general list accessor ... | ||||
| 378 | |||||
| 379 | # spent 8.43ms (5.94+2.49) within Moose::Meta::Role::get_method_modifier_list which was called 192 times, avg 44µs/call:
# 63 times (1.92ms+825µs) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 217 of Moose/Meta/Role/Application/ToClass.pm, avg 44µs/call
# 54 times (1.58ms+673µs) by Moose::Meta::Role::Application::ToRole::apply_method_modifiers at line 176 of Moose/Meta/Role/Application/ToRole.pm, avg 42µs/call
# 27 times (763µs+360µs) by Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers at line 246 of Moose/Meta/Role/Application/RoleSummation.pm, avg 42µs/call
# 21 times (738µs+279µ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
# 18 times (652µs+242µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 136 of Moose/Meta/Role/Application/ToRole.pm, avg 50µs/call
# 9 times (281µs+108µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 209 of Moose/Meta/Role/Application/RoleSummation.pm, avg 43µs/call | ||||
| 380 | 576 | 5.89ms | my ($self, $modifier_type) = @_; | ||
| 381 | my $accessor = "get_${modifier_type}_method_modifiers_map"; | ||||
| 382 | 192 | 2.49ms | keys %{$self->$accessor}; # spent 661µs making 48 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 14µs/call
# spent 630µs making 48 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 13µs/call
# spent 599µs making 48 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 12µs/call
# spent 598µs making 48 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 12µs/call | ||
| 383 | } | ||||
| 384 | |||||
| 385 | 35 | 444µs | # spent 428µs within Moose::Meta::Role::_meta_method_class which was called 35 times, avg 12µs/call:
# 35 times (428µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 28 of Class/MOP/Mixin/HasMethods.pm, avg 12µs/call | ||
| 386 | |||||
| 387 | ## ------------------------------------------------------------------ | ||||
| 388 | ## subroles | ||||
| 389 | |||||
| 390 | $META->add_attribute('roles' => ( | ||||
| 391 | reader => 'get_roles', | ||||
| 392 | 35 | 421µs | # spent 374µs within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:392] which was called 35 times, avg 11µs/call:
# 35 times (374µs+0s) by Moose::Meta::Role::_new at line 117 of generated method (unknown origin), avg 11µs/call | ||
| 393 | 1 | 19µs | 1 | 2.03ms | )); # spent 2.03ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute |
| 394 | |||||
| 395 | # spent 1.87ms (1.19+683µs) within Moose::Meta::Role::add_role which was called 18 times, avg 104µs/call:
# 18 times (1.19ms+683µs) by Moose::Meta::Role::Application::ToRole::apply at line 18 of Moose/Meta/Role/Application/ToRole.pm, avg 104µs/call | ||||
| 396 | 72 | 1.38ms | my ($self, $role) = @_; | ||
| 397 | 36 | 244µs | (blessed($role) && $role->isa('Moose::Meta::Role')) # spent 134µs making 18 calls to Scalar::Util::blessed, avg 7µs/call
# spent 111µs making 18 calls to UNIVERSAL::isa, avg 6µs/call | ||
| 398 | || Moose->throw_error("Roles must be instances of Moose::Meta::Role"); | ||||
| 399 | 18 | 244µs | push @{$self->get_roles} => $role; # spent 244µs making 18 calls to Moose::Meta::Role::get_roles, avg 14µs/call | ||
| 400 | 18 | 195µs | $self->reset_package_cache_flag; # spent 195µs making 18 calls to Class::MOP::Mixin::HasMethods::reset_package_cache_flag, avg 11µs/call | ||
| 401 | } | ||||
| 402 | |||||
| 403 | # spent 367µs (290+78) within Moose::Meta::Role::calculate_all_roles which was called 4 times, avg 92µs/call:
# 2 times (192µs+175µs) by Moose::Meta::Class::calculate_all_roles at line 200 of Moose/Meta/Class.pm, avg 184µs/call
# 2 times (98µs+-98µs) by Moose::Meta::Role::calculate_all_roles at line 407, avg 0s/call | ||||
| 404 | 12 | 147µs | my $self = shift; | ||
| 405 | my %seen; | ||||
| 406 | 6 | 33µs | grep { # spent 33µs making 6 calls to Class::MOP::Package::name, avg 6µs/call | ||
| 407 | 2 | 0s | !$seen{$_->name}++ # spent 132µs making 2 calls to Moose::Meta::Role::calculate_all_roles, avg 66µs/call, recursion: max depth 1, sum of overlapping time 132µs | ||
| 408 | } ($self, map { | ||||
| 409 | $_->calculate_all_roles | ||||
| 410 | 8 | 166µs | 4 | 44µs | } @{ $self->get_roles }); # spent 44µ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 | 57 | 1.08ms | 57 | 14.8ms | # spent 15.9ms (1.17+14.8) within Moose::Meta::Role::find_method_by_name which was called 57 times, avg 279µs/call:
# 35 times (702µs+4.46ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 23 of Class/MOP/Mixin/HasMethods.pm, avg 147µs/call
# 22 times (464µs+10.3ms) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 489µs/call # spent 14.8ms making 57 calls to Class::MOP::Mixin::HasMethods::get_method, avg 259µs/call |
| 428 | |||||
| 429 | ## ------------------------------------------------------------------ | ||||
| 430 | ## role construction | ||||
| 431 | ## ------------------------------------------------------------------ | ||||
| 432 | |||||
| 433 | # spent 609ms (4.82+605) within Moose::Meta::Role::apply which was called 39 times, avg 15.6ms/call:
# 36 times (4.43ms+537ms) by Moose::Util::_apply_all_roles at line 137 of Moose/Util.pm, avg 15.0ms/call
# 3 times (387µs+67.6ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 22.7ms/call | ||||
| 434 | 429 | 5.21ms | my ($self, $other, %args) = @_; | ||
| 435 | |||||
| 436 | 39 | 223µs | (blessed($other)) # spent 223µs making 39 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 | 99 | 1.11ms | if ($other->isa('Moose::Meta::Role')) { # spent 431µs making 60 calls to UNIVERSAL::isa, avg 7µs/call
# spent 346µs making 21 calls to Moose::Meta::Role::application_to_class_class, avg 16µs/call
# spent 332µs making 18 calls to Moose::Meta::Role::application_to_role_class, avg 18µ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 | 39 | 4.00ms | Class::MOP::load_class($application_class); # spent 9.15ms making 39 calls to Class::MOP::load_class, avg 235µs/call, recursion: max depth 3, sum of overlapping time 5.15ms | ||
| 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 | 78 | 594ms | return $application_class->new(%args)->apply($self, $other, \%args); # spent 379ms making 21 calls to Moose::Meta::Role::Application::ToClass::apply, avg 18.1ms/call
# spent 209ms making 18 calls to Moose::Meta::Role::Application::ToRole::apply, avg 11.6ms/call
# spent 5.92ms making 39 calls to Moose::Meta::Role::Application::new, avg 152µs/call | ||
| 484 | } | ||||
| 485 | |||||
| 486 | 9 | 91µs | # spent 57µs within Moose::Meta::Role::composition_class_roles which was called 9 times, avg 6µs/call:
# 9 times (57µs+0s) by Moose::Meta::Role::Composite::new at line 50 of Moose/Meta/Role/Composite.pm, avg 6µs/call | ||
| 487 | |||||
| 488 | # spent 75.2ms (621µs+74.6) within Moose::Meta::Role::combine which was called 3 times, avg 25.1ms/call:
# 3 times (621µs+74.6ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 25.1ms/call | ||||
| 489 | 18 | 229µs | my ($class, @role_specs) = @_; | ||
| 490 | |||||
| 491 | require Moose::Meta::Role::Composite; | ||||
| 492 | |||||
| 493 | my (@roles, %role_params); | ||||
| 494 | while (@role_specs) { | ||||
| 495 | 47 | 416µs | my ($role, $params) = @{ splice @role_specs, 0, 1 }; | ||
| 496 | 9 | 51µs | my $requested_role # spent 51µs making 9 calls to Scalar::Util::blessed, avg 6µs/call | ||
| 497 | = blessed $role | ||||
| 498 | ? $role | ||||
| 499 | : Class::MOP::class_of($role); | ||||
| 500 | |||||
| 501 | 9 | 97µs | my $actual_role = $requested_role->_role_for_combination($params); # spent 97µs making 9 calls to Moose::Meta::Role::_role_for_combination, avg 11µs/call | ||
| 502 | push @roles => $actual_role; | ||||
| 503 | |||||
| 504 | next unless defined $params; | ||||
| 505 | 2 | 17µs | $role_params{$actual_role->name} = $params; # spent 17µs making 2 calls to Class::MOP::Package::name, avg 8µs/call | ||
| 506 | } | ||||
| 507 | |||||
| 508 | 3 | 2.36ms | my $c = Moose::Meta::Role::Composite->new(roles => \@roles); # spent 2.36ms making 3 calls to Moose::Meta::Role::Composite::new, avg 787µs/call | ||
| 509 | 3 | 72.1ms | return $c->apply_params(\%role_params); # spent 72.1ms making 3 calls to Moose::Meta::Role::Composite::apply_params, avg 24.0ms/call | ||
| 510 | } | ||||
| 511 | |||||
| 512 | # spent 97µs within Moose::Meta::Role::_role_for_combination which was called 9 times, avg 11µs/call:
# 9 times (97µs+0s) by Moose::Meta::Role::combine at line 501, avg 11µs/call | ||||
| 513 | 18 | 130µs | my ($self, $params) = @_; | ||
| 514 | 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 | 3 | 11µ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 | my $ANON_ROLE_PREFIX = 'Moose::Meta::Role::__ANON__::SERIAL::'; | ||||
| 596 | |||||
| 597 | sub is_anon_role { | ||||
| 598 | my $self = shift; | ||||
| 599 | 3 | 442µs | 2 | 209µs | # spent 133µs (58+76) within Moose::Meta::Role::BEGIN@599 which was called:
# once (58µs+76µs) by Moose::BEGIN@27 at line 599 # spent 133µs making 1 call to Moose::Meta::Role::BEGIN@599
# spent 76µ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 | 224µs | 2 | 160µs | # spent 101µs (42+59) within Moose::Meta::Role::BEGIN@621 which was called:
# once (42µs+59µs) by Moose::BEGIN@27 at line 621 # spent 101µ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 | 553µs | 2 | 166µs | # spent 104µs (41+63) within Moose::Meta::Role::BEGIN@636 which was called:
# once (41µs+63µs) by Moose::BEGIN@27 at line 636 # spent 104µs making 1 call to Moose::Meta::Role::BEGIN@636
# spent 62µ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 | 138µs | 1; | ||
| 752 | |||||
| 753 | __END__ |