Profile of Moose/Meta/Role.pm

← Index
NYTProf Performance Profile «line view»
For script/ponapi
Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:11 2016

Filename | /usr/local/lib/perl/5.18.2/Moose/Meta/Role.pm
Statements | Executed 5454 statements in 16.6ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
444 | 6 | 3 | 1.63ms | 2.32ms | Moose::Meta::Role::::get_method_modifier_listMoose::Meta::Role::get_method_modifier_list
42 | 2 | 1 | 798µs | 378ms | Moose::Meta::Role::::applyMoose::Meta::Role::apply (recurses: max depth 1, inclusive time 29.3ms)
78 | 2 | 2 | 726µs | 926µs | Moose::Meta::Role::::calculate_all_rolesMoose::Meta::Role::calculate_all_roles (recurses: max depth 1, inclusive time 338µs)
1 | 1 | 1 | 656µs | 2.70ms | Moose::Meta::Role::::BEGIN@11Moose::Meta::Role::BEGIN@11
72 | 3 | 3 | 623µs | 3.51ms | Moose::Meta::Role::::add_attributeMoose::Meta::Role::add_attribute
19 | 1 | 1 | 553µs | 61.4ms | Moose::Meta::Role::::combineMoose::Meta::Role::combine
51 | 4 | 4 | 479µs | 900µs | Moose::Meta::Role::::add_required_methodsMoose::Meta::Role::add_required_methods
35 | 1 | 1 | 401µs | 3.94ms | Moose::Meta::Role::::initializeMoose::Meta::Role::initialize
54 | 3 | 3 | 238µs | 861µs | Moose::Meta::Role::::add_override_method_modifierMoose::Meta::Role::add_override_method_modifier
1 | 1 | 1 | 233µs | 6.10ms | Moose::Meta::Role::::BEGIN@14Moose::Meta::Role::BEGIN@14
1 | 1 | 1 | 231µs | 978µs | Moose::Meta::Role::::BEGIN@13Moose::Meta::Role::BEGIN@13
75 | 3 | 3 | 205µs | 256µs | Moose::Meta::Role::::get_override_method_modifierMoose::Meta::Role::get_override_method_modifier
162 | 6 | 1 | 201µs | 201µs | Moose::Meta::Role::::__ANON__[:305]Moose::Meta::Role::__ANON__[:305]
1 | 1 | 1 | 170µs | 229µs | Moose::Meta::Role::::BEGIN@12Moose::Meta::Role::BEGIN@12
72 | 1 | 1 | 162µs | 721µs | Moose::Meta::Role::::_attach_attributeMoose::Meta::Role::_attach_attribute
14 | 1 | 1 | 159µs | 232µs | Moose::Meta::Role::::add_roleMoose::Meta::Role::add_role
57 | 2 | 2 | 150µs | 1.87ms | Moose::Meta::Role::::find_method_by_nameMoose::Meta::Role::find_method_by_name
108 | 4 | 1 | 116µs | 116µs | Moose::Meta::Role::::__ANON__[:84]Moose::Meta::Role::__ANON__[:84]
36 | 1 | 1 | 98µs | 126µs | Moose::Meta::Role::::has_override_method_modifierMoose::Meta::Role::has_override_method_modifier
54 | 2 | 1 | 68µs | 68µs | Moose::Meta::Role::::__ANON__[:351]Moose::Meta::Role::__ANON__[:351]
69 | 1 | 1 | 60µs | 60µs | Moose::Meta::Role::::_role_for_combinationMoose::Meta::Role::_role_for_combination
35 | 1 | 1 | 53µs | 53µs | Moose::Meta::Role::::__ANON__[:398]Moose::Meta::Role::__ANON__[:398]
35 | 1 | 1 | 40µs | 40µs | Moose::Meta::Role::::_meta_method_classMoose::Meta::Role::_meta_method_class
4 | 1 | 1 | 38µs | 207µs | Moose::Meta::Role::::add_conflicting_methodMoose::Meta::Role::add_conflicting_method
69 | 1 | 1 | 36µs | 36µs | Moose::Meta::Role::::composition_class_rolesMoose::Meta::Role::composition_class_roles
1 | 1 | 1 | 23µs | 28µs | Moose::Meta::Role::::BEGIN@5Moose::Meta::Role::BEGIN@5
15 | 1 | 1 | 13µs | 13µs | Moose::Meta::Role::::CORE:matchMoose::Meta::Role::CORE:match (opcode)
1 | 1 | 1 | 9µs | 19µs | Moose::Meta::Role::::BEGIN@4Moose::Meta::Role::BEGIN@4
1 | 1 | 1 | 8µs | 40µs | Moose::Meta::Role::::BEGIN@8Moose::Meta::Role::BEGIN@8
1 | 1 | 1 | 7µs | 61µs | Moose::Meta::Role::::BEGIN@19Moose::Meta::Role::BEGIN@19
1 | 1 | 1 | 6µs | 158µs | Moose::Meta::Role::::BEGIN@16Moose::Meta::Role::BEGIN@16
1 | 1 | 1 | 6µs | 375µs | Moose::Meta::Role::::BEGIN@6Moose::Meta::Role::BEGIN@6
1 | 1 | 1 | 6µs | 6µs | Moose::Meta::Role::::BEGIN@15Moose::Meta::Role::BEGIN@15
1 | 1 | 1 | 5µs | 5µs | Moose::Meta::Role::::BEGIN@17Moose::Meta::Role::BEGIN@17
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::Role::::BEGIN@10Moose::Meta::Role::BEGIN@10
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:102]Moose::Meta::Role::__ANON__[:102]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:107]Moose::Meta::Role::__ANON__[:107]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:112]Moose::Meta::Role::__ANON__[:112]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:117]Moose::Meta::Role::__ANON__[:117]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:315]Moose::Meta::Role::__ANON__[:315]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:323]Moose::Meta::Role::__ANON__[:323]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:342]Moose::Meta::Role::__ANON__[:342]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:591]Moose::Meta::Role::__ANON__[:591]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:92]Moose::Meta::Role::__ANON__[:92]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::__ANON__[:97]Moose::Meta::Role::__ANON__[:97]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::_anon_cache_keyMoose::Meta::Role::_anon_cache_key
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::_anon_package_prefixMoose::Meta::Role::_anon_package_prefix
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::_restore_metaobjects_fromMoose::Meta::Role::_restore_metaobjects_from
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::consumersMoose::Meta::Role::consumers
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::createMoose::Meta::Role::create
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::create_anon_roleMoose::Meta::Role::create_anon_role
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::does_roleMoose::Meta::Role::does_role
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::is_anon_roleMoose::Meta::Role::is_anon_role
0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::::reinitializeMoose::Meta::Role::reinitialize

Call graph for these subroutines as a Graphviz dot language file.

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