← Index
NYTProf Performance Profile   « line view »
For examples/Atom-timer.pl
  Run on Mon Aug 12 14:45:28 2013
Reported on Mon Aug 12 14:46:14 2013

Filename/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/Attribute.pm
StatementsExecuted 9275 statements in 26.2ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
29225.89ms17.1msMoose::Meta::Attribute::::new Moose::Meta::Attribute::new
1115.48ms63.5msMoose::Meta::Attribute::::BEGIN@24 Moose::Meta::Attribute::BEGIN@24
4114.91ms47.6msMoose::Meta::Attribute::::install_delegation Moose::Meta::Attribute::install_delegation
47433.63ms19.7msMoose::Meta::Attribute::::_inline_set_value Moose::Meta::Attribute::_inline_set_value
147322.00ms19.9msMoose::Meta::Attribute::::_inline_throw_error Moose::Meta::Attribute::_inline_throw_error
1111.80ms2.44msMoose::Meta::Attribute::::BEGIN@13 Moose::Meta::Attribute::BEGIN@13
61111.52ms3.66msMoose::Meta::Attribute::::_eval_environment Moose::Meta::Attribute::_eval_environment
90211.21ms17.7msMoose::Meta::Attribute::::_inline_check_constraint Moose::Meta::Attribute::_inline_check_constraint
111666µs820µsMoose::Meta::Attribute::::BEGIN@21 Moose::Meta::Attribute::BEGIN@21
111608µs788µsMoose::Meta::Attribute::::BEGIN@22 Moose::Meta::Attribute::BEGIN@22
4311590µs9.70msMoose::Meta::Attribute::::_inline_init_from_default Moose::Meta::Attribute::_inline_init_from_default
2922508µs4.52msMoose::Meta::Attribute::::_process_options Moose::Meta::Attribute::_process_options
3531490µs61.6msMoose::Meta::Attribute::::_process_accessors Moose::Meta::Attribute::_process_accessors
14711408µs487µsMoose::Meta::Attribute::::_error_thrower Moose::Meta::Attribute::_error_thrower
4311361µs1.44msMoose::Meta::Attribute::::_inline_generate_default Moose::Meta::Attribute::_inline_generate_default
5322348µs10.7msMoose::Meta::Attribute::::_inline_check_lazy Moose::Meta::Attribute::_inline_check_lazy
9021343µs581µsMoose::Meta::Attribute::::_inline_weaken_value Moose::Meta::Attribute::_inline_weaken_value
9021236µs349µsMoose::Meta::Attribute::::_inline_check_coercion Moose::Meta::Attribute::_inline_check_coercion
2822230µs41.6msMoose::Meta::Attribute::::interpolate_class_and_new Moose::Meta::Attribute::interpolate_class_and_new (recurses: max depth 1, inclusive time 440µs)
4311213µs853µsMoose::Meta::Attribute::::_inline_init_slot Moose::Meta::Attribute::_inline_init_slot
2911211µs3.72msMoose::Meta::Attribute::::_process_isa_option Moose::Meta::Attribute::_process_isa_option
4711204µs11.8msMoose::Meta::Attribute::::_inline_tc_code Moose::Meta::Attribute::_inline_tc_code
2721192µs6.38msMoose::Meta::Attribute::::_inline_get_value Moose::Meta::Attribute::_inline_get_value
7322178µs298µsMoose::Meta::Attribute::::_writer_value_needs_copy Moose::Meta::Attribute::_writer_value_needs_copy
3032172µs117msMoose::Meta::Attribute::::install_accessors Moose::Meta::Attribute::install_accessors
2811168µs25.4msMoose::Meta::Attribute::::interpolate_class Moose::Meta::Attribute::interpolate_class (recurses: max depth 1, inclusive time 14µs)
811111µs387µsMoose::Meta::Attribute::::initialize_instance_slot Moose::Meta::Attribute::initialize_instance_slot
3722106µs176µsMoose::Meta::Attribute::::_inline_trigger Moose::Meta::Attribute::_inline_trigger
271187µs151µsMoose::Meta::Attribute::::_auto_deref Moose::Meta::Attribute::_auto_deref
281180µs98µsMoose::Meta::Attribute::::_check_associated_methods Moose::Meta::Attribute::_check_associated_methods
872279µs79µsMoose::Meta::Attribute::::accessor_metaclass Moose::Meta::Attribute::accessor_metaclass
271178µs230µsMoose::Meta::Attribute::::_inline_return_auto_deref Moose::Meta::Attribute::_inline_return_auto_deref
241177µs138µsMoose::Meta::Attribute::::_inline_get_old_value_for_trigger Moose::Meta::Attribute::_inline_get_old_value_for_trigger
241172µs137µsMoose::Meta::Attribute::::_inline_check_required Moose::Meta::Attribute::_inline_check_required
291168µs68µsMoose::Meta::Attribute::::_process_is_option Moose::Meta::Attribute::_process_is_option
41142µs438µsMoose::Meta::Attribute::::does Moose::Meta::Attribute::does
291140µs40µsMoose::Meta::Attribute::::_process_does_option Moose::Meta::Attribute::_process_does_option
291136µs36µsMoose::Meta::Attribute::::_process_lazy_option Moose::Meta::Attribute::_process_lazy_option
41136µs145µsMoose::Meta::Attribute::::_coerce_and_verify Moose::Meta::Attribute::_coerce_and_verify
521136µs36µsMoose::Meta::Attribute::::delegation_metaclass Moose::Meta::Attribute::delegation_metaclass
41136µs100µsMoose::Meta::Attribute::::verify_against_type_constraint Moose::Meta::Attribute::verify_against_type_constraint
291133µs33µsMoose::Meta::Attribute::::_process_coerce_option Moose::Meta::Attribute::_process_coerce_option
291130µs30µsMoose::Meta::Attribute::::_process_trigger_option Moose::Meta::Attribute::_process_trigger_option
291130µs30µsMoose::Meta::Attribute::::_process_required_option Moose::Meta::Attribute::_process_required_option
291129µs29µsMoose::Meta::Attribute::::_process_auto_deref_option Moose::Meta::Attribute::_process_auto_deref_option
291128µs28µsMoose::Meta::Attribute::::_process_lazy_build_option Moose::Meta::Attribute::_process_lazy_build_option
1119µs12µsMoose::Meta::Attribute::::BEGIN@11 Moose::Meta::Attribute::BEGIN@11
1118µs8µsMoose::Meta::Attribute::::BEGIN@3 Moose::Meta::Attribute::BEGIN@3
1117µs33µsMoose::Meta::Attribute::::BEGIN@14 Moose::Meta::Attribute::BEGIN@14
1117µs30µsMoose::Meta::Attribute::::BEGIN@17 Moose::Meta::Attribute::BEGIN@17
1116µs12µsMoose::Meta::Attribute::::BEGIN@20 Moose::Meta::Attribute::BEGIN@20
1116µs25µsMoose::Meta::Attribute::::BEGIN@16 Moose::Meta::Attribute::BEGIN@16
1116µs29µsMoose::Meta::Attribute::::BEGIN@15 Moose::Meta::Attribute::BEGIN@15
1116µs7.64msMoose::Meta::Attribute::::BEGIN@27 Moose::Meta::Attribute::BEGIN@27
1116µs16µsMoose::Meta::Attribute::::BEGIN@10 Moose::Meta::Attribute::BEGIN@10
1114µs4µsMoose::Meta::Attribute::::BEGIN@25 Moose::Meta::Attribute::BEGIN@25
1114µs4µsMoose::Meta::Attribute::Custom::Moose::::BEGIN@1287Moose::Meta::Attribute::Custom::Moose::BEGIN@1287
1114µs4µsMoose::Meta::Attribute::::BEGIN@23 Moose::Meta::Attribute::BEGIN@23
1113µs3µsMoose::Meta::Attribute::::BEGIN@18 Moose::Meta::Attribute::BEGIN@18
0000s0sMoose::Meta::Attribute::Custom::Moose::::register_implementationMoose::Meta::Attribute::Custom::Moose::register_implementation
0000s0sMoose::Meta::Attribute::::__ANON__[:1135] Moose::Meta::Attribute::__ANON__[:1135]
0000s0sMoose::Meta::Attribute::::__ANON__[:169] Moose::Meta::Attribute::__ANON__[:169]
0000s0sMoose::Meta::Attribute::::__ANON__[:340] Moose::Meta::Attribute::__ANON__[:340]
0000s0sMoose::Meta::Attribute::::__ANON__[:45] Moose::Meta::Attribute::__ANON__[:45]
0000s0sMoose::Meta::Attribute::::__ANON__[:571] Moose::Meta::Attribute::__ANON__[:571]
0000s0sMoose::Meta::Attribute::::_call_builder Moose::Meta::Attribute::_call_builder
0000s0sMoose::Meta::Attribute::::_canonicalize_handles Moose::Meta::Attribute::_canonicalize_handles
0000s0sMoose::Meta::Attribute::::_find_delegate_metaclass Moose::Meta::Attribute::_find_delegate_metaclass
0000s0sMoose::Meta::Attribute::::_get_delegate_method_list Moose::Meta::Attribute::_get_delegate_method_list
0000s0sMoose::Meta::Attribute::::_inline_copy_value Moose::Meta::Attribute::_inline_copy_value
0000s0sMoose::Meta::Attribute::::_make_delegation_method Moose::Meta::Attribute::_make_delegation_method
0000s0sMoose::Meta::Attribute::::_make_initializer_writer_callback Moose::Meta::Attribute::_make_initializer_writer_callback
0000s0sMoose::Meta::Attribute::::_weaken_value Moose::Meta::Attribute::_weaken_value
0000s0sMoose::Meta::Attribute::::clone Moose::Meta::Attribute::clone
0000s0sMoose::Meta::Attribute::::clone_and_inherit_options Moose::Meta::Attribute::clone_and_inherit_options
0000s0sMoose::Meta::Attribute::::get_value Moose::Meta::Attribute::get_value
0000s0sMoose::Meta::Attribute::::illegal_options_for_inheritance Moose::Meta::Attribute::illegal_options_for_inheritance
0000s0sMoose::Meta::Attribute::::remove_accessors Moose::Meta::Attribute::remove_accessors
0000s0sMoose::Meta::Attribute::::remove_delegation Moose::Meta::Attribute::remove_delegation
0000s0sMoose::Meta::Attribute::::set_value Moose::Meta::Attribute::set_value
0000s0sMoose::Meta::Attribute::::throw_error Moose::Meta::Attribute::throw_error
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::Attribute;
3
# spent 8µs within Moose::Meta::Attribute::BEGIN@3 which was called: # once (8µs+0s) by Moose::Meta::TypeCoercion::BEGIN@14 at line 5
BEGIN {
414µs $Moose::Meta::Attribute::AUTHORITY = 'cpan:STEVAN';
5129µs18µs}
# spent 8µs making 1 call to Moose::Meta::Attribute::BEGIN@3
6{
72800ns $Moose::Meta::Attribute::VERSION = '2.1005';
8}
9
10219µs226µs
# spent 16µs (6+10) within Moose::Meta::Attribute::BEGIN@10 which was called: # once (6µs+10µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 10
use strict;
# spent 16µs making 1 call to Moose::Meta::Attribute::BEGIN@10 # spent 10µs making 1 call to strict::import
11219µs215µs
# spent 12µs (9+3) within Moose::Meta::Attribute::BEGIN@11 which was called: # once (9µs+3µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 11
use warnings;
# spent 12µs making 1 call to Moose::Meta::Attribute::BEGIN@11 # spent 3µs making 1 call to warnings::import
12
13297µs12.44ms
# spent 2.44ms (1.80+634µs) within Moose::Meta::Attribute::BEGIN@13 which was called: # once (1.80ms+634µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 13
use B ();
# spent 2.44ms making 1 call to Moose::Meta::Attribute::BEGIN@13
14224µs259µs
# spent 33µs (7+26) within Moose::Meta::Attribute::BEGIN@14 which was called: # once (7µs+26µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 14
use Class::Load qw(is_class_loaded load_class);
# spent 33µs making 1 call to Moose::Meta::Attribute::BEGIN@14 # spent 26µs making 1 call to Exporter::import
15222µs252µs
# spent 29µs (6+23) within Moose::Meta::Attribute::BEGIN@15 which was called: # once (6µs+23µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 15
use Scalar::Util 'blessed', 'weaken';
# spent 29µs making 1 call to Moose::Meta::Attribute::BEGIN@15 # spent 23µs making 1 call to Exporter::import
16220µs243µs
# spent 25µs (6+18) within Moose::Meta::Attribute::BEGIN@16 which was called: # once (6µs+18µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 16
use List::MoreUtils 'any';
# spent 25µs making 1 call to Moose::Meta::Attribute::BEGIN@16 # spent 18µs making 1 call to Exporter::import
17219µs253µs
# spent 30µs (7+23) within Moose::Meta::Attribute::BEGIN@17 which was called: # once (7µs+23µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 17
use Try::Tiny;
# spent 30µs making 1 call to Moose::Meta::Attribute::BEGIN@17 # spent 23µs making 1 call to Exporter::import
18218µs13µs
# spent 3µs within Moose::Meta::Attribute::BEGIN@18 which was called: # once (3µs+0s) by Moose::Meta::TypeCoercion::BEGIN@14 at line 18
use overload ();
# spent 3µs making 1 call to Moose::Meta::Attribute::BEGIN@18
19
20223µs217µs
# spent 12µs (6+5) within Moose::Meta::Attribute::BEGIN@20 which was called: # once (6µs+5µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 20
use Moose::Deprecated;
21293µs1820µs
# spent 820µs (666+154) within Moose::Meta::Attribute::BEGIN@21 which was called: # once (666µs+154µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 21
use Moose::Meta::Method::Accessor;
# spent 820µs making 1 call to Moose::Meta::Attribute::BEGIN@21
22289µs1788µs
# spent 788µs (608+179) within Moose::Meta::Attribute::BEGIN@22 which was called: # once (608µs+179µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 22
use Moose::Meta::Method::Delegation;
# spent 788µs making 1 call to Moose::Meta::Attribute::BEGIN@22
23218µs14µs
# spent 4µs within Moose::Meta::Attribute::BEGIN@23 which was called: # once (4µs+0s) by Moose::Meta::TypeCoercion::BEGIN@14 at line 23
use Moose::Util ();
# spent 4µs making 1 call to Moose::Meta::Attribute::BEGIN@23
24289µs163.5ms
# spent 63.5ms (5.48+58.0) within Moose::Meta::Attribute::BEGIN@24 which was called: # once (5.48ms+58.0ms) by Moose::Meta::TypeCoercion::BEGIN@14 at line 24
use Moose::Util::TypeConstraints ();
# spent 63.5ms making 1 call to Moose::Meta::Attribute::BEGIN@24
25224µs14µs
# spent 4µs within Moose::Meta::Attribute::BEGIN@25 which was called: # once (4µs+0s) by Moose::Meta::TypeCoercion::BEGIN@14 at line 25
use Class::MOP::MiniTrait;
# spent 4µs making 1 call to Moose::Meta::Attribute::BEGIN@25
26
2724.68ms215.3ms
# spent 7.64ms (6µs+7.63) within Moose::Meta::Attribute::BEGIN@27 which was called: # once (6µs+7.63ms) by Moose::Meta::TypeCoercion::BEGIN@14 at line 27
use base 'Class::MOP::Attribute', 'Moose::Meta::Mixin::AttributeCore';
# spent 7.64ms making 1 call to Moose::Meta::Attribute::BEGIN@27 # spent 7.63ms making 1 call to base::import
28
2912µs11.08msClass::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
# spent 1.08ms making 1 call to Class::MOP::MiniTrait::apply
30
3115µs3418µs__PACKAGE__->meta->add_attribute('traits' => (
# spent 404µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µs making 1 call to Class::MOP::Object::meta # spent 5µs making 1 call to Class::MOP::_definition_context
32 reader => 'applied_traits',
33 predicate => 'has_applied_traits',
34 Class::MOP::_definition_context(),
35));
36
37# we need to have a ->does method in here to
38# more easily support traits, and the introspection
39# of those traits. We extend the does check to look
40# for metatrait aliases.
41
# spent 438µs (42+396) within Moose::Meta::Attribute::does which was called 4 times, avg 109µs/call: # 4 times (42µs+396µs) by Moose::Meta::Attribute::interpolate_class at line 162, avg 109µs/call
sub does {
4242µs my ($self, $role_name) = @_;
43 my $name = try {
4448µs4274µs Moose::Util::resolve_metatrait_alias(Attribute => $role_name)
# spent 274µs making 4 calls to Moose::Util::resolve_metatrait_alias, avg 68µs/call
45418µs4335µs };
# spent 335µs making 4 calls to Try::Tiny::try, avg 84µs/call
464900ns return 0 if !defined($name); # failed to load class
47415µs460µs return $self->Moose::Object::does($name);
# spent 60µs making 4 calls to Moose::Object::does, avg 15µs/call
48}
49
50
# spent 487µs (408+80) within Moose::Meta::Attribute::_error_thrower which was called 147 times, avg 3µs/call: # 147 times (408µs+80µs) by Moose::Meta::Attribute::_inline_throw_error at line 69, avg 3µs/call
sub _error_thrower {
5114715µs my $self = shift;
5214738µs require Moose::Meta::Class;
53147506µs14780µs ( ref $self && $self->associated_class ) || "Moose::Meta::Class";
# spent 80µs making 147 calls to Class::MOP::Attribute::associated_class, avg 541ns/call
54}
55
56sub throw_error {
57 my $self = shift;
58 my $inv = $self->_error_thrower;
59 unshift @_, "message" if @_ % 2 == 1;
60 unshift @_, attr => $self if ref $self;
61 unshift @_, $inv;
62 my $handler = $inv->can("throw_error"); # to avoid incrementing depth by 1
63 goto $handler;
64}
65
66
# spent 19.9ms (2.00+17.9) within Moose::Meta::Attribute::_inline_throw_error which was called 147 times, avg 135µs/call: # 88 times (1.18ms+10.0ms) by Moose::Meta::Attribute::_inline_check_constraint at line 711, avg 127µs/call # 47 times (657µs+7.08ms) by Moose::Meta::Method::_inline_throw_error at line 51 of Moose/Meta/Method.pm, avg 165µs/call # 12 times (159µs+792µs) by Moose::Meta::Attribute::_inline_generate_default at line 942, avg 79µs/call
sub _inline_throw_error {
6714745µs my ( $self, $msg, $args ) = @_;
68
69147101µs147487µs my $inv = $self->_error_thrower;
# spent 487µs making 147 calls to Moose::Meta::Attribute::_error_thrower, avg 3µs/call
70 # XXX ugh
71147299µs147104µs $inv = 'Moose::Meta::Class' unless $inv->can('_inline_throw_error');
# spent 104µs making 147 calls to UNIVERSAL::can, avg 704ns/call
72
73 # XXX ugh ugh UGH
74147253µs14760µs my $class = $self->associated_class;
# spent 60µs making 147 calls to Class::MOP::Attribute::associated_class, avg 407ns/call
7514716µs if ($class) {
76147560µs294192µs my $class_name = B::perlstring($class->name);
# spent 115µs making 147 calls to B::perlstring, avg 784ns/call # spent 76µs making 147 calls to Class::MOP::Package::name, avg 518ns/call
77147514µs294155µs my $attr_name = B::perlstring($self->name);
# spent 88µs making 147 calls to B::perlstring, avg 602ns/call # spent 67µs making 147 calls to Class::MOP::Mixin::AttributeCore::name, avg 454ns/call
78147139µs $args = 'attr => Class::MOP::class_of(' . $class_name . ')'
79 . '->find_attribute_by_name(' . $attr_name . '), '
80 . (defined $args ? $args : '');
81 }
82
83147308µs14716.9ms return $inv->_inline_throw_error($msg, $args)
# spent 16.9ms making 147 calls to Moose::Meta::Class::_inline_throw_error, avg 115µs/call
84}
85
86
# spent 17.1ms (5.89+11.2) within Moose::Meta::Attribute::new which was called 29 times, avg 590µs/call: # 28 times (5.81ms+10.6ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 129, avg 586µs/call # once (86µs+612µs) by Moose::BEGIN@29 at line 23 of Moose/Meta/TypeCoercion.pm
sub new {
872933µs my ($class, $name, %options) = @_;
882933µs296.44ms $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS
# spent 4.25ms making 25 calls to Moose::Meta::Attribute::_process_options, avg 170µs/call # spent 2.19ms making 4 calls to Moose::Meta::Class::__ANON__::SERIAL::1::_process_options, avg 548µs/call
89
90299µs delete $options{__hack_no_process_options};
91
92 my %attrs =
93 ( map { $_ => 1 }
948205.01ms820296µs grep { defined }
# spent 296µs making 820 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 361ns/call
9529626µs58877µs map { $_->init_arg() }
# spent 353µs making 5 calls to Class::MOP::Class::get_all_attributes, avg 71µs/call # spent 274µs making 24 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 11µs/call # spent 211µs making 25 calls to Class::MOP::Object::meta, avg 8µs/call # spent 40µs making 4 calls to Moose::Meta::Class::__ANON__::SERIAL::1::meta, avg 10µs/call
96 $class->meta()->get_all_attributes()
97 );
98
9929119µs299µs my @bad = sort grep { ! $attrs{$_} } keys %options;
# spent 9µs making 29 calls to Moose::Meta::Attribute::CORE:sort, avg 310ns/call
100
101297µs if (@bad)
102 {
103 my $s = @bad > 1 ? 's' : '';
104 my $list = join "', '", @bad;
105
106 my $package = $options{definition_context}{package};
107 my $context = $options{definition_context}{context}
108 || 'attribute constructor';
109 my $type = $options{definition_context}{type} || 'class';
110
111 my $location = '';
112 if (defined($package)) {
113 $location = " in ";
114 $location .= "$type " if $type;
115 $location .= $package;
116 }
117
118 Carp::cluck "Found unknown argument$s '$list' in the $context for '$name'$location";
119 }
120
12129152µs293.60ms return $class->SUPER::new($name, %options);
# spent 3.60ms making 29 calls to Class::MOP::Attribute::new, avg 124µs/call
122}
123
124
# spent 41.6ms (230µs+41.4) within Moose::Meta::Attribute::interpolate_class_and_new which was called 28 times, avg 1.49ms/call: # 19 times (161µs+32.3ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 91 of Moose/Meta/Role/Attribute.pm, avg 1.71ms/call # 9 times (69µs+9.03ms) by Moose::Meta::Class::_process_new_attribute at line 714 of Moose/Meta/Class.pm, avg 1.01ms/call
sub interpolate_class_and_new {
1252842µs my ($class, $name, %args) = @_;
126
1272846µs2825.4ms my ( $new_class, @traits ) = $class->interpolate_class(\%args);
# spent 25.4ms making 28 calls to Moose::Meta::Attribute::interpolate_class, avg 907µs/call, recursion: max depth 1, sum of overlapping time 14µs
128
12928113µs2816.4ms $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) );
# spent 16.4ms making 28 calls to Moose::Meta::Attribute::new, avg 586µs/call
130}
131
132
# spent 25.4ms (168µs+25.2) within Moose::Meta::Attribute::interpolate_class which was called 28 times, avg 907µs/call: # 28 times (168µs+25.2ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 127, avg 907µs/call
sub interpolate_class {
133286µs my ($class, $options) = @_;
134
135285µs $class = ref($class) || $class;
136
1372812µs if ( my $metaclass_name = delete $options->{metaclass} ) {
138 my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name );
139
140 if ( $class ne $new_class ) {
141 if ( $new_class->can("interpolate_class") ) {
142 return $new_class->interpolate_class($options);
143 } else {
144 $class = $new_class;
145 }
146 }
147 }
148
149281µs my @traits;
150
151287µs if (my $traits = $options->{traits}) {
1524900ns my $i = 0;
1534500ns my $has_foreign_options = 0;
154
15542µs while ($i < @$traits) {
15642µs my $trait = $traits->[$i++];
1574500ns next if ref($trait); # options to a trait we discarded
158
15946µs412.7ms $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait)
# spent 12.7ms making 4 calls to Moose::Util::resolve_metatrait_alias, avg 3.16ms/call
160 || $trait;
161
16246µs4438µs next if $class->does($trait);
# spent 438µs making 4 calls to Moose::Meta::Attribute::does, avg 109µs/call
163
16442µs push @traits, $trait;
165
166 # are there options?
16744µs if ($traits->[$i] && ref($traits->[$i])) {
168 $has_foreign_options = 1
169 if any { $_ ne '-alias' && $_ ne '-excludes' } keys %{ $traits->[$i] };
170
171 push @traits, $traits->[$i++];
172 }
173 }
174
17542µs if (@traits) {
17647µs my %options = (
177 superclasses => [ $class ],
178 roles => [ @traits ],
179 );
180
18141µs if ($has_foreign_options) {
182 $options{weaken} = 0;
183 }
184 else {
18542µs $options{cache} = 1;
186 }
187
188414µs412.1ms my $anon_class = Moose::Meta::Class->create_anon_class(%options);
# spent 12.1ms making 4 calls to Class::MOP::Class::create_anon_class, avg 3.04ms/call
189417µs43µs $class = $anon_class->name;
# spent 3µs making 4 calls to Class::MOP::Package::name, avg 725ns/call
190 }
191 }
192
1932864µs return ( wantarray ? ( $class, @traits ) : $class );
194}
195
196# ...
197
198# method-generating options shouldn't be overridden
199sub illegal_options_for_inheritance {
200 qw(reader writer accessor clearer predicate)
201}
202
203# NOTE/TODO
204# This method *must* be able to handle
205# Class::MOP::Attribute instances as
206# well. Yes, I know that is wrong, but
207# apparently we didn't realize it was
208# doing that and now we have some code
209# which is dependent on it. The real
210# solution of course is to push this
211# feature back up into Class::MOP::Attribute
212# but I not right now, I am too lazy.
213# However if you are reading this and
214# looking for something to do,.. please
215# be my guest.
216# - stevan
217sub clone_and_inherit_options {
218 my ($self, %options) = @_;
219
220 # NOTE:
221 # we may want to extends a Class::MOP::Attribute
222 # in which case we need to be able to use the
223 # core set of legal options that have always
224 # been here. But we allows Moose::Meta::Attribute
225 # instances to changes them.
226 # - SL
227 my @illegal_options = $self->can('illegal_options_for_inheritance')
228 ? $self->illegal_options_for_inheritance
229 : ();
230
231 my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options;
232 (scalar @found_illegal_options == 0)
233 || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options);
234
235 $self->_process_isa_option( $self->name, \%options );
236 $self->_process_does_option( $self->name, \%options );
237
238 # NOTE:
239 # this doesn't apply to Class::MOP::Attributes,
240 # so we can ignore it for them.
241 # - SL
242 if ($self->can('interpolate_class')) {
243 ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options);
244
245 my %seen;
246 my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits;
247 $options{traits} = \@all_traits if @all_traits;
248 }
249
250 # This method can be called on a CMOP::Attribute object, so we need to
251 # make sure we can call this method.
252 $self->_process_lazy_build_option( $self->name, \%options )
253 if $self->can('_process_lazy_build_option');
254
255 $self->clone(%options);
256}
257
258sub clone {
259 my ( $self, %params ) = @_;
260
261 my $class = delete $params{metaclass} || ref $self;
262
263 my ( @init, @non_init );
264
265 foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) {
266 push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr;
267 }
268
269 my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params );
270
271 my $name = delete $new_params{name};
272
273 my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 );
274
275 foreach my $attr ( @non_init ) {
276 $attr->set_value($clone, $attr->get_value($self));
277 }
278
279 return $clone;
280}
281
282
# spent 4.52ms (508µs+4.01) within Moose::Meta::Attribute::_process_options which was called 29 times, avg 156µs/call: # 25 times (422µs+3.83ms) by Moose::Meta::Attribute::new at line 88, avg 170µs/call # 4 times (86µs+185µs) by Class::MOP::Method::Wrapped::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Class/MOP/Method/Wrapped.pm:51] at line 50 of Class/MOP/Method/Wrapped.pm, avg 68µs/call
sub _process_options {
283298µs my ( $class, $name, $options ) = @_;
284
2852925µs2968µs $class->_process_is_option( $name, $options );
# spent 68µs making 29 calls to Moose::Meta::Attribute::_process_is_option, avg 2µs/call
2862941µs293.72ms $class->_process_isa_option( $name, $options );
# spent 3.72ms making 29 calls to Moose::Meta::Attribute::_process_isa_option, avg 128µs/call
2872929µs2940µs $class->_process_does_option( $name, $options );
# spent 40µs making 29 calls to Moose::Meta::Attribute::_process_does_option, avg 1µs/call
2882924µs2933µs $class->_process_coerce_option( $name, $options );
# spent 33µs making 29 calls to Moose::Meta::Attribute::_process_coerce_option, avg 1µs/call
2892921µs2930µs $class->_process_trigger_option( $name, $options );
# spent 30µs making 29 calls to Moose::Meta::Attribute::_process_trigger_option, avg 1µs/call
2902924µs2929µs $class->_process_auto_deref_option( $name, $options );
# spent 29µs making 29 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 986ns/call
2912921µs2928µs $class->_process_lazy_build_option( $name, $options );
# spent 28µs making 29 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 976ns/call
2922921µs2936µs $class->_process_lazy_option( $name, $options );
# spent 36µs making 29 calls to Moose::Meta::Attribute::_process_lazy_option, avg 1µs/call
2932965µs2930µs $class->_process_required_option( $name, $options );
# spent 30µs making 29 calls to Moose::Meta::Attribute::_process_required_option, avg 1µs/call
294}
295
296
# spent 68µs within Moose::Meta::Attribute::_process_is_option which was called 29 times, avg 2µs/call: # 29 times (68µs+0s) by Moose::Meta::Attribute::_process_options at line 285, avg 2µs/call
sub _process_is_option {
297295µs my ( $class, $name, $options ) = @_;
298
2992914µs return unless $options->{is};
300
301 ### -------------------------
302 ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before
303 ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo)
304 ## is => rw, accessor => _foo # turns into (accessor => _foo)
305 ## is => ro, accessor => _foo # error, accesor is rw
306 ### -------------------------
307
3082551µs if ( $options->{is} eq 'ro' ) {
30931µs $class->throw_error(
310 "Cannot define an accessor name on a read-only attribute, accessors are read/write",
311 data => $options )
312 if exists $options->{accessor};
31332µs $options->{reader} ||= $name;
314 }
315 elsif ( $options->{is} eq 'rw' ) {
316 if ( $options->{writer} ) {
317 $options->{reader} ||= $name;
318 }
319 else {
3202212µs $options->{accessor} ||= $name;
321 }
322 }
323 elsif ( $options->{is} eq 'bare' ) {
324 return;
325 # do nothing, but don't complain (later) about missing methods
326 }
327 else {
328 $class->throw_error( "I do not understand this option (is => "
329 . $options->{is}
330 . ") on attribute ($name)", data => $options->{is} );
331 }
332}
333
334
# spent 3.72ms (211µs+3.51) within Moose::Meta::Attribute::_process_isa_option which was called 29 times, avg 128µs/call: # 29 times (211µs+3.51ms) by Moose::Meta::Attribute::_process_options at line 286, avg 128µs/call
sub _process_isa_option {
335297µs my ( $class, $name, $options ) = @_;
336
3372912µs return unless exists $options->{isa};
338
339285µs if ( exists $options->{does} ) {
340 if ( try { $options->{isa}->can('does') } ) {
341 ( $options->{isa}->does( $options->{does} ) )
342 || $class->throw_error(
343 "Cannot have an isa option and a does option if the isa does not do the does on attribute ($name)",
344 data => $options );
345 }
346 else {
347 $class->throw_error(
348 "Cannot have an isa option which cannot ->does() on attribute ($name)",
349 data => $options );
350 }
351 }
352
353 # allow for anon-subtypes here ...
354 #
355 # Checking for Specio explicitly is completely revolting. At some point
356 # this needs to be refactored so that Moose core defines a standard type
357 # API that all types must implement. Unfortunately, the current core API
358 # is _not_ the right API, so we probably need to A) come up with the new
359 # API (Specio is a good start); B) refactor the core types to implement
360 # that API; C) do duck type checking on type objects.
36128133µs5621µs if ( blessed( $options->{isa} )
# spent 21µs making 56 calls to Scalar::Util::blessed, avg 375ns/call
362 && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) {
363 $options->{type_constraint} = $options->{isa};
364 }
365 elsif (
366 blessed( $options->{isa} )
367 && Moose::Util::does_role(
368 $options->{isa}, 'Specio::Constraint::Role::Interface'
369 )
370 ) {
371 $options->{type_constraint} = $options->{isa};
372 }
373 else {
3742869µs283.49ms $options->{type_constraint}
# spent 3.49ms making 28 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 125µs/call
375 = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint(
376 $options->{isa},
377 { package_defined_in => $options->{definition_context}->{package} }
378 );
379 }
380}
381
382
# spent 40µs within Moose::Meta::Attribute::_process_does_option which was called 29 times, avg 1µs/call: # 29 times (40µs+0s) by Moose::Meta::Attribute::_process_options at line 287, avg 1µs/call
sub _process_does_option {
383299µs my ( $class, $name, $options ) = @_;
384
3852948µs return unless exists $options->{does} && ! exists $options->{isa};
386
387 # allow for anon-subtypes here ...
388 if ( blessed( $options->{does} )
389 && $options->{does}->isa('Moose::Meta::TypeConstraint') ) {
390 $options->{type_constraint} = $options->{does};
391 }
392 else {
393 $options->{type_constraint}
394 = Moose::Util::TypeConstraints::find_or_create_does_type_constraint(
395 $options->{does},
396 { package_defined_in => $options->{definition_context}->{package} }
397 );
398 }
399}
400
401
# spent 33µs within Moose::Meta::Attribute::_process_coerce_option which was called 29 times, avg 1µs/call: # 29 times (33µs+0s) by Moose::Meta::Attribute::_process_options at line 288, avg 1µs/call
sub _process_coerce_option {
402297µs my ( $class, $name, $options ) = @_;
403
4042942µs return unless $options->{coerce};
405
406 ( exists $options->{type_constraint} )
407 || $class->throw_error(
408 "You cannot have coercion without specifying a type constraint on attribute ($name)",
409 data => $options );
410
411 $class->throw_error(
412 "You cannot have a weak reference to a coerced value on attribute ($name)",
413 data => $options )
414 if $options->{weak_ref};
415
416 unless ( $options->{type_constraint}->has_coercion ) {
417 my $type = $options->{type_constraint}->name;
418
419 Moose::Deprecated::deprecated(
420 feature => 'coerce without coercion',
421 message =>
422 "You cannot coerce an attribute ($name) unless its type ($type) has a coercion"
423 );
424 }
425}
426
427
# spent 30µs within Moose::Meta::Attribute::_process_trigger_option which was called 29 times, avg 1µs/call: # 29 times (30µs+0s) by Moose::Meta::Attribute::_process_options at line 289, avg 1µs/call
sub _process_trigger_option {
428297µs my ( $class, $name, $options ) = @_;
429
4302942µs return unless exists $options->{trigger};
431
432 ( 'CODE' eq ref $options->{trigger} )
433 || $class->throw_error("Trigger must be a CODE ref on attribute ($name)", data => $options->{trigger});
434}
435
436
# spent 29µs within Moose::Meta::Attribute::_process_auto_deref_option which was called 29 times, avg 986ns/call: # 29 times (29µs+0s) by Moose::Meta::Attribute::_process_options at line 290, avg 986ns/call
sub _process_auto_deref_option {
437297µs my ( $class, $name, $options ) = @_;
438
4392939µs return unless $options->{auto_deref};
440
441 ( exists $options->{type_constraint} )
442 || $class->throw_error(
443 "You cannot auto-dereference without specifying a type constraint on attribute ($name)",
444 data => $options );
445
446 ( $options->{type_constraint}->is_a_type_of('ArrayRef')
447 || $options->{type_constraint}->is_a_type_of('HashRef') )
448 || $class->throw_error(
449 "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)",
450 data => $options );
451}
452
453
# spent 28µs within Moose::Meta::Attribute::_process_lazy_build_option which was called 29 times, avg 976ns/call: # 29 times (28µs+0s) by Moose::Meta::Attribute::_process_options at line 291, avg 976ns/call
sub _process_lazy_build_option {
454297µs my ( $class, $name, $options ) = @_;
455
4562939µs return unless $options->{lazy_build};
457
458 $class->throw_error(
459 "You can not use lazy_build and default for the same attribute ($name)",
460 data => $options )
461 if exists $options->{default};
462
463 $options->{lazy} = 1;
464 $options->{builder} ||= "_build_${name}";
465
466 if ( $name =~ /^_/ ) {
467 $options->{clearer} ||= "_clear${name}";
468 $options->{predicate} ||= "_has${name}";
469 }
470 else {
471 $options->{clearer} ||= "clear_${name}";
472 $options->{predicate} ||= "has_${name}";
473 }
474}
475
476
# spent 36µs within Moose::Meta::Attribute::_process_lazy_option which was called 29 times, avg 1µs/call: # 29 times (36µs+0s) by Moose::Meta::Attribute::_process_options at line 292, avg 1µs/call
sub _process_lazy_option {
477297µs my ( $class, $name, $options ) = @_;
478
4792917µs return unless $options->{lazy};
480
4812030µs ( exists $options->{default} || defined $options->{builder} )
482 || $class->throw_error(
483 "You cannot have a lazy attribute ($name) without specifying a default value for it",
484 data => $options );
485}
486
487
# spent 30µs within Moose::Meta::Attribute::_process_required_option which was called 29 times, avg 1µs/call: # 29 times (30µs+0s) by Moose::Meta::Attribute::_process_options at line 293, avg 1µs/call
sub _process_required_option {
488297µs my ( $class, $name, $options ) = @_;
489
4902938µs if (
491 $options->{required}
492 && !(
493 ( !exists $options->{init_arg} || defined $options->{init_arg} )
494 || exists $options->{default}
495 || defined $options->{builder}
496 )
497 ) {
498 $class->throw_error(
499 "You cannot have a required attribute ($name) without a default, builder, or an init_arg",
500 data => $options );
501 }
502}
503
504
# spent 387µs (111+276) within Moose::Meta::Attribute::initialize_instance_slot which was called 8 times, avg 48µs/call: # 8 times (111µs+276µs) by Class::MOP::Class::_construct_instance at line 525 of Class/MOP/Class.pm, avg 48µs/call
sub initialize_instance_slot {
50582µs my ($self, $meta_instance, $instance, $params) = @_;
506819µs84µs my $init_arg = $self->init_arg();
# spent 4µs making 8 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 475ns/call
507 # try to fetch the init arg from the %params ...
508
5098200ns my $val;
5108400ns my $value_is_set;
51183µs if ( defined($init_arg) and exists $params->{$init_arg}) {
512 $val = $params->{$init_arg};
513 $value_is_set = 1;
514 }
515 else {
516 # skip it if it's lazy
517815µs810µs return if $self->is_lazy;
# spent 10µs making 8 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 1µs/call
518 # and die if it's required and doesn't have a default value
51944µs44µs $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params)
# spent 4µs making 4 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 1µs/call
520 if $self->is_required && !$self->has_default && !$self->has_builder;
521
522 # if nothing was in the %params, we can use the
523 # attribute's default value (if it has one)
52445µs44µs if ($self->has_default) {
# spent 4µs making 4 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call
52544µs418µs $val = $self->default($instance);
# spent 18µs making 4 calls to Class::MOP::Mixin::AttributeCore::default, avg 4µs/call
5264900ns $value_is_set = 1;
527 }
528 elsif ($self->has_builder) {
529 $val = $self->_call_builder($instance);
530 $value_is_set = 1;
531 }
532 }
533
5344600ns return unless $value_is_set;
535
53646µs4145µs $val = $self->_coerce_and_verify( $val, $instance );
# spent 145µs making 4 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 36µs/call
537
53847µs490µs $self->set_initial_value($instance, $val);
# spent 90µs making 4 calls to Class::MOP::Attribute::set_initial_value, avg 23µs/call
539
54046µs if ( ref $val && $self->is_weak_ref ) {
541 $self->_weaken_value($instance);
542 }
543}
544
545sub _call_builder {
546 my ( $self, $instance ) = @_;
547
548 my $builder = $self->builder();
549
550 return $instance->$builder()
551 if $instance->can( $self->builder );
552
553 $self->throw_error( blessed($instance)
554 . " does not support builder method '"
555 . $self->builder
556 . "' for attribute '"
557 . $self->name
558 . "'",
559 object => $instance,
560 );
561}
562
563## Slot management
564
565sub _make_initializer_writer_callback {
566 my $self = shift;
567 my ($meta_instance, $instance, $slot_name) = @_;
568 my $old_callback = $self->SUPER::_make_initializer_writer_callback(@_);
569 return sub {
570 $old_callback->($self->_coerce_and_verify($_[0], $instance));
571 };
572}
573
574sub set_value {
575 my ($self, $instance, @args) = @_;
576 my $value = $args[0];
577
578 my $attr_name = quotemeta($self->name);
579
580 if ($self->is_required and not @args) {
581 $self->throw_error("Attribute ($attr_name) is required", object => $instance);
582 }
583
584 $value = $self->_coerce_and_verify( $value, $instance );
585
586 my @old;
587 if ( $self->has_trigger && $self->has_value($instance) ) {
588 @old = $self->get_value($instance, 'for trigger');
589 }
590
591 $self->SUPER::set_value($instance, $value);
592
593 if ( ref $value && $self->is_weak_ref ) {
594 $self->_weaken_value($instance);
595 }
596
597 if ($self->has_trigger) {
598 $self->trigger->($instance, $value, @old);
599 }
600}
601
602
# spent 19.7ms (3.63+16.1) within Moose::Meta::Attribute::_inline_set_value which was called 47 times, avg 419µs/call: # 22 times (397µs+11.4ms) by Class::MOP::Method::Accessor::try {...} at line 112 of Class/MOP/Method/Accessor.pm, avg 535µs/call # 22 times (3.17ms+4.03ms) by Moose::Meta::Class::_inline_init_attr_from_constructor at line 406 of Moose/Meta/Class.pm, avg 327µs/call # 2 times (45µs+432µs) by Class::MOP::Class::_inline_init_attr_from_constructor at line 630 of Class/MOP/Class.pm, avg 238µs/call # once (11µs+239µs) by Moose::Meta::Class::_inline_init_attr_from_default at line 433 of Moose/Meta/Class.pm
sub _inline_set_value {
603479µs my $self = shift;
6044717µs my ($instance, $value, $tc, $coercion, $message, $for_constructor) = @_;
605
606476µs my $old = '@old';
607472µs my $copy = '$val';
608473µs $tc ||= '$type_constraint';
609473µs $coercion ||= '$type_coercion';
610472µs $message ||= '$type_message';
611
612473µs my @code;
6134729µs47215µs if ($self->_writer_value_needs_copy) {
# spent 215µs making 47 calls to Moose::Meta::Attribute::_writer_value_needs_copy, avg 5µs/call
614 push @code, $self->_inline_copy_value($value, $copy);
615 $value = $copy;
616 }
617
618 # constructors already handle required checks
6194724µs24137µs push @code, $self->_inline_check_required
# spent 137µs making 24 calls to Moose::Meta::Attribute::_inline_check_required, avg 6µs/call
620 unless $for_constructor;
621
6224797µs4711.8ms push @code, $self->_inline_tc_code($value, $tc, $coercion, $message);
# spent 11.8ms making 47 calls to Moose::Meta::Attribute::_inline_tc_code, avg 251µs/call
623
624 # constructors do triggers all at once at the end
6254732µs24138µs push @code, $self->_inline_get_old_value_for_trigger($instance, $old)
# spent 138µs making 24 calls to Moose::Meta::Attribute::_inline_get_old_value_for_trigger, avg 6µs/call
626 unless $for_constructor;
627
62847116µs943.64ms push @code, (
# spent 3.34ms making 47 calls to Class::MOP::Attribute::_inline_set_value, avg 71µs/call # spent 304µs making 47 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 6µs/call
629 $self->SUPER::_inline_set_value($instance, $value),
630 $self->_inline_weaken_value($instance, $value),
631 );
632
633 # constructors do triggers all at once at the end
6344724µs24126µs push @code, $self->_inline_trigger($instance, $value, $old)
# spent 126µs making 24 calls to Moose::Meta::Attribute::_inline_trigger, avg 5µs/call
635 unless $for_constructor;
636
63747130µs return @code;
638}
639
640
# spent 298µs (178+119) within Moose::Meta::Attribute::_writer_value_needs_copy which was called 73 times, avg 4µs/call: # 47 times (118µs+97µs) by Moose::Meta::Attribute::_inline_set_value at line 613, avg 5µs/call # 26 times (60µs+22µs) by Moose::Meta::Method::Accessor::_writer_value_needs_copy at line 91 of Moose/Meta/Method/Accessor.pm, avg 3µs/call
sub _writer_value_needs_copy {
641738µs my $self = shift;
64273141µs73119µs return $self->should_coerce;
# spent 119µs making 73 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 2µs/call
643}
644
645sub _inline_copy_value {
646 my $self = shift;
647 my ($value, $copy) = @_;
648
649 return 'my ' . $copy . ' = ' . $value . ';'
650}
651
652
# spent 137µs (72+65) within Moose::Meta::Attribute::_inline_check_required which was called 24 times, avg 6µs/call: # 24 times (72µs+65µs) by Moose::Meta::Attribute::_inline_set_value at line 619, avg 6µs/call
sub _inline_check_required {
653243µs my $self = shift;
654
6552459µs2465µs return unless $self->is_required;
# spent 65µs making 24 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 3µs/call
656
657 my $attr_name = quotemeta($self->name);
658
659 return (
660 'if (@_ < 2) {',
661 $self->_inline_throw_error(
662 '"Attribute (' . $attr_name . ') is required"'
663 ) . ';',
664 '}',
665 );
666}
667
668
# spent 11.8ms (204µs+11.6) within Moose::Meta::Attribute::_inline_tc_code which was called 47 times, avg 251µs/call: # 47 times (204µs+11.6ms) by Moose::Meta::Attribute::_inline_set_value at line 622, avg 251µs/call
sub _inline_tc_code {
669476µs my $self = shift;
6704716µs my ($value, $tc, $coercion, $message, $is_lazy) = @_;
671 return (
67247117µs9411.6ms $self->_inline_check_coercion(
# spent 11.4ms making 47 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 243µs/call # spent 184µs making 47 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 4µs/call
673 $value, $tc, $coercion, $is_lazy,
674 ),
675 $self->_inline_check_constraint(
676 $value, $tc, $message, $is_lazy,
677 ),
678 );
679}
680
681
# spent 349µs (236+114) within Moose::Meta::Attribute::_inline_check_coercion which was called 90 times, avg 4µs/call: # 47 times (113µs+72µs) by Moose::Meta::Attribute::_inline_tc_code at line 672, avg 4µs/call # 43 times (123µs+42µs) by Moose::Meta::Attribute::_inline_init_from_default at line 914, avg 4µs/call
sub _inline_check_coercion {
682908µs my $self = shift;
6839019µs my ($value, $tc, $coercion) = @_;
684
68590163µs90114µs return unless $self->should_coerce && $self->type_constraint->has_coercion;
# spent 114µs making 90 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 1µs/call
686
687 if ( $self->type_constraint->can_be_inlined ) {
688 return (
689 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {',
690 $value . ' = ' . $coercion . '->(' . $value . ');',
691 '}',
692 );
693 }
694 else {
695 return (
696 'if (!' . $tc . '->(' . $value . ')) {',
697 $value . ' = ' . $coercion . '->(' . $value . ');',
698 '}',
699 );
700 }
701}
702
703
# spent 17.7ms (1.21+16.5) within Moose::Meta::Attribute::_inline_check_constraint which was called 90 times, avg 197µs/call: # 47 times (637µs+10.8ms) by Moose::Meta::Attribute::_inline_tc_code at line 672, avg 243µs/call # 43 times (572µs+5.70ms) by Moose::Meta::Attribute::_inline_init_from_default at line 914, avg 146µs/call
sub _inline_check_constraint {
7049010µs my $self = shift;
7059019µs my ($value, $tc, $message) = @_;
706
7079066µs90115µs return unless $self->has_type_constraint;
# spent 115µs making 90 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call
708
70988177µs8843µs my $attr_name = quotemeta($self->name);
# spent 43µs making 88 calls to Class::MOP::Mixin::AttributeCore::name, avg 492ns/call
710
71188588µs44016.3ms if ( $self->type_constraint->can_be_inlined ) {
# spent 11.2ms making 88 calls to Moose::Meta::Attribute::_inline_throw_error, avg 127µs/call # spent 2.60ms making 71 calls to Moose::Meta::TypeConstraint::_inline_check, avg 37µs/call # spent 1.05ms making 14 calls to Moose::Meta::TypeConstraint::Parameterized::_inline_check, avg 75µs/call # spent 645µs making 71 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 9µs/call # spent 307µs making 14 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 22µs/call # spent 295µs making 3 calls to Moose::Meta::TypeConstraint::Union::_inline_check, avg 98µs/call # spent 164µs making 176 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 935ns/call # spent 83µs making 3 calls to Moose::Meta::TypeConstraint::Union::can_be_inlined, avg 28µs/call
712 return (
713 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {',
714 $self->_inline_throw_error(
715 '"Attribute (' . $attr_name . ') does not pass the type '
716 . 'constraint because: " . '
717 . 'do { local $_ = ' . $value . '; '
718 . $message . '->(' . $value . ')'
719 . '}',
720 'data => ' . $value
721 ) . ';',
722 '}',
723 );
724 }
725 else {
726 return (
727 'if (!' . $tc . '->(' . $value . ')) {',
728 $self->_inline_throw_error(
729 '"Attribute (' . $attr_name . ') does not pass the type '
730 . 'constraint because: " . '
731 . 'do { local $_ = ' . $value . '; '
732 . $message . '->(' . $value . ')'
733 . '}',
734 'data => ' . $value
735 ) . ';',
736 '}',
737 );
738 }
739}
740
741
# spent 138µs (77+61) within Moose::Meta::Attribute::_inline_get_old_value_for_trigger which was called 24 times, avg 6µs/call: # 24 times (77µs+61µs) by Moose::Meta::Attribute::_inline_set_value at line 625, avg 6µs/call
sub _inline_get_old_value_for_trigger {
742243µs my $self = shift;
743247µs my ($instance, $old) = @_;
744
7452449µs2461µs return unless $self->has_trigger;
# spent 61µs making 24 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 3µs/call
746
747 return (
748 'my ' . $old . ' = ' . $self->_inline_instance_has($instance),
749 '? ' . $self->_inline_instance_get($instance),
750 ': ();',
751 );
752}
753
754
# spent 581µs (343+238) within Moose::Meta::Attribute::_inline_weaken_value which was called 90 times, avg 6µs/call: # 47 times (172µs+132µs) by Moose::Meta::Attribute::_inline_set_value at line 628, avg 6µs/call # 43 times (171µs+107µs) by Moose::Meta::Attribute::_inline_init_from_default at line 914, avg 6µs/call
sub _inline_weaken_value {
7559011µs my $self = shift;
7569019µs my ($instance, $value) = @_;
757
75890164µs90148µs return unless $self->is_weak_ref;
# spent 148µs making 90 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 2µs/call
759
7601334µs2623µs my $mi = $self->associated_class->get_meta_instance;
# spent 12µs making 12 calls to Class::MOP::Class::get_meta_instance, avg 958ns/call # spent 7µs making 13 calls to Class::MOP::Attribute::associated_class, avg 515ns/call # spent 5µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance
761 return (
7621360µs2667µs $mi->inline_weaken_slot_value($instance, $self->name),
# spent 62µs making 13 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 5µs/call # spent 6µs making 13 calls to Class::MOP::Mixin::AttributeCore::name, avg 438ns/call
763 'if ref ' . $value . ';',
764 );
765}
766
767
# spent 176µs (106+70) within Moose::Meta::Attribute::_inline_trigger which was called 37 times, avg 5µs/call: # 24 times (68µs+58µs) by Moose::Meta::Attribute::_inline_set_value at line 634, avg 5µs/call # 13 times (38µs+12µs) by Moose::Meta::Method::Accessor::_inline_trigger at line 119 of Moose/Meta/Method/Accessor.pm, avg 4µs/call
sub _inline_trigger {
768374µs my $self = shift;
769379µs my ($instance, $value, $old) = @_;
770
7713769µs3770µs return unless $self->has_trigger;
# spent 70µs making 37 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 2µs/call
772
773 return '$trigger->(' . $instance . ', ' . $value . ', ' . $old . ');';
774}
775
776
# spent 3.66ms (1.52+2.14) within Moose::Meta::Attribute::_eval_environment which was called 61 times, avg 60µs/call: # 61 times (1.52ms+2.14ms) by Moose::Meta::Method::Accessor::_eval_environment at line 52 of Moose/Meta/Method/Accessor.pm, avg 60µs/call
sub _eval_environment {
777617µs my $self = shift;
778
7796120µs my $env = { };
780
7816164µs61124µs $env->{'$trigger'} = \($self->trigger)
# spent 124µs making 61 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 2µs/call
782 if $self->has_trigger;
7836199µs96102µs $env->{'$attr_default'} = \($self->default)
# spent 57µs making 61 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 934ns/call # spent 45µs making 35 calls to Class::MOP::Mixin::AttributeCore::default, avg 1µs/call
784 if $self->has_default;
785
78661103µs6196µs if ($self->has_type_constraint) {
# spent 96µs making 61 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 2µs/call
7875946µs5957µs my $tc_obj = $self->type_constraint;
# spent 57µs making 59 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 966ns/call
788
7895954µs59686µs $env->{'$type_constraint'} = \(
# spent 416µs making 47 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 9µs/call # spent 244µs making 11 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 22µs/call # spent 25µs making 1 call to Moose::Meta::TypeConstraint::Union::can_be_inlined
790 $tc_obj->_compiled_type_constraint
791 ) unless $tc_obj->can_be_inlined;
792 # these two could probably get inlined versions too
7935955µs5985µs $env->{'$type_coercion'} = \(
# spent 65µs making 58 calls to Moose::Meta::TypeConstraint::has_coercion, avg 1µs/call # spent 20µs making 1 call to Moose::Meta::TypeConstraint::Union::has_coercion
794 $tc_obj->coercion->_compiled_type_coercion
795 ) if $tc_obj->has_coercion;
79659115µs118118µs $env->{'$type_message'} = \(
# spent 62µs making 59 calls to Moose::Meta::TypeConstraint::_default_message, avg 1µs/call # spent 56µs making 59 calls to Moose::Meta::TypeConstraint::has_message, avg 953ns/call
797 $tc_obj->has_message ? $tc_obj->message : $tc_obj->_default_message
798 );
799
80059158µs59764µs $env = { %$env, %{ $tc_obj->inline_environment } };
# spent 400µs making 47 calls to Moose::Meta::TypeConstraint::inline_environment, avg 9µs/call # spent 336µs making 11 calls to Moose::Meta::TypeConstraint::Parameterized::inline_environment, avg 31µs/call # spent 28µs making 1 call to Moose::Meta::TypeConstraint::Union::inline_environment
801 }
802
803 # XXX ugh, fix these
8046152µs6165µs $env->{'$attr'} = \$self
# spent 65µs making 61 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 1µs/call
805 if $self->has_initializer && $self->is_lazy;
806 # pretty sure this is only going to be closed over if you use a custom
807 # error class at this point, but we should still get rid of this
808 # at some point
80961150µs6141µs $env->{'$meta'} = \($self->associated_class);
# spent 41µs making 61 calls to Class::MOP::Attribute::associated_class, avg 674ns/call
810
8116192µs return $env;
812}
813
814sub _weaken_value {
815 my ( $self, $instance ) = @_;
816
817 my $meta_instance = Class::MOP::Class->initialize( blessed($instance) )
818 ->get_meta_instance;
819
820 $meta_instance->weaken_slot_value( $instance, $self->name );
821}
822
823sub get_value {
824 my ($self, $instance, $for_trigger) = @_;
825
826 if ($self->is_lazy) {
827 unless ($self->has_value($instance)) {
828 my $value;
829 if ($self->has_default) {
830 $value = $self->default($instance);
831 } elsif ( $self->has_builder ) {
832 $value = $self->_call_builder($instance);
833 }
834
835 $value = $self->_coerce_and_verify( $value, $instance );
836
837 $self->set_initial_value($instance, $value);
838
839 if ( ref $value && $self->is_weak_ref ) {
840 $self->_weaken_value($instance);
841 }
842 }
843 }
844
845 if ( $self->should_auto_deref && ! $for_trigger ) {
846
847 my $type_constraint = $self->type_constraint;
848
849 if ($type_constraint->is_a_type_of('ArrayRef')) {
850 my $rv = $self->SUPER::get_value($instance);
851 return unless defined $rv;
852 return wantarray ? @{ $rv } : $rv;
853 }
854 elsif ($type_constraint->is_a_type_of('HashRef')) {
855 my $rv = $self->SUPER::get_value($instance);
856 return unless defined $rv;
857 return wantarray ? %{ $rv } : $rv;
858 }
859 else {
860 $self->throw_error("Can not auto de-reference the type constraint '" . $type_constraint->name . "'", object => $instance, type_constraint => $type_constraint);
861 }
862
863 }
864 else {
865
866 return $self->SUPER::get_value($instance);
867 }
868}
869
870
# spent 6.38ms (192µs+6.19) within Moose::Meta::Attribute::_inline_get_value which was called 27 times, avg 236µs/call: # 22 times (146µs+5.04ms) by Class::MOP::Method::Accessor::try {...} at line 112 of Class/MOP/Method/Accessor.pm, avg 236µs/call # 5 times (46µs+1.15ms) by Class::MOP::Method::Accessor::try {...} at line 142 of Class/MOP/Method/Accessor.pm, avg 238µs/call
sub _inline_get_value {
871274µs my $self = shift;
872277µs my ($instance, $tc, $coercion, $message) = @_;
873
8742728µs27907µs my $slot_access = $self->_inline_instance_get($instance);
# spent 907µs making 27 calls to Class::MOP::Attribute::_inline_instance_get, avg 34µs/call
875274µs $tc ||= '$type_constraint';
876273µs $coercion ||= '$type_coercion';
877272µs $message ||= '$type_message';
878
879 return (
8802785µs545.28ms $self->_inline_check_lazy($instance, $tc, $coercion, $message),
# spent 5.05ms making 27 calls to Moose::Meta::Attribute::_inline_check_lazy, avg 187µs/call # spent 230µs making 27 calls to Moose::Meta::Attribute::_inline_return_auto_deref, avg 8µs/call
881 $self->_inline_return_auto_deref($slot_access),
882 );
883}
884
885
# spent 10.7ms (348µs+10.4) within Moose::Meta::Attribute::_inline_check_lazy which was called 53 times, avg 203µs/call: # 27 times (159µs+4.89ms) by Moose::Meta::Attribute::_inline_get_value at line 880, avg 187µs/call # 26 times (189µs+5.51ms) by Moose::Meta::Method::Accessor::_inline_check_lazy at line 107 of Moose/Meta/Method/Accessor.pm, avg 219µs/call
sub _inline_check_lazy {
886536µs my $self = shift;
8875318µs my ($instance, $tc, $coercion, $message) = @_;
888
8895362µs53121µs return unless $self->is_lazy;
# spent 121µs making 53 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 2µs/call
890
8914344µs43579µs my $slot_exists = $self->_inline_instance_has($instance);
# spent 579µs making 43 calls to Class::MOP::Attribute::_inline_instance_has, avg 13µs/call
892
893 return (
89443123µs439.70ms 'if (!' . $slot_exists . ') {',
# spent 9.70ms making 43 calls to Moose::Meta::Attribute::_inline_init_from_default, avg 226µs/call
895 $self->_inline_init_from_default($instance, '$default', $tc, $coercion, $message, 'lazy'),
896 '}',
897 );
898}
899
900
# spent 9.70ms (590µs+9.11) within Moose::Meta::Attribute::_inline_init_from_default which was called 43 times, avg 226µs/call: # 43 times (590µs+9.11ms) by Moose::Meta::Attribute::_inline_check_lazy at line 894, avg 226µs/call
sub _inline_init_from_default {
901434µs my $self = shift;
9024318µs my ($instance, $default, $tc, $coercion, $message, $for_lazy) = @_;
903
9044347µs5556µs if (!($self->has_default || $self->has_builder)) {
# spent 44µs making 43 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call # spent 12µs making 12 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 1µs/call
905 $self->throw_error(
906 'You cannot have a lazy attribute '
907 . '(' . $self->name . ') '
908 . 'without specifying a default value for it',
909 attr => $self,
910 );
911 }
912
913 return (
91443261µs2589.05ms $self->_inline_generate_default($instance, $default),
# spent 6.27ms making 43 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 146µs/call # spent 1.44ms making 43 calls to Moose::Meta::Attribute::_inline_generate_default, avg 33µs/call # spent 853µs making 43 calls to Moose::Meta::Attribute::_inline_init_slot, avg 20µs/call # spent 277µs making 43 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 6µs/call # spent 164µs making 43 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 4µs/call # spent 47µs making 43 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call
915 # intentionally not using _inline_tc_code, since that can be overridden
916 # to do things like possibly only do member tc checks, which isn't
917 # appropriate for checking the result of a default
918 $self->has_type_constraint
919 ? ($self->_inline_check_coercion($default, $tc, $coercion, $for_lazy),
920 $self->_inline_check_constraint($default, $tc, $message, $for_lazy))
921 : (),
922 $self->_inline_init_slot($instance, $default),
923 $self->_inline_weaken_value($instance, $default),
924 );
925}
926
927
# spent 1.44ms (361µs+1.08) within Moose::Meta::Attribute::_inline_generate_default which was called 43 times, avg 33µs/call: # 43 times (361µs+1.08ms) by Moose::Meta::Attribute::_inline_init_from_default at line 914, avg 33µs/call
sub _inline_generate_default {
928435µs my $self = shift;
929439µs my ($instance, $default) = @_;
930
9314326µs5537µs if ($self->has_default) {
# spent 28µs making 43 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 649ns/call # spent 9µs making 12 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 725ns/call
9323110µs my $source = 'my ' . $default . ' = $attr_default';
9333129µs3160µs $source .= '->(' . $instance . ')'
# spent 60µs making 31 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 2µs/call
934 if $self->is_default_a_coderef;
9353153µs return $source . ';';
936 }
937 elsif ($self->has_builder) {
9381261µs2421µs my $builder = B::perlstring($self->builder);
# spent 14µs making 12 calls to B::perlstring, avg 1µs/call # spent 7µs making 12 calls to Class::MOP::Mixin::AttributeCore::builder, avg 550ns/call
9391224µs125µs my $builder_str = quotemeta($self->builder);
# spent 5µs making 12 calls to Class::MOP::Mixin::AttributeCore::builder, avg 400ns/call
9401222µs124µs my $attr_name_str = quotemeta($self->name);
# spent 4µs making 12 calls to Class::MOP::Mixin::AttributeCore::name, avg 367ns/call
941 return (
9421262µs12951µs 'my ' . $default . ';',
# spent 951µs making 12 calls to Moose::Meta::Attribute::_inline_throw_error, avg 79µs/call
943 'if (my $builder = ' . $instance . '->can(' . $builder . ')) {',
944 $default . ' = ' . $instance . '->$builder;',
945 '}',
946 'else {',
947 'my $class = ref(' . $instance . ') || ' . $instance . ';',
948 $self->_inline_throw_error(
949 '"$class does not support builder method '
950 . '\'' . $builder_str . '\' for attribute '
951 . '\'' . $attr_name_str . '\'"'
952 ) . ';',
953 '}',
954 );
955 }
956 else {
957 $self->throw_error(
958 "Can't generate a default for " . $self->name
959 . " since no default or builder was specified"
960 );
961 }
962}
963
964
# spent 853µs (213+640) within Moose::Meta::Attribute::_inline_init_slot which was called 43 times, avg 20µs/call: # 43 times (213µs+640µs) by Moose::Meta::Attribute::_inline_init_from_default at line 914, avg 20µs/call
sub _inline_init_slot {
965436µs my $self = shift;
966439µs my ($inv, $value) = @_;
967
9684331µs4347µs if ($self->has_initializer) {
# spent 47µs making 43 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 1µs/call
969 return '$attr->set_initial_value(' . $inv . ', ' . $value . ');';
970 }
971 else {
97243103µs43593µs return $self->_inline_instance_set($inv, $value) . ';';
# spent 593µs making 43 calls to Class::MOP::Attribute::_inline_instance_set, avg 14µs/call
973 }
974}
975
976
# spent 230µs (78+151) within Moose::Meta::Attribute::_inline_return_auto_deref which was called 27 times, avg 8µs/call: # 27 times (78µs+151µs) by Moose::Meta::Attribute::_inline_get_value at line 880, avg 8µs/call
sub _inline_return_auto_deref {
977274µs my $self = shift;
978
9792766µs27151µs return 'return ' . $self->_auto_deref(@_) . ';';
# spent 151µs making 27 calls to Moose::Meta::Attribute::_auto_deref, avg 6µs/call
980}
981
982
# spent 151µs (87+64) within Moose::Meta::Attribute::_auto_deref which was called 27 times, avg 6µs/call: # 27 times (87µs+64µs) by Moose::Meta::Attribute::_inline_return_auto_deref at line 979, avg 6µs/call
sub _auto_deref {
983273µs my $self = shift;
984275µs my ($ref_value) = @_;
985
9862769µs2764µs return $ref_value unless $self->should_auto_deref;
# spent 64µs making 27 calls to Moose::Meta::Mixin::AttributeCore::should_auto_deref, avg 2µs/call
987
988 my $type_constraint = $self->type_constraint;
989
990 my $sigil;
991 if ($type_constraint->is_a_type_of('ArrayRef')) {
992 $sigil = '@';
993 }
994 elsif ($type_constraint->is_a_type_of('HashRef')) {
995 $sigil = '%';
996 }
997 else {
998 $self->throw_error(
999 'Can not auto de-reference the type constraint \''
1000 . $type_constraint->name
1001 . '\'',
1002 type_constraint => $type_constraint,
1003 );
1004 }
1005
1006 return 'wantarray '
1007 . '? ' . $sigil . '{ (' . $ref_value . ') || return } '
1008 . ': (' . $ref_value . ')';
1009}
1010
1011## installing accessors
1012
101387130µs
# spent 79µs within Moose::Meta::Attribute::accessor_metaclass which was called 87 times, avg 910ns/call: # 52 times (51µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 205 of Moose/Meta/Attribute/Native/Trait.pm, avg 983ns/call # 35 times (28µs+0s) by Class::MOP::Attribute::try {...} at line 389 of Class/MOP/Attribute.pm, avg 803ns/call
sub accessor_metaclass { 'Moose::Meta::Method::Accessor' }
1014
1015
# spent 117ms (172µs+116) within Moose::Meta::Attribute::install_accessors which was called 30 times, avg 3.88ms/call: # 25 times (127µs+65.9ms) by Class::MOP::Class::try {...} at line 891 of Class/MOP/Class.pm, avg 2.64ms/call # 4 times (39µs+49.5ms) by Class::MOP::Method::Wrapped::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Class/MOP/Method/Wrapped.pm:45] at line 35 of Class/MOP/Method/Wrapped.pm, avg 12.4ms/call # once (6µs+1.03ms) by Class::MOP::Class::_inline_accessors at line 1413 of Class/MOP/Class.pm
sub install_accessors {
1016304µs my $self = shift;
10173034µs3068.7ms $self->SUPER::install_accessors(@_);
# spent 68.7ms making 30 calls to Class::MOP::Attribute::install_accessors, avg 2.29ms/call
10183046µs3447.6ms $self->install_delegation if $self->has_handles;
# spent 47.6ms making 4 calls to Moose::Meta::Attribute::install_delegation, avg 11.9ms/call # spent 72µs making 30 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 2µs/call
10193042µs return;
1020}
1021
1022
# spent 98µs (80+17) within Moose::Meta::Attribute::_check_associated_methods which was called 28 times, avg 3µs/call: # 28 times (80µs+17µs) by Moose::Meta::Class::add_attribute at line 583 of Moose/Meta/Class.pm, avg 3µs/call
sub _check_associated_methods {
1023284µs my $self = shift;
102428105µs2817µs unless (
# spent 17µs making 28 calls to Class::MOP::Attribute::associated_methods, avg 607ns/call
1025 @{ $self->associated_methods }
1026 || ($self->_is_metadata || '') eq 'bare'
1027 ) {
1028 Carp::cluck(
1029 'Attribute (' . $self->name . ') of class '
1030 . $self->associated_class->name
1031 . ' has no associated methods'
1032 . ' (did you mean to provide an "is" argument?)'
1033 . "\n"
1034 )
1035 }
1036}
1037
1038
# spent 61.6ms (490µs+61.1) within Moose::Meta::Attribute::_process_accessors which was called 35 times, avg 1.76ms/call: # 22 times (281µs+46.6ms) by Class::MOP::Attribute::install_accessors at line 424 of Class/MOP/Attribute.pm, avg 2.13ms/call # 8 times (101µs+8.46ms) by Class::MOP::Attribute::install_accessors at line 436 of Class/MOP/Attribute.pm, avg 1.07ms/call # 5 times (108µs+6.02ms) by Class::MOP::Attribute::install_accessors at line 428 of Class/MOP/Attribute.pm, avg 1.23ms/call
sub _process_accessors {
1039354µs my $self = shift;
10403511µs my ($type, $accessor, $generate_as_inline_methods) = @_;
1041
1042358µs $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH';
10433594µs70773µs my $method = $self->associated_class->get_method($accessor);
# spent 758µs making 35 calls to Class::MOP::Mixin::HasMethods::get_method, avg 22µs/call # spent 15µs making 35 calls to Class::MOP::Attribute::associated_class, avg 431ns/call
1044
10453510µs43µs if ( $method
# spent 1µs making 1 call to Class::MOP::Method::Accessor::associated_attribute # spent 1µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 500ns/call # spent 700ns making 1 call to UNIVERSAL::isa
1046 && $method->isa('Class::MOP::Method::Accessor')
1047 && $method->associated_attribute->name ne $self->name ) {
1048
1049 my $other_attr_name = $method->associated_attribute->name;
1050 my $name = $self->name;
1051
1052 Carp::cluck(
1053 "You are overwriting an accessor ($accessor) for the $other_attr_name attribute"
1054 . " with a new accessor method for the $name attribute" );
1055 }
1056
10573518µs24µs if (
# spent 4µs making 1 call to Class::MOP::Method::is_stub # spent 700ns making 1 call to UNIVERSAL::isa
1058 $method
1059 && !$method->is_stub
1060 && !$method->isa('Class::MOP::Method::Accessor')
1061 && ( !$self->definition_context
1062 || $method->package_name eq $self->definition_context->{package} )
1063 ) {
1064
1065 Carp::cluck(
1066 "You are overwriting a locally defined method ($accessor) with "
1067 . "an accessor" );
1068 }
1069
107035203µs138770µs if ( !$self->associated_class->has_method($accessor)
# spent 495µs making 35 calls to Class::MOP::Mixin::HasMethods::has_method, avg 14µs/call # spent 237µs making 34 calls to Class::MOP::Package::has_package_symbol, avg 7µs/call # spent 39µs making 69 calls to Class::MOP::Attribute::associated_class, avg 561ns/call
1071 && $self->associated_class->has_package_symbol( '&' . $accessor ) ) {
1072
1073 Carp::cluck(
1074 "You are overwriting a locally defined function ($accessor) with "
1075 . "an accessor" );
1076 }
1077
10783596µs3559.5ms $self->SUPER::_process_accessors(@_);
# spent 59.5ms making 35 calls to Class::MOP::Attribute::_process_accessors, avg 1.70ms/call
1079}
1080
1081sub remove_accessors {
1082 my $self = shift;
1083 $self->SUPER::remove_accessors(@_);
1084 $self->remove_delegation if $self->has_handles;
1085 return;
1086}
1087
1088
# spent 47.6ms (4.91+42.7) within Moose::Meta::Attribute::install_delegation which was called 4 times, avg 11.9ms/call: # 4 times (4.91ms+42.7ms) by Moose::Meta::Attribute::install_accessors at line 1018, avg 11.9ms/call
sub install_delegation {
10894600ns my $self = shift;
1090
1091 # NOTE:
1092 # Here we canonicalize the 'handles' option
1093 # this will sort out any details and always
1094 # return an hash of methods which we want
1095 # to delagate to, see that method for details
1096411µs4142µs my %handles = $self->_canonicalize_handles;
# spent 142µs making 4 calls to Moose::Meta::Class::__ANON__::SERIAL::1::_canonicalize_handles, avg 36µs/call
1097
1098
1099 # install the delegation ...
1100411µs42µs my $associated_class = $self->associated_class;
# spent 2µs making 4 calls to Class::MOP::Attribute::associated_class, avg 625ns/call
1101431µs45µs foreach my $handle (sort keys %handles) {
# spent 5µs making 4 calls to Moose::Meta::Attribute::CORE:sort, avg 1µs/call
1102266µs my $method_to_call = $handles{$handle};
11032654µs2614µs my $class_name = $associated_class->name;
# spent 14µs making 26 calls to Class::MOP::Package::name, avg 531ns/call
1104268µs my $name = "${class_name}::${handle}";
1105
11062620µs263.22ms if ( my $method = $associated_class->get_method($handle) ) {
# spent 3.22ms making 26 calls to Class::MOP::Mixin::HasMethods::get_method, avg 124µs/call
1107 $self->throw_error(
1108 "You cannot overwrite a locally defined method ($handle) with a delegation",
1109 method_name => $handle
1110 ) unless $method->is_stub;
1111 }
1112
1113 # NOTE:
1114 # handles is not allowed to delegate
1115 # any of these methods, as they will
1116 # override the ones in your class, which
1117 # is almost certainly not what you want.
1118
1119 # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something
1120 #cluck("Not delegating method '$handle' because it is a core method") and
1121264.61ms78136µs next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle);
# spent 64µs making 26 calls to UNIVERSAL::can, avg 2µs/call # spent 51µs making 26 calls to Moose::Meta::Attribute::CORE:match, avg 2µs/call # spent 21µs making 26 calls to UNIVERSAL::isa, avg 819ns/call
1122
11232637µs2637.6ms my $method = $self->_make_delegation_method($handle, $method_to_call);
# spent 37.6ms making 26 calls to Moose::Meta::Class::__ANON__::SERIAL::1::_make_delegation_method, avg 1.45ms/call
1124
112526168µs781.48ms $self->associated_class->add_method($method->name, $method);
# spent 1.44ms making 26 calls to Class::MOP::Mixin::HasMethods::add_method, avg 55µs/call # spent 26µs making 26 calls to Class::MOP::Attribute::associated_class, avg 1µs/call # spent 15µs making 26 calls to Class::MOP::Method::name, avg 562ns/call
11262645µs2643µs $self->associate_method($method);
# spent 43µs making 26 calls to Class::MOP::Attribute::associate_method, avg 2µs/call
1127 }
1128}
1129
1130sub remove_delegation {
1131 my $self = shift;
1132 my %handles = $self->_canonicalize_handles;
1133 my $associated_class = $self->associated_class;
1134 foreach my $handle (keys %handles) {
1135 next unless any { $handle eq $_ }
1136 map { $_->name }
1137 @{ $self->associated_methods };
1138 $self->associated_class->remove_method($handle);
1139 }
1140}
1141
1142# private methods to help delegation ...
1143
1144sub _canonicalize_handles {
1145 my $self = shift;
1146 my $handles = $self->handles;
1147 if (my $handle_type = ref($handles)) {
1148 if ($handle_type eq 'HASH') {
1149 return %{$handles};
1150 }
1151 elsif ($handle_type eq 'ARRAY') {
1152 return map { $_ => $_ } @{$handles};
1153 }
1154 elsif ($handle_type eq 'Regexp') {
1155 ($self->has_type_constraint)
1156 || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)", data => $handles);
1157 return map { ($_ => $_) }
1158 grep { /$handles/ } $self->_get_delegate_method_list;
1159 }
1160 elsif ($handle_type eq 'CODE') {
1161 return $handles->($self, $self->_find_delegate_metaclass);
1162 }
1163 elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) {
1164 return map { $_ => $_ } @{ $handles->methods };
1165 }
1166 elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) {
1167 $handles = $handles->role;
1168 }
1169 else {
1170 $self->throw_error("Unable to canonicalize the 'handles' option with $handles", data => $handles);
1171 }
1172 }
1173
1174 load_class($handles);
1175 my $role_meta = Class::MOP::class_of($handles);
1176
1177 (blessed $role_meta && $role_meta->isa('Moose::Meta::Role'))
1178 || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles);
1179
1180 return map { $_ => $_ }
1181 map { $_->name }
1182 grep { !$_->isa('Class::MOP::Method::Meta') } (
1183 $role_meta->_get_local_methods,
1184 $role_meta->get_required_method_list,
1185 );
1186}
1187
1188sub _get_delegate_method_list {
1189 my $self = shift;
1190 my $meta = $self->_find_delegate_metaclass;
1191 if ($meta->isa('Class::MOP::Class')) {
1192 return map { $_->name } # NOTE: !never! delegate &meta
1193 grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') }
1194 $meta->get_all_methods;
1195 }
1196 elsif ($meta->isa('Moose::Meta::Role')) {
1197 return $meta->get_method_list;
1198 }
1199 else {
1200 $self->throw_error("Unable to recognize the delegate metaclass '$meta'", data => $meta);
1201 }
1202}
1203
1204sub _find_delegate_metaclass {
1205 my $self = shift;
1206 if (my $class = $self->_isa_metadata) {
1207 unless ( is_class_loaded($class) ) {
1208 $self->throw_error(
1209 sprintf(
1210 'The %s attribute is trying to delegate to a class which has not been loaded - %s',
1211 $self->name, $class
1212 )
1213 );
1214 }
1215 # we might be dealing with a non-Moose class,
1216 # and need to make our own metaclass. if there's
1217 # already a metaclass, it will be returned
1218 return Class::MOP::Class->initialize($class);
1219 }
1220 elsif (my $role = $self->_does_metadata) {
1221 unless ( is_class_loaded($class) ) {
1222 $self->throw_error(
1223 sprintf(
1224 'The %s attribute is trying to delegate to a role which has not been loaded - %s',
1225 $self->name, $role
1226 )
1227 );
1228 }
1229
1230 return Class::MOP::class_of($role);
1231 }
1232 else {
1233 $self->throw_error("Cannot find delegate metaclass for attribute " . $self->name);
1234 }
1235}
1236
12375273µs
# spent 36µs within Moose::Meta::Attribute::delegation_metaclass which was called 52 times, avg 687ns/call: # 52 times (36µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 205 of Moose/Meta/Attribute/Native/Trait.pm, avg 687ns/call
sub delegation_metaclass { 'Moose::Meta::Method::Delegation' }
1238
1239sub _make_delegation_method {
1240 my ( $self, $handle_name, $method_to_call ) = @_;
1241
1242 my @curried_arguments;
1243
1244 ($method_to_call, @curried_arguments) = @$method_to_call
1245 if 'ARRAY' eq ref($method_to_call);
1246
1247 return $self->delegation_metaclass->new(
1248 name => $handle_name,
1249 package_name => $self->associated_class->name,
1250 attribute => $self,
1251 delegate_to_method => $method_to_call,
1252 curried_arguments => \@curried_arguments,
1253 );
1254}
1255
1256
# spent 145µs (36+109) within Moose::Meta::Attribute::_coerce_and_verify which was called 4 times, avg 36µs/call: # 4 times (36µs+109µs) by Moose::Meta::Attribute::initialize_instance_slot at line 536, avg 36µs/call
sub _coerce_and_verify {
12574900ns my $self = shift;
12584600ns my $val = shift;
12594600ns my $instance = shift;
1260
126144µs45µs return $val unless $self->has_type_constraint;
# spent 5µs making 4 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call
1262
126344µs44µs $val = $self->type_constraint->coerce($val)
# spent 4µs making 4 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 1µs/call
1264 if $self->should_coerce && $self->type_constraint->has_coercion;
1265
126645µs4100µs $self->verify_against_type_constraint($val, instance => $instance);
# spent 100µs making 4 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 25µs/call
1267
126847µs return $val;
1269}
1270
1271
# spent 100µs (36+64) within Moose::Meta::Attribute::verify_against_type_constraint which was called 4 times, avg 25µs/call: # 4 times (36µs+64µs) by Moose::Meta::Attribute::_coerce_and_verify at line 1266, avg 25µs/call
sub verify_against_type_constraint {
12724700ns my $self = shift;
12734900ns my $val = shift;
1274
127543µs43µs return 1 if !$self->has_type_constraint;
# spent 3µs making 4 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 700ns/call
1276
127743µs44µs my $type_constraint = $self->type_constraint;
# spent 4µs making 4 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 1µs/call
1278
1279414µs457µs $type_constraint->check($val)
# spent 57µs making 4 calls to Moose::Meta::TypeConstraint::check, avg 14µs/call
1280 || $self->throw_error("Attribute ("
1281 . $self->name
1282 . ") does not pass the type constraint because: "
1283 . $type_constraint->get_message($val), data => $val, @_);
1284}
1285
1286package Moose::Meta::Attribute::Custom::Moose;
1287
# spent 4µs within Moose::Meta::Attribute::Custom::Moose::BEGIN@1287 which was called: # once (4µs+0s) by Moose::Meta::TypeCoercion::BEGIN@14 at line 1289
BEGIN {
128815µs $Moose::Meta::Attribute::Custom::Moose::AUTHORITY = 'cpan:STEVAN';
1289152µs14µs}
1290{
12912500ns $Moose::Meta::Attribute::Custom::Moose::VERSION = '2.1005';
1292}
1293sub register_implementation { 'Moose::Meta::Attribute' }
1294
129516µs1;
1296
1297# ABSTRACT: The Moose attribute metaclass
1298
1299__END__