Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/Class.pm |
Statements | Executed 313 statements in 3.02ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 459µs | 627µs | BEGIN@17 | Moose::Meta::Class::
1 | 1 | 1 | 227µs | 373µs | BEGIN@15 | Moose::Meta::Class::
1 | 1 | 1 | 213µs | 1.75ms | BEGIN@13 | Moose::Meta::Class::
1 | 1 | 1 | 213µs | 366µs | BEGIN@16 | Moose::Meta::Class::
1 | 1 | 1 | 210µs | 329µs | BEGIN@14 | Moose::Meta::Class::
1 | 1 | 1 | 146µs | 189µs | BEGIN@18 | Moose::Meta::Class::
1 | 1 | 1 | 77µs | 210µs | _eval_environment | Moose::Meta::Class::
4 | 1 | 1 | 60µs | 13.1ms | add_attribute | Moose::Meta::Class::
6 | 3 | 2 | 40µs | 577µs | superclasses (recurses: max depth 1, inclusive time 40µs) | Moose::Meta::Class::
4 | 1 | 1 | 34µs | 251µs | _inline_init_attr_from_default | Moose::Meta::Class::
4 | 1 | 1 | 32µs | 40µs | _inline_check_required_attr | Moose::Meta::Class::
1 | 1 | 1 | 28µs | 70µs | _inline_triggers | Moose::Meta::Class::
4 | 1 | 1 | 27µs | 4.21ms | _process_attribute | Moose::Meta::Class::
4 | 1 | 1 | 26µs | 359µs | _inline_init_attr_from_constructor | Moose::Meta::Class::
2 | 2 | 1 | 25µs | 34µs | _base_metaclasses | Moose::Meta::Class::
4 | 1 | 1 | 25µs | 4.18ms | _process_new_attribute | Moose::Meta::Class::
4 | 1 | 1 | 20µs | 711µs | _inline_slot_initializer | Moose::Meta::Class::
2 | 2 | 1 | 19µs | 22µs | CORE:sort (opcode) | Moose::Meta::Class::
2 | 2 | 2 | 19µs | 905µs | initialize | Moose::Meta::Class::
1 | 1 | 1 | 18µs | 175µs | _inline_BUILDARGS | Moose::Meta::Class::
1 | 1 | 1 | 14µs | 189µs | _inline_params | Moose::Meta::Class::
1 | 1 | 1 | 10µs | 11µs | BEGIN@4 | Moose::Meta::Class::
1 | 1 | 1 | 9µs | 40µs | BEGIN@9 | Moose::Meta::Class::
12 | 1 | 1 | 6µs | 6µs | CORE:subst (opcode) | Moose::Meta::Class::
1 | 1 | 1 | 6µs | 63µs | _inline_BUILDALL | Moose::Meta::Class::
1 | 1 | 1 | 6µs | 25µs | _immutable_options | Moose::Meta::Class::
1 | 1 | 1 | 6µs | 139µs | _inline_extra_init | Moose::Meta::Class::
2 | 2 | 1 | 5µs | 5µs | _inline_throw_exception | Moose::Meta::Class::
1 | 1 | 1 | 5µs | 20µs | BEGIN@11 | Moose::Meta::Class::
1 | 1 | 1 | 5µs | 165µs | BEGIN@10 | Moose::Meta::Class::
1 | 1 | 1 | 5µs | 86µs | BEGIN@19 | Moose::Meta::Class::
1 | 1 | 1 | 4µs | 7µs | BEGIN@5 | Moose::Meta::Class::
1 | 1 | 1 | 4µs | 9µs | BEGIN@8 | Moose::Meta::Class::
1 | 1 | 1 | 4µs | 21µs | BEGIN@22 | Moose::Meta::Class::
1 | 1 | 1 | 3µs | 3µs | BEGIN@20 | Moose::Meta::Class::
2 | 1 | 1 | 3µs | 3µs | __ANON__[:34] | Moose::Meta::Class::
2 | 1 | 1 | 2µs | 2µs | __ANON__[:28] | Moose::Meta::Class::
1 | 1 | 1 | 2µs | 2µs | _generate_fallback_constructor | Moose::Meta::Class::
2 | 1 | 1 | 2µs | 2µs | _meta_method_class | Moose::Meta::Class::
4 | 1 | 1 | 2µs | 2µs | CORE:match (opcode) | Moose::Meta::Class::
1 | 1 | 1 | 2µs | 2µs | BEGIN@7 | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:110] | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:535] | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _anon_cache_key | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _anon_package_prefix | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _call_all_triggers | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _find_next_method_by_name_which_is_not_overridden | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _fix_class_metaclass_incompatibility | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _fix_single_metaclass_incompatibility | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _fixup_attributes_after_rebless | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _process_inherited_attribute | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _replace_self | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _restore_metaobjects_from | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | _roles_with_inheritance | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | add_augment_method_modifier | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | add_override_method_modifier | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | add_role | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | add_role_application | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | calculate_all_roles | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | calculate_all_roles_with_inheritance | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | create | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | does_role | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | excludes_role | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | new_object | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | reinitialize | Moose::Meta::Class::
0 | 0 | 0 | 0s | 0s | role_applications | Moose::Meta::Class::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Class; | ||||
2 | 1 | 400ns | our $VERSION = '2.1605'; | ||
3 | |||||
4 | 2 | 14µs | 2 | 12µs | # spent 11µs (10+1) within Moose::Meta::Class::BEGIN@4 which was called:
# once (10µs+1µs) by Moose::BEGIN@24 at line 4 # spent 11µs making 1 call to Moose::Meta::Class::BEGIN@4
# spent 1µs making 1 call to strict::import |
5 | 2 | 11µs | 2 | 10µs | # spent 7µs (4+3) within Moose::Meta::Class::BEGIN@5 which was called:
# once (4µs+3µs) by Moose::BEGIN@24 at line 5 # spent 7µs making 1 call to Moose::Meta::Class::BEGIN@5
# spent 3µs making 1 call to warnings::import |
6 | |||||
7 | 2 | 11µs | 1 | 2µs | # spent 2µs within Moose::Meta::Class::BEGIN@7 which was called:
# once (2µs+0s) by Moose::BEGIN@24 at line 7 # spent 2µs making 1 call to Moose::Meta::Class::BEGIN@7 |
8 | 2 | 17µs | 2 | 14µs | # spent 9µs (4+5) within Moose::Meta::Class::BEGIN@8 which was called:
# once (4µs+5µs) by Moose::BEGIN@24 at line 8 # spent 9µs making 1 call to Moose::Meta::Class::BEGIN@8
# spent 5µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:270] |
9 | 3 | 26µs | 3 | 52µs | # spent 40µs (9+31) within Moose::Meta::Class::BEGIN@9 which was called:
# once (9µs+31µs) by Moose::BEGIN@24 at line 9 # spent 40µs making 1 call to Moose::Meta::Class::BEGIN@9
# spent 6µs making 1 call to UNIVERSAL::VERSION
# spent 6µs making 1 call to List::Util::import |
10 | 2 | 23µs | 2 | 324µs | # spent 165µs (5+160) within Moose::Meta::Class::BEGIN@10 which was called:
# once (5µs+160µs) by Moose::BEGIN@24 at line 10 # spent 165µs making 1 call to Moose::Meta::Class::BEGIN@10
# spent 160µs making 1 call to Exporter::Tiny::import |
11 | 2 | 15µs | 2 | 36µs | # spent 20µs (5+15) within Moose::Meta::Class::BEGIN@11 which was called:
# once (5µs+15µs) by Moose::BEGIN@24 at line 11 # spent 20µs making 1 call to Moose::Meta::Class::BEGIN@11
# spent 15µs making 1 call to Exporter::import |
12 | |||||
13 | 2 | 70µs | 1 | 1.75ms | # spent 1.75ms (213µs+1.54) within Moose::Meta::Class::BEGIN@13 which was called:
# once (213µs+1.54ms) by Moose::BEGIN@24 at line 13 # spent 1.75ms making 1 call to Moose::Meta::Class::BEGIN@13 |
14 | 2 | 66µs | 1 | 329µs | # spent 329µs (210+119) within Moose::Meta::Class::BEGIN@14 which was called:
# once (210µs+119µs) by Moose::BEGIN@24 at line 14 # spent 329µs making 1 call to Moose::Meta::Class::BEGIN@14 |
15 | 2 | 64µs | 1 | 373µs | # spent 373µs (227+146) within Moose::Meta::Class::BEGIN@15 which was called:
# once (227µs+146µs) by Moose::BEGIN@24 at line 15 # spent 373µs making 1 call to Moose::Meta::Class::BEGIN@15 |
16 | 2 | 73µs | 1 | 366µs | # spent 366µs (213+153) within Moose::Meta::Class::BEGIN@16 which was called:
# once (213µs+153µs) by Moose::BEGIN@24 at line 16 # spent 366µs making 1 call to Moose::Meta::Class::BEGIN@16 |
17 | 2 | 77µs | 1 | 627µs | # spent 627µs (459+168) within Moose::Meta::Class::BEGIN@17 which was called:
# once (459µs+168µs) by Moose::BEGIN@24 at line 17 # spent 627µs making 1 call to Moose::Meta::Class::BEGIN@17 |
18 | 2 | 62µs | 1 | 189µs | # spent 189µs (146+43) within Moose::Meta::Class::BEGIN@18 which was called:
# once (146µs+43µs) by Moose::BEGIN@24 at line 18 # spent 189µs making 1 call to Moose::Meta::Class::BEGIN@18 |
19 | 2 | 18µs | 2 | 167µs | # spent 86µs (5+81) within Moose::Meta::Class::BEGIN@19 which was called:
# once (5µs+81µs) by Moose::BEGIN@24 at line 19 # spent 86µs making 1 call to Moose::Meta::Class::BEGIN@19
# spent 81µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
20 | 2 | 13µs | 1 | 3µs | # spent 3µs within Moose::Meta::Class::BEGIN@20 which was called:
# once (3µs+0s) by Moose::BEGIN@24 at line 20 # spent 3µs making 1 call to Moose::Meta::Class::BEGIN@20 |
21 | |||||
22 | 2 | 1.92ms | 2 | 39µs | # spent 21µs (4+18) within Moose::Meta::Class::BEGIN@22 which was called:
# once (4µs+18µs) by Moose::BEGIN@24 at line 22 # spent 21µs making 1 call to Moose::Meta::Class::BEGIN@22
# spent 18µs making 1 call to parent::import |
23 | |||||
24 | 1 | 2µs | 1 | 5.25ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 5.25ms making 1 call to Class::MOP::MiniTrait::apply |
25 | |||||
26 | __PACKAGE__->meta->add_attribute('roles' => ( | ||||
27 | reader => 'roles', | ||||
28 | 2 | 4µs | # spent 2µs within Moose::Meta::Class::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/Class.pm:28] which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 40 of Class/MOP/Mixin/AttributeCore.pm, avg 1µs/call | ||
29 | 1 | 10µs | 3 | 318µs | Class::MOP::_definition_context(), # spent 304µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 8µs making 1 call to Class::MOP::Object::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
30 | )); | ||||
31 | |||||
32 | __PACKAGE__->meta->add_attribute('role_applications' => ( | ||||
33 | reader => '_get_role_applications', | ||||
34 | 2 | 4µs | # spent 3µs within Moose::Meta::Class::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/Class.pm:34] which was called 2 times, avg 1µs/call:
# 2 times (3µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 40 of Class/MOP/Mixin/AttributeCore.pm, avg 1µs/call | ||
35 | 1 | 3µs | 3 | 191µs | Class::MOP::_definition_context(), # spent 182µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Class::MOP::Object::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
36 | )); | ||||
37 | |||||
38 | 1 | 3µs | 4 | 190µs | __PACKAGE__->meta->add_attribute( # spent 170µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Class::MOP::Attribute::new
# spent 6µs making 1 call to Class::MOP::Object::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
39 | Class::MOP::Attribute->new('immutable_trait' => ( | ||||
40 | accessor => "immutable_trait", | ||||
41 | default => 'Moose::Meta::Class::Immutable::Trait', | ||||
42 | Class::MOP::_definition_context(), | ||||
43 | )) | ||||
44 | ); | ||||
45 | |||||
46 | 1 | 2µs | 3 | 173µs | __PACKAGE__->meta->add_attribute('constructor_class' => ( # spent 165µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Class::MOP::Object::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
47 | accessor => 'constructor_class', | ||||
48 | default => 'Moose::Meta::Method::Constructor', | ||||
49 | Class::MOP::_definition_context(), | ||||
50 | )); | ||||
51 | |||||
52 | 1 | 2µs | 3 | 177µs | __PACKAGE__->meta->add_attribute('destructor_class' => ( # spent 169µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 5µs making 1 call to Class::MOP::Object::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
53 | accessor => 'destructor_class', | ||||
54 | default => 'Moose::Meta::Method::Destructor', | ||||
55 | Class::MOP::_definition_context(), | ||||
56 | )); | ||||
57 | |||||
58 | # spent 905µs (19+886) within Moose::Meta::Class::initialize which was called 2 times, avg 453µs/call:
# once (10µs+483µs) by metaclass::import at line 38 of metaclass.pm
# once (9µs+403µs) by Moose::init_meta at line 203 of Moose.pm | ||||
59 | 2 | 800ns | my $class = shift; | ||
60 | 2 | 1µs | my @args = @_; | ||
61 | 2 | 2µs | unshift @args, 'package' if @args % 2; | ||
62 | 2 | 2µs | my %opts = @args; | ||
63 | 2 | 1µs | my $package = delete $opts{package}; | ||
64 | 2 | 13µs | 4 | 886µs | return Class::MOP::get_metaclass_by_name($package) # spent 884µs making 2 calls to Class::MOP::Class::initialize, avg 442µs/call
# spent 1µs making 2 calls to Class::MOP::get_metaclass_by_name, avg 700ns/call |
65 | || $class->SUPER::initialize($package, | ||||
66 | 'attribute_metaclass' => 'Moose::Meta::Attribute', | ||||
67 | 'method_metaclass' => 'Moose::Meta::Method', | ||||
68 | 'instance_metaclass' => 'Moose::Meta::Instance', | ||||
69 | %opts, | ||||
70 | ); | ||||
71 | } | ||||
72 | |||||
73 | sub create { | ||||
74 | my $class = shift; | ||||
75 | my @args = @_; | ||||
76 | |||||
77 | unshift @args, 'package' if @args % 2 == 1; | ||||
78 | my %options = @args; | ||||
79 | |||||
80 | (ref $options{roles} eq 'ARRAY') | ||||
81 | || throw_exception( RolesInCreateTakesAnArrayRef => params => \%options ) | ||||
82 | if exists $options{roles}; | ||||
83 | |||||
84 | my $package = delete $options{package}; | ||||
85 | my $roles = delete $options{roles}; | ||||
86 | |||||
87 | my $new_meta = $class->SUPER::create($package, %options); | ||||
88 | |||||
89 | if ($roles) { | ||||
90 | Moose::Util::apply_all_roles( $new_meta, @$roles ); | ||||
91 | } | ||||
92 | |||||
93 | return $new_meta; | ||||
94 | } | ||||
95 | |||||
96 | 2 | 4µs | # spent 2µs within Moose::Meta::Class::_meta_method_class which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 24 of Class/MOP/Mixin/HasMethods.pm, avg 1µs/call | ||
97 | |||||
98 | sub _anon_package_prefix { 'Moose::Meta::Class::__ANON__::SERIAL::' } | ||||
99 | |||||
100 | sub _anon_cache_key { | ||||
101 | my $class = shift; | ||||
102 | my %options = @_; | ||||
103 | |||||
104 | my $superclass_key = join('|', | ||||
105 | map { $_->[0] } @{ Data::OptList::mkopt($options{superclasses} || []) } | ||||
106 | ); | ||||
107 | |||||
108 | my $roles = Data::OptList::mkopt(($options{roles} || []), { | ||||
109 | moniker => 'role', | ||||
110 | val_test => sub { ref($_[0]) eq 'HASH' }, | ||||
111 | }); | ||||
112 | |||||
113 | my @role_keys; | ||||
114 | for my $role_spec (@$roles) { | ||||
115 | my ($role, $params) = @$role_spec; | ||||
116 | $params = { %$params } if $params; | ||||
117 | |||||
118 | my $key = blessed($role) ? $role->name : $role; | ||||
119 | |||||
120 | if ($params && %$params) { | ||||
121 | my $alias = delete $params->{'-alias'} | ||||
122 | || delete $params->{'alias'} | ||||
123 | || {}; | ||||
124 | my $excludes = delete $params->{'-excludes'} | ||||
125 | || delete $params->{'excludes'} | ||||
126 | || []; | ||||
127 | $excludes = [$excludes] unless ref($excludes) eq 'ARRAY'; | ||||
128 | |||||
129 | if (%$params) { | ||||
130 | warn "Roles with parameters cannot be cached. Consider " | ||||
131 | . "applying the parameters before calling " | ||||
132 | . "create_anon_class, or using 'weaken => 0' instead"; | ||||
133 | return; | ||||
134 | } | ||||
135 | |||||
136 | my $alias_key = join('%', | ||||
137 | map { $_ => $alias->{$_} } sort keys %$alias | ||||
138 | ); | ||||
139 | my $excludes_key = join('%', | ||||
140 | sort @$excludes | ||||
141 | ); | ||||
142 | $key .= '<' . join('+', 'a', $alias_key, 'e', $excludes_key) . '>'; | ||||
143 | } | ||||
144 | |||||
145 | push @role_keys, $key; | ||||
146 | } | ||||
147 | |||||
148 | my $role_key = join('|', sort @role_keys); | ||||
149 | |||||
150 | # Makes something like Super::Class|Super::Class::2=Role|Role::1 | ||||
151 | return join('=', $superclass_key, $role_key); | ||||
152 | } | ||||
153 | |||||
154 | sub reinitialize { | ||||
155 | my $self = shift; | ||||
156 | my $pkg = shift; | ||||
157 | |||||
158 | my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg); | ||||
159 | |||||
160 | my %existing_classes; | ||||
161 | if ($meta) { | ||||
162 | %existing_classes = map { $_ => $meta->$_() } qw( | ||||
163 | attribute_metaclass | ||||
164 | method_metaclass | ||||
165 | wrapped_method_metaclass | ||||
166 | instance_metaclass | ||||
167 | constructor_class | ||||
168 | destructor_class | ||||
169 | ); | ||||
170 | } | ||||
171 | |||||
172 | return $self->SUPER::reinitialize( | ||||
173 | $pkg, | ||||
174 | %existing_classes, | ||||
175 | @_, | ||||
176 | ); | ||||
177 | } | ||||
178 | |||||
179 | sub add_role { | ||||
180 | my ($self, $role) = @_; | ||||
181 | (blessed($role) && $role->isa('Moose::Meta::Role')) | ||||
182 | || throw_exception( AddRoleTakesAMooseMetaRoleInstance => role_to_be_added => $role, | ||||
183 | class_name => $self->name, | ||||
184 | ); | ||||
185 | push @{$self->roles} => $role; | ||||
186 | } | ||||
187 | |||||
188 | sub role_applications { | ||||
189 | my ($self) = @_; | ||||
190 | |||||
191 | return @{$self->_get_role_applications}; | ||||
192 | } | ||||
193 | |||||
194 | sub add_role_application { | ||||
195 | my ($self, $application) = @_; | ||||
196 | |||||
197 | (blessed($application) && $application->isa('Moose::Meta::Role::Application::ToClass')) | ||||
198 | || throw_exception( InvalidRoleApplication => class_name => $self->name, | ||||
199 | application => $application, | ||||
200 | ); | ||||
201 | |||||
202 | push @{$self->_get_role_applications} => $application; | ||||
203 | } | ||||
204 | |||||
205 | sub calculate_all_roles { | ||||
206 | my $self = shift; | ||||
207 | my %seen; | ||||
208 | grep { !$seen{$_->name}++ } map { $_->calculate_all_roles } @{ $self->roles }; | ||||
209 | } | ||||
210 | |||||
211 | sub _roles_with_inheritance { | ||||
212 | my $self = shift; | ||||
213 | my %seen; | ||||
214 | grep { !$seen{$_->name}++ } | ||||
215 | map { Class::MOP::class_of($_)->can('roles') | ||||
216 | ? @{ Class::MOP::class_of($_)->roles } | ||||
217 | : () } | ||||
218 | $self->linearized_isa; | ||||
219 | } | ||||
220 | |||||
221 | sub calculate_all_roles_with_inheritance { | ||||
222 | my $self = shift; | ||||
223 | my %seen; | ||||
224 | grep { !$seen{$_->name}++ } | ||||
225 | map { Class::MOP::class_of($_)->can('calculate_all_roles') | ||||
226 | ? Class::MOP::class_of($_)->calculate_all_roles | ||||
227 | : () } | ||||
228 | $self->linearized_isa; | ||||
229 | } | ||||
230 | |||||
231 | sub does_role { | ||||
232 | my ($self, $role_name) = @_; | ||||
233 | |||||
234 | (defined $role_name) | ||||
235 | || throw_exception( RoleNameRequired => class_name => $self->name ); | ||||
236 | |||||
237 | foreach my $class ($self->class_precedence_list) { | ||||
238 | my $meta = Class::MOP::class_of($class); | ||||
239 | # when a Moose metaclass is itself extended with a role, | ||||
240 | # this check needs to be done since some items in the | ||||
241 | # class_precedence_list might in fact be Class::MOP | ||||
242 | # based still. | ||||
243 | next unless $meta && $meta->can('roles'); | ||||
244 | foreach my $role (@{$meta->roles}) { | ||||
245 | return 1 if $role->does_role($role_name); | ||||
246 | } | ||||
247 | } | ||||
248 | return 0; | ||||
249 | } | ||||
250 | |||||
251 | sub excludes_role { | ||||
252 | my ($self, $role_name) = @_; | ||||
253 | |||||
254 | (defined $role_name) | ||||
255 | || throw_exception( RoleNameRequired => class_name => $self->name ); | ||||
256 | |||||
257 | foreach my $class ($self->class_precedence_list) { | ||||
258 | my $meta = Class::MOP::class_of($class); | ||||
259 | # when a Moose metaclass is itself extended with a role, | ||||
260 | # this check needs to be done since some items in the | ||||
261 | # class_precedence_list might in fact be Class::MOP | ||||
262 | # based still. | ||||
263 | next unless $meta && $meta->can('roles'); | ||||
264 | foreach my $role (@{$meta->roles}) { | ||||
265 | return 1 if $role->excludes_role($role_name); | ||||
266 | } | ||||
267 | } | ||||
268 | return 0; | ||||
269 | } | ||||
270 | |||||
271 | sub new_object { | ||||
272 | my $self = shift; | ||||
273 | my $params = @_ == 1 ? $_[0] : {@_}; | ||||
274 | my $object = $self->SUPER::new_object($params); | ||||
275 | |||||
276 | $self->_call_all_triggers($object, $params); | ||||
277 | |||||
278 | $object->BUILDALL($params) if $object->can('BUILDALL'); | ||||
279 | |||||
280 | return $object; | ||||
281 | } | ||||
282 | |||||
283 | sub _call_all_triggers { | ||||
284 | my ($self, $object, $params) = @_; | ||||
285 | |||||
286 | foreach my $attr ( $self->get_all_attributes() ) { | ||||
287 | |||||
288 | next unless $attr->can('has_trigger') && $attr->has_trigger; | ||||
289 | |||||
290 | my $init_arg = $attr->init_arg; | ||||
291 | next unless defined $init_arg; | ||||
292 | next unless exists $params->{$init_arg}; | ||||
293 | |||||
294 | $attr->trigger->( | ||||
295 | $object, | ||||
296 | ( | ||||
297 | $attr->should_coerce | ||||
298 | ? $attr->get_read_method_ref->($object) | ||||
299 | : $params->{$init_arg} | ||||
300 | ), | ||||
301 | ); | ||||
302 | } | ||||
303 | } | ||||
304 | |||||
305 | # spent 2µs within Moose::Meta::Class::_generate_fallback_constructor which was called:
# once (2µs+0s) by Class::MOP::Class::_inline_fallback_constructor at line 554 of Class/MOP/Class.pm | ||||
306 | 1 | 300ns | my $self = shift; | ||
307 | 1 | 300ns | my ($class) = @_; | ||
308 | 1 | 2µs | return $class . '->Moose::Object::new(@_)' | ||
309 | } | ||||
310 | |||||
311 | # spent 189µs (14+175) within Moose::Meta::Class::_inline_params which was called:
# once (14µs+175µs) by Class::MOP::Class::_inline_new_object at line 538 of Class/MOP/Class.pm | ||||
312 | 1 | 200ns | my $self = shift; | ||
313 | 1 | 300ns | my ($params, $class) = @_; | ||
314 | return ( | ||||
315 | 1 | 14µs | 1 | 175µs | 'my ' . $params . ' = ', # spent 175µs making 1 call to Moose::Meta::Class::_inline_BUILDARGS |
316 | $self->_inline_BUILDARGS($class, '@_'), | ||||
317 | ';', | ||||
318 | ); | ||||
319 | } | ||||
320 | |||||
321 | # spent 175µs (18+157) within Moose::Meta::Class::_inline_BUILDARGS which was called:
# once (18µs+157µs) by Moose::Meta::Class::_inline_params at line 315 | ||||
322 | 1 | 200ns | my $self = shift; | ||
323 | 1 | 400ns | my ($class, $args) = @_; | ||
324 | |||||
325 | 1 | 2µs | 1 | 152µs | my $buildargs = $self->find_method_by_name("BUILDARGS"); # spent 152µs making 1 call to Class::MOP::Class::find_method_by_name |
326 | |||||
327 | 1 | 12µs | 3 | 5µs | if ($args eq '@_' # spent 4µs making 1 call to Moose::Meta::Class::_inline_throw_exception
# spent 1µs making 1 call to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:16]
# spent 200ns making 1 call to Class::MOP::Method::body |
328 | && (!$buildargs or $buildargs->body == \&Moose::Object::BUILDARGS)) { | ||||
329 | return ( | ||||
330 | 'do {', | ||||
331 | 'my $params;', | ||||
332 | 'if (scalar @_ == 1) {', | ||||
333 | 'if (!defined($_[0]) || ref($_[0]) ne \'HASH\') {', | ||||
334 | $self->_inline_throw_exception( | ||||
335 | 'SingleParamsToNewMustBeHashRef' | ||||
336 | ) . ';', | ||||
337 | '}', | ||||
338 | '$params = { %{ $_[0] } };', | ||||
339 | '}', | ||||
340 | 'elsif (@_ % 2) {', | ||||
341 | 'Carp::carp(', | ||||
342 | '"The new() method for ' . $class . ' expects a ' | ||||
343 | . 'hash reference or a key/value list. You passed an ' | ||||
344 | . 'odd number of arguments"', | ||||
345 | ');', | ||||
346 | '$params = {@_, undef};', | ||||
347 | '}', | ||||
348 | 'else {', | ||||
349 | '$params = {@_};', | ||||
350 | '}', | ||||
351 | '$params;', | ||||
352 | '}', | ||||
353 | ); | ||||
354 | } | ||||
355 | else { | ||||
356 | return $class . '->BUILDARGS(' . $args . ')'; | ||||
357 | } | ||||
358 | } | ||||
359 | |||||
360 | # spent 711µs (20+690) within Moose::Meta::Class::_inline_slot_initializer which was called 4 times, avg 178µs/call:
# 4 times (20µs+690µs) by Class::MOP::Class::_inline_slot_initializers at line 592 of Class/MOP/Class.pm, avg 178µs/call | ||||
361 | 4 | 600ns | my $self = shift; | ||
362 | 4 | 600ns | my ($attr, $idx) = @_; | ||
363 | |||||
364 | return ( | ||||
365 | 4 | 18µs | 12 | 690µs | '## ' . $attr->name, # spent 650µs making 4 calls to Class::MOP::Class::_inline_slot_initializer, avg 162µs/call
# spent 40µs making 4 calls to Moose::Meta::Class::_inline_check_required_attr, avg 10µs/call
# spent 900ns making 4 calls to Class::MOP::Mixin::AttributeCore::name, avg 225ns/call |
366 | $self->_inline_check_required_attr($attr), | ||||
367 | $self->SUPER::_inline_slot_initializer(@_), | ||||
368 | ); | ||||
369 | } | ||||
370 | |||||
371 | # spent 40µs (32+8) within Moose::Meta::Class::_inline_check_required_attr which was called 4 times, avg 10µs/call:
# 4 times (32µs+8µs) by Moose::Meta::Class::_inline_slot_initializer at line 365, avg 10µs/call | ||||
372 | 4 | 700ns | my $self = shift; | ||
373 | 4 | 900ns | my ($attr) = @_; | ||
374 | |||||
375 | 4 | 7µs | 4 | 900ns | return unless defined $attr->init_arg; # spent 900ns making 4 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 225ns/call |
376 | 4 | 12µs | 8 | 4µs | return unless $attr->can('is_required') && $attr->is_required; # spent 2µs making 4 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 600ns/call
# spent 1µs making 4 calls to UNIVERSAL::can, avg 350ns/call |
377 | 1 | 3µs | 2 | 1µs | return if $attr->has_default || $attr->has_builder; # spent 900ns making 1 call to Class::MOP::Mixin::AttributeCore::has_builder
# spent 500ns making 1 call to Class::MOP::Mixin::AttributeCore::has_default |
378 | |||||
379 | return ( | ||||
380 | 1 | 8µs | 3 | 2µs | 'if (!exists $params->{\'' . $attr->init_arg . '\'}) {', # spent 2µs making 1 call to Moose::Meta::Class::_inline_throw_exception
# spent 200ns making 1 call to Class::MOP::Mixin::AttributeCore::init_arg
# spent 200ns making 1 call to Class::MOP::Mixin::AttributeCore::name |
381 | $self->_inline_throw_exception( | ||||
382 | AttributeIsRequired => | ||||
383 | 'params => $params, '. | ||||
384 | 'class_name => $class_name, '. | ||||
385 | 'attribute_name => "'.quotemeta($attr->name).'"' | ||||
386 | ).';', | ||||
387 | '}', | ||||
388 | ); | ||||
389 | } | ||||
390 | |||||
391 | # XXX: these two are duplicated from cmop, because we have to pass the tc stuff | ||||
392 | # through to _inline_set_value - this should probably be fixed, but i'm not | ||||
393 | # quite sure how. -doy | ||||
394 | # spent 359µs (26+332) within Moose::Meta::Class::_inline_init_attr_from_constructor which was called 4 times, avg 90µs/call:
# 4 times (26µs+332µs) by Class::MOP::Class::_inline_slot_initializer at line 601 of Class/MOP/Class.pm, avg 90µs/call | ||||
395 | 4 | 600ns | my $self = shift; | ||
396 | 4 | 700ns | my ($attr, $idx) = @_; | ||
397 | |||||
398 | 4 | 14µs | 8 | 331µs | my @initial_value = $attr->_inline_set_value( # spent 330µs making 4 calls to Moose::Meta::Attribute::_inline_set_value, avg 82µs/call
# spent 600ns making 4 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 150ns/call |
399 | '$instance', | ||||
400 | '$params->{\'' . $attr->init_arg . '\'}', | ||||
401 | '$type_constraint_bodies[' . $idx . ']', | ||||
402 | '$type_coercions[' . $idx . ']', | ||||
403 | '$type_constraint_messages[' . $idx . ']', | ||||
404 | 'for constructor', | ||||
405 | ); | ||||
406 | |||||
407 | 4 | 3µs | 4 | 2µs | push @initial_value, ( # spent 2µs making 4 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 475ns/call |
408 | '$attrs->[' . $idx . ']->set_initial_value(', | ||||
409 | '$instance,', | ||||
410 | $attr->_inline_instance_get('$instance'), | ||||
411 | ');', | ||||
412 | ) if $attr->has_initializer; | ||||
413 | |||||
414 | 4 | 7µs | return @initial_value; | ||
415 | } | ||||
416 | |||||
417 | # spent 251µs (34+217) within Moose::Meta::Class::_inline_init_attr_from_default which was called 4 times, avg 63µs/call:
# 4 times (34µs+217µs) by Class::MOP::Class::_inline_slot_initializer at line 606 of Class/MOP/Class.pm, avg 63µs/call | ||||
418 | 4 | 600ns | my $self = shift; | ||
419 | 4 | 800ns | my ($attr, $idx) = @_; | ||
420 | |||||
421 | 4 | 37µs | 8 | 28µs | return if $attr->can('is_lazy') && $attr->is_lazy; # spent 26µs making 4 calls to UNIVERSAL::can, avg 7µs/call
# spent 2µs making 4 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 575ns/call |
422 | 3 | 4µs | 3 | 15µs | my $default = $self->_inline_default_value($attr, $idx); # spent 15µs making 3 calls to Class::MOP::Class::_inline_default_value, avg 5µs/call |
423 | 3 | 3µs | return unless $default; | ||
424 | |||||
425 | 2 | 6µs | 2 | 172µs | my @initial_value = ( # spent 172µs making 2 calls to Moose::Meta::Attribute::_inline_set_value, avg 86µs/call |
426 | 'my $default = ' . $default . ';', | ||||
427 | $attr->_inline_set_value( | ||||
428 | '$instance', | ||||
429 | '$default', | ||||
430 | '$type_constraint_bodies[' . $idx . ']', | ||||
431 | '$type_coercions[' . $idx . ']', | ||||
432 | '$type_constraint_messages[' . $idx . ']', | ||||
433 | 'for constructor', | ||||
434 | ), | ||||
435 | ); | ||||
436 | |||||
437 | 2 | 1µs | 2 | 1µs | push @initial_value, ( # spent 1µs making 2 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 500ns/call |
438 | '$attrs->[' . $idx . ']->set_initial_value(', | ||||
439 | '$instance,', | ||||
440 | $attr->_inline_instance_get('$instance'), | ||||
441 | ');', | ||||
442 | ) if $attr->has_initializer; | ||||
443 | |||||
444 | 2 | 3µs | return @initial_value; | ||
445 | } | ||||
446 | |||||
447 | # spent 139µs (6+133) within Moose::Meta::Class::_inline_extra_init which was called:
# once (6µs+133µs) by Class::MOP::Class::_inline_new_object at line 538 of Class/MOP/Class.pm | ||||
448 | 1 | 400ns | my $self = shift; | ||
449 | return ( | ||||
450 | 1 | 4µs | 2 | 133µs | $self->_inline_triggers, # spent 70µs making 1 call to Moose::Meta::Class::_inline_triggers
# spent 63µs making 1 call to Moose::Meta::Class::_inline_BUILDALL |
451 | $self->_inline_BUILDALL, | ||||
452 | ); | ||||
453 | } | ||||
454 | |||||
455 | # spent 70µs (28+42) within Moose::Meta::Class::_inline_triggers which was called:
# once (28µs+42µs) by Moose::Meta::Class::_inline_extra_init at line 450 | ||||
456 | 1 | 200ns | my $self = shift; | ||
457 | 1 | 200ns | my @trigger_calls; | ||
458 | |||||
459 | 6 | 16µs | 12 | 31µs | my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes; # spent 17µs making 1 call to Class::MOP::Class::get_all_attributes
# spent 12µs making 1 call to Moose::Meta::Class::CORE:sort
# spent 1µs making 10 calls to Class::MOP::Mixin::AttributeCore::name, avg 140ns/call |
460 | 1 | 2µs | for my $i (0 .. $#attrs) { | ||
461 | 4 | 800ns | my $attr = $attrs[$i]; | ||
462 | |||||
463 | 4 | 8µs | 8 | 3µs | next unless $attr->can('has_trigger') && $attr->has_trigger; # spent 2µs making 4 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 400ns/call
# spent 1µs making 4 calls to UNIVERSAL::can, avg 275ns/call |
464 | |||||
465 | 1 | 3µs | 1 | 300ns | my $init_arg = $attr->init_arg; # spent 300ns making 1 call to Class::MOP::Mixin::AttributeCore::init_arg |
466 | 1 | 300ns | next unless defined $init_arg; | ||
467 | |||||
468 | 1 | 4µs | 1 | 9µs | push @trigger_calls, # spent 9µs making 1 call to Class::MOP::Attribute::_inline_instance_get |
469 | 'if (exists $params->{\'' . $init_arg . '\'}) {', | ||||
470 | '$triggers->[' . $i . ']->(', | ||||
471 | '$instance,', | ||||
472 | $attr->_inline_instance_get('$instance') . ',', | ||||
473 | ');', | ||||
474 | '}'; | ||||
475 | } | ||||
476 | |||||
477 | 1 | 3µs | return @trigger_calls; | ||
478 | } | ||||
479 | |||||
480 | # spent 63µs (6+56) within Moose::Meta::Class::_inline_BUILDALL which was called:
# once (6µs+56µs) by Moose::Meta::Class::_inline_extra_init at line 450 | ||||
481 | 1 | 300ns | my $self = shift; | ||
482 | |||||
483 | 1 | 4µs | 1 | 56µs | my @methods = reverse $self->find_all_methods_by_name('BUILD'); # spent 56µs making 1 call to Class::MOP::Class::find_all_methods_by_name |
484 | 1 | 200ns | my @BUILD_calls; | ||
485 | |||||
486 | 1 | 800ns | foreach my $method (@methods) { | ||
487 | push @BUILD_calls, | ||||
488 | '$instance->' . $method->{class} . '::BUILD($params);'; | ||||
489 | } | ||||
490 | |||||
491 | 1 | 2µs | return @BUILD_calls; | ||
492 | } | ||||
493 | |||||
494 | # spent 210µs (77+133) within Moose::Meta::Class::_eval_environment which was called:
# once (77µs+133µs) by Class::MOP::Method::Constructor::_eval_environment at line 86 of Class/MOP/Method/Constructor.pm | ||||
495 | 1 | 300ns | my $self = shift; | ||
496 | |||||
497 | 5 | 13µs | 10 | 27µs | my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes; # spent 16µs making 1 call to Class::MOP::Class::get_all_attributes
# spent 10µs making 1 call to Moose::Meta::Class::CORE:sort
# spent 1µs making 8 calls to Class::MOP::Mixin::AttributeCore::name, avg 150ns/call |
498 | |||||
499 | my $triggers = [ | ||||
500 | 5 | 10µs | 9 | 4µs | map { $_->can('has_trigger') && $_->has_trigger ? $_->trigger : undef } # spent 2µs making 4 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 375ns/call
# spent 2µs making 1 call to Moose::Meta::Mixin::AttributeCore::trigger
# spent 1µs making 4 calls to UNIVERSAL::can, avg 250ns/call |
501 | @attrs | ||||
502 | ]; | ||||
503 | |||||
504 | # We need to check if the attribute ->can('type_constraint') | ||||
505 | # since we may be trying to immutabilize a Moose meta class, | ||||
506 | # which in turn has attributes which are Class::MOP::Attribute | ||||
507 | # objects, rather than Moose::Meta::Attribute. And | ||||
508 | # Class::MOP::Attribute attributes have no type constraints. | ||||
509 | # However we need to make sure we leave an undef value there | ||||
510 | # because the inlined code is using the index of the attributes | ||||
511 | # to determine where to find the type constraint | ||||
512 | |||||
513 | my @type_constraints = map { | ||||
514 | 5 | 8µs | 8 | 3µs | $_->can('type_constraint') ? $_->type_constraint : undef # spent 2µs making 4 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 425ns/call
# spent 900ns making 4 calls to UNIVERSAL::can, avg 225ns/call |
515 | } @attrs; | ||||
516 | |||||
517 | my @type_constraint_bodies = map { | ||||
518 | 5 | 5µs | 4 | 2µs | defined $_ ? $_->_compiled_type_constraint : undef; # spent 2µs making 4 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 625ns/call |
519 | } @type_constraints; | ||||
520 | |||||
521 | my @type_coercions = map { | ||||
522 | 5 | 4µs | 4 | 1µs | defined $_ && $_->has_coercion # spent 1µs making 4 calls to Moose::Meta::TypeConstraint::has_coercion, avg 350ns/call |
523 | ? $_->coercion->_compiled_type_coercion | ||||
524 | : undef | ||||
525 | } @type_constraints; | ||||
526 | |||||
527 | my @type_constraint_messages = map { | ||||
528 | 5 | 6µs | 8 | 4µs | defined $_ # spent 2µs making 4 calls to Moose::Meta::TypeConstraint::_default_message, avg 525ns/call
# spent 2µs making 4 calls to Moose::Meta::TypeConstraint::has_message, avg 375ns/call |
529 | ? ($_->has_message ? $_->message : $_->_default_message) | ||||
530 | : undef | ||||
531 | } @type_constraints; | ||||
532 | |||||
533 | return { | ||||
534 | %{ $self->SUPER::_eval_environment }, | ||||
535 | 4 | 8µs | 4 | 2µs | ((any { defined && $_->has_initializer } @attrs) # spent 2µs making 4 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 375ns/call |
536 | ? ('$attrs' => \[@attrs]) | ||||
537 | : ()), | ||||
538 | '$triggers' => \$triggers, | ||||
539 | '@type_coercions' => \@type_coercions, | ||||
540 | '@type_constraint_bodies' => \@type_constraint_bodies, | ||||
541 | '@type_constraint_messages' => \@type_constraint_messages, | ||||
542 | 9 | 16µs | 7 | 93µs | ( map { defined($_) ? %{ $_->inline_environment } : () } # spent 36µs making 1 call to Class::MOP::Class::_eval_environment
# spent 33µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::inline_environment
# spent 14µs making 3 calls to Moose::Meta::TypeConstraint::inline_environment, avg 5µs/call
# spent 9µs making 1 call to List::Util::any
# spent 300ns making 1 call to Class::MOP::Package::name |
543 | @type_constraints ), | ||||
544 | # pretty sure this is only going to be closed over if you use a custom | ||||
545 | # error class at this point, but we should still get rid of this | ||||
546 | # at some point | ||||
547 | '$meta' => \$self, | ||||
548 | '$class_name' => \($self->name), | ||||
549 | }; | ||||
550 | } | ||||
551 | |||||
552 | # spent 577µs (40+538) within Moose::Meta::Class::superclasses which was called 6 times, avg 96µs/call:
# 3 times (19µs+57µs) by Class::MOP::Class::_check_metaclass_compatibility at line 197 of Class/MOP/Class.pm, avg 25µs/call
# 2 times (17µs+485µs) by Moose::init_meta at line 225 of Moose.pm, avg 251µs/call
# once (3µs+-3µs) by Class::MOP::Class::_superclasses_updated at line 979 of Class/MOP/Class.pm | ||||
553 | 6 | 1µs | my $self = shift; | ||
554 | 6 | 6µs | 6 | 48µs | my $supers = Data::OptList::mkopt(\@_); # spent 48µs making 6 calls to Data::OptList::mkopt, avg 8µs/call |
555 | 6 | 4µs | foreach my $super (@{ $supers }) { | ||
556 | 1 | 900ns | my ($name, $opts) = @{ $super }; | ||
557 | 1 | 2µs | 1 | 45µs | Moose::Util::_load_user_class($name, $opts); # spent 45µs making 1 call to Moose::Util::_load_user_class |
558 | 1 | 1µs | 1 | 5µs | my $meta = Class::MOP::class_of($name); # spent 5µs making 1 call to Class::MOP::class_of |
559 | 1 | 5µs | 1 | 2µs | throw_exception( CanExtendOnlyClasses => role_name => $meta->name ) # spent 2µs making 1 call to UNIVERSAL::isa |
560 | if $meta && $meta->isa('Moose::Meta::Role') | ||||
561 | } | ||||
562 | 6 | 17µs | 6 | 464µs | return $self->SUPER::superclasses(map { $_->[0] } @{ $supers }); # spent 477µs making 6 calls to Class::MOP::Class::superclasses, avg 80µs/call, recursion: max depth 1, sum of overlapping time 14µs |
563 | } | ||||
564 | |||||
565 | ### --------------------------------------------- | ||||
566 | |||||
567 | # spent 13.1ms (60µs+13.0) within Moose::Meta::Class::add_attribute which was called 4 times, avg 3.27ms/call:
# 4 times (60µs+13.0ms) by Moose::has at line 76 of Moose.pm, avg 3.27ms/call | ||||
568 | 4 | 1µs | my $self = shift; | ||
569 | 4 | 22µs | 8 | 4.21ms | my $attr = # spent 4.21ms making 4 calls to Moose::Meta::Class::_process_attribute, avg 1.05ms/call
# spent 1µs making 4 calls to Scalar::Util::blessed, avg 250ns/call |
570 | (blessed $_[0] && $_[0]->isa('Class::MOP::Attribute') | ||||
571 | ? $_[0] | ||||
572 | : $self->_process_attribute(@_)); | ||||
573 | 4 | 10µs | 4 | 8.79ms | $self->SUPER::add_attribute($attr); # spent 8.79ms making 4 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.20ms/call |
574 | # it may be a Class::MOP::Attribute, theoretically, which doesn't have | ||||
575 | # 'bare' and doesn't implement this method | ||||
576 | 4 | 14µs | 8 | 17µs | if ($attr->can('_check_associated_methods')) { # spent 13µs making 4 calls to Moose::Meta::Attribute::_check_associated_methods, avg 3µs/call
# spent 3µs making 4 calls to UNIVERSAL::can, avg 825ns/call |
577 | $attr->_check_associated_methods; | ||||
578 | } | ||||
579 | 4 | 6µs | return $attr; | ||
580 | } | ||||
581 | |||||
582 | sub add_override_method_modifier { | ||||
583 | my ($self, $name, $method, $_super_package) = @_; | ||||
584 | |||||
585 | my $existing_method = $self->get_method($name); | ||||
586 | (!$existing_method) | ||||
587 | || throw_exception( CannotOverrideLocalMethodIsPresent => class_name => $self->name, | ||||
588 | method => $existing_method, | ||||
589 | ); | ||||
590 | $self->add_method($name => Moose::Meta::Method::Overridden->new( | ||||
591 | method => $method, | ||||
592 | class => $self, | ||||
593 | package => $_super_package, # need this for roles | ||||
594 | name => $name, | ||||
595 | )); | ||||
596 | } | ||||
597 | |||||
598 | sub add_augment_method_modifier { | ||||
599 | my ($self, $name, $method) = @_; | ||||
600 | my $existing_method = $self->get_method($name); | ||||
601 | throw_exception( CannotAugmentIfLocalMethodPresent => class_name => $self->name, | ||||
602 | method => $existing_method, | ||||
603 | ) | ||||
604 | if( $existing_method ); | ||||
605 | |||||
606 | $self->add_method($name => Moose::Meta::Method::Augmented->new( | ||||
607 | method => $method, | ||||
608 | class => $self, | ||||
609 | name => $name, | ||||
610 | )); | ||||
611 | } | ||||
612 | |||||
613 | ## Private Utility methods ... | ||||
614 | |||||
615 | sub _find_next_method_by_name_which_is_not_overridden { | ||||
616 | my ($self, $name) = @_; | ||||
617 | foreach my $method ($self->find_all_methods_by_name($name)) { | ||||
618 | return $method->{code} | ||||
619 | if blessed($method->{code}) && !$method->{code}->isa('Moose::Meta::Method::Overridden'); | ||||
620 | } | ||||
621 | return undef; | ||||
622 | } | ||||
623 | |||||
624 | ## Metaclass compatibility | ||||
625 | |||||
626 | # spent 34µs (25+9) within Moose::Meta::Class::_base_metaclasses which was called 2 times, avg 17µs/call:
# once (16µs+5µs) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 324 of Class/MOP/Class.pm
# once (9µs+4µs) by Class::MOP::Class::_check_metaclass_compatibility at line 202 of Class/MOP/Class.pm | ||||
627 | 2 | 300ns | my $self = shift; | ||
628 | 2 | 5µs | 2 | 3µs | my %metaclasses = $self->SUPER::_base_metaclasses; # spent 3µs making 2 calls to Class::MOP::Class::_base_metaclasses, avg 1µs/call |
629 | 2 | 2µs | for my $class (keys %metaclasses) { | ||
630 | 12 | 20µs | 12 | 6µs | $metaclasses{$class} =~ s/^Class::MOP/Moose::Meta/; # spent 6µs making 12 calls to Moose::Meta::Class::CORE:subst, avg 542ns/call |
631 | } | ||||
632 | return ( | ||||
633 | 2 | 5µs | %metaclasses, | ||
634 | ); | ||||
635 | } | ||||
636 | |||||
637 | sub _fix_class_metaclass_incompatibility { | ||||
638 | my $self = shift; | ||||
639 | my ($super_meta) = @_; | ||||
640 | |||||
641 | $self->SUPER::_fix_class_metaclass_incompatibility(@_); | ||||
642 | |||||
643 | if ($self->_class_metaclass_can_be_made_compatible($super_meta)) { | ||||
644 | ($self->is_pristine) | ||||
645 | || throw_exception( CannotFixMetaclassCompatibility => class => $self, | ||||
646 | superclass => $super_meta | ||||
647 | ); | ||||
648 | my $super_meta_name = $super_meta->_real_ref_name; | ||||
649 | my $class_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass(blessed($self), $super_meta_name); | ||||
650 | my $new_self = $class_meta_subclass_meta_name->reinitialize( | ||||
651 | $self->name, | ||||
652 | ); | ||||
653 | |||||
654 | $self->_replace_self( $new_self, $class_meta_subclass_meta_name ); | ||||
655 | } | ||||
656 | } | ||||
657 | |||||
658 | sub _fix_single_metaclass_incompatibility { | ||||
659 | my $self = shift; | ||||
660 | my ($metaclass_type, $super_meta) = @_; | ||||
661 | |||||
662 | $self->SUPER::_fix_single_metaclass_incompatibility(@_); | ||||
663 | |||||
664 | if ($self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type)) { | ||||
665 | ($self->is_pristine) | ||||
666 | || throw_exception( CannotFixMetaclassCompatibility => class => $self, | ||||
667 | superclass => $super_meta, | ||||
668 | metaclass_type => $metaclass_type | ||||
669 | ); | ||||
670 | my $super_meta_name = $super_meta->_real_ref_name; | ||||
671 | my $class_specific_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass($self->$metaclass_type, $super_meta->$metaclass_type); | ||||
672 | my $new_self = $super_meta->reinitialize( | ||||
673 | $self->name, | ||||
674 | $metaclass_type => $class_specific_meta_subclass_meta_name, | ||||
675 | ); | ||||
676 | |||||
677 | $self->_replace_self( $new_self, $super_meta_name ); | ||||
678 | } | ||||
679 | } | ||||
680 | |||||
681 | sub _replace_self { | ||||
682 | my $self = shift; | ||||
683 | my ( $new_self, $new_class) = @_; | ||||
684 | |||||
685 | %$self = %$new_self; | ||||
686 | bless $self, $new_class; | ||||
687 | |||||
688 | # We need to replace the cached metaclass instance or else when it goes | ||||
689 | # out of scope Class::MOP::Class destroy's the namespace for the | ||||
690 | # metaclass's class, causing much havoc. | ||||
691 | my $weaken = Class::MOP::metaclass_is_weak( $self->name ); | ||||
692 | Class::MOP::store_metaclass_by_name( $self->name, $self ); | ||||
693 | Class::MOP::weaken_metaclass( $self->name ) if $weaken; | ||||
694 | } | ||||
695 | |||||
696 | # spent 4.21ms (27µs+4.18) within Moose::Meta::Class::_process_attribute which was called 4 times, avg 1.05ms/call:
# 4 times (27µs+4.18ms) by Moose::Meta::Class::add_attribute at line 569, avg 1.05ms/call | ||||
697 | 4 | 4µs | my ( $self, $name, @args ) = @_; | ||
698 | |||||
699 | 4 | 2µs | @args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH'; | ||
700 | |||||
701 | 4 | 9µs | 4 | 2µs | if (($name || '') =~ /^\+(.*)/) { # spent 2µs making 4 calls to Moose::Meta::Class::CORE:match, avg 550ns/call |
702 | return $self->_process_inherited_attribute($1, @args); | ||||
703 | } | ||||
704 | else { | ||||
705 | 4 | 12µs | 4 | 4.18ms | return $self->_process_new_attribute($name, @args); # spent 4.18ms making 4 calls to Moose::Meta::Class::_process_new_attribute, avg 1.04ms/call |
706 | } | ||||
707 | } | ||||
708 | |||||
709 | # spent 4.18ms (25µs+4.15) within Moose::Meta::Class::_process_new_attribute which was called 4 times, avg 1.04ms/call:
# 4 times (25µs+4.15ms) by Moose::Meta::Class::_process_attribute at line 705, avg 1.04ms/call | ||||
710 | 4 | 3µs | my ( $self, $name, @args ) = @_; | ||
711 | |||||
712 | 4 | 31µs | 8 | 4.15ms | $self->attribute_metaclass->interpolate_class_and_new($name, @args); # spent 4.15ms making 4 calls to Moose::Meta::Attribute::interpolate_class_and_new, avg 1.04ms/call
# spent 2µs making 4 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 600ns/call |
713 | } | ||||
714 | |||||
715 | sub _process_inherited_attribute { | ||||
716 | my ($self, $attr_name, %options) = @_; | ||||
717 | |||||
718 | my $inherited_attr = $self->find_attribute_by_name($attr_name); | ||||
719 | (defined $inherited_attr) | ||||
720 | || throw_exception( NoAttributeFoundInSuperClass => class_name => $self->name, | ||||
721 | attribute_name => $attr_name, | ||||
722 | params => \%options | ||||
723 | ); | ||||
724 | if ($inherited_attr->isa('Moose::Meta::Attribute')) { | ||||
725 | return $inherited_attr->clone_and_inherit_options(%options); | ||||
726 | } | ||||
727 | else { | ||||
728 | # NOTE: | ||||
729 | # kind of a kludge to handle Class::MOP::Attributes | ||||
730 | return $inherited_attr->Moose::Meta::Attribute::clone_and_inherit_options(%options); | ||||
731 | } | ||||
732 | } | ||||
733 | |||||
734 | # reinitialization support | ||||
735 | |||||
736 | sub _restore_metaobjects_from { | ||||
737 | my $self = shift; | ||||
738 | my ($old_meta) = @_; | ||||
739 | |||||
740 | $self->SUPER::_restore_metaobjects_from($old_meta); | ||||
741 | |||||
742 | for my $role ( @{ $old_meta->roles } ) { | ||||
743 | $self->add_role($role); | ||||
744 | } | ||||
745 | |||||
746 | for my $application ( @{ $old_meta->_get_role_applications } ) { | ||||
747 | $application->class($self); | ||||
748 | $self->add_role_application ($application); | ||||
749 | } | ||||
750 | } | ||||
751 | |||||
752 | ## Immutability | ||||
753 | |||||
754 | # spent 25µs (6+19) within Moose::Meta::Class::_immutable_options which was called:
# once (6µs+19µs) by Class::MOP::Class::make_immutable at line 1297 of Class/MOP/Class.pm | ||||
755 | 1 | 300ns | my ( $self, @args ) = @_; | ||
756 | |||||
757 | 1 | 5µs | 1 | 19µs | $self->SUPER::_immutable_options( # spent 19µs making 1 call to Class::MOP::Class::_immutable_options |
758 | inline_destructor => 1, | ||||
759 | |||||
760 | # Moose always does this when an attribute is created | ||||
761 | inline_accessors => 0, | ||||
762 | |||||
763 | @args, | ||||
764 | ); | ||||
765 | } | ||||
766 | |||||
767 | sub _fixup_attributes_after_rebless { | ||||
768 | my $self = shift; | ||||
769 | my ($instance, $rebless_from, %params) = @_; | ||||
770 | |||||
771 | $self->SUPER::_fixup_attributes_after_rebless( | ||||
772 | $instance, | ||||
773 | $rebless_from, | ||||
774 | %params | ||||
775 | ); | ||||
776 | |||||
777 | $self->_call_all_triggers( $instance, \%params ); | ||||
778 | } | ||||
779 | |||||
780 | ## ------------------------------------------------- | ||||
781 | |||||
782 | our $error_level; | ||||
783 | |||||
784 | sub _inline_throw_exception { | ||||
785 | 2 | 2µs | my ( $self, $exception_type, $throw_args ) = @_; | ||
786 | 2 | 5µs | return 'die Module::Runtime::use_module("Moose::Exception::' . $exception_type . '")->new(' . ($throw_args || '') . ')'; | ||
787 | } | ||||
788 | |||||
789 | 1 | 9µs | 1; | ||
790 | |||||
791 | # ABSTRACT: The Moose metaclass | ||||
792 | |||||
793 | __END__ | ||||
# spent 2µs within Moose::Meta::Class::CORE:match which was called 4 times, avg 550ns/call:
# 4 times (2µs+0s) by Moose::Meta::Class::_process_attribute at line 701, avg 550ns/call | |||||
sub Moose::Meta::Class::CORE:sort; # opcode | |||||
# spent 6µs within Moose::Meta::Class::CORE:subst which was called 12 times, avg 542ns/call:
# 12 times (6µs+0s) by Moose::Meta::Class::_base_metaclasses at line 630, avg 542ns/call |