Profile of Moose/Meta/Attribute.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:48 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Attribute.pm
Statements | Executed 1668 statements in 10.5ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 5.32ms | 73.5ms | Moose::Meta::Attribute::::BEGIN@24 Moose::Meta::Attribute::BEGIN@24
1 | 1 | 1 | 1.89ms | 3.09ms | Moose::Meta::Attribute::::BEGIN@13 Moose::Meta::Attribute::BEGIN@13
9 | 2 | 2 | 1.39ms | 5.73ms | Moose::Meta::Attribute::::new Moose::Meta::Attribute::new
1 | 1 | 1 | 715µs | 935µs | Moose::Meta::Attribute::::BEGIN@21 Moose::Meta::Attribute::BEGIN@21
1 | 1 | 1 | 577µs | 776µs | Moose::Meta::Attribute::::BEGIN@22 Moose::Meta::Attribute::BEGIN@22
9 | 1 | 1 | 348µs | 2.17ms | Moose::Meta::Attribute::::_process_options Moose::Meta::Attribute::_process_options
9 | 1 | 1 | 337µs | 696µs | Moose::Meta::Attribute::::_eval_environment Moose::Meta::Attribute::_eval_environment
9 | 2 | 1 | 305µs | 16.3ms | Moose::Meta::Attribute::::_process_accessors Moose::Meta::Attribute::_process_accessors
8 | 2 | 2 | 285µs | 3.78ms | Moose::Meta::Attribute::::_inline_set_value Moose::Meta::Attribute::_inline_set_value
9 | 2 | 2 | 240µs | 1.56ms | Moose::Meta::Attribute::::_inline_throw_error Moose::Meta::Attribute::_inline_throw_error
9 | 2 | 1 | 199µs | 1.70ms | Moose::Meta::Attribute::::_inline_check_constraint Moose::Meta::Attribute::_inline_check_constraint
8 | 1 | 1 | 190µs | 3.44ms | Moose::Meta::Attribute::::initialize_instance_slot Moose::Meta::Attribute::initialize_instance_slot
10 | 2 | 1 | 151µs | 18.0ms | Moose::Meta::Attribute::::install_accessors Moose::Meta::Attribute::install_accessors
8 | 2 | 2 | 143µs | 4.92ms | Moose::Meta::Attribute::::interpolate_class_and_new Moose::Meta::Attribute::interpolate_class_and_new
9 | 2 | 1 | 130µs | 1.25ms | Moose::Meta::Attribute::::_inline_get_value Moose::Meta::Attribute::_inline_get_value
9 | 1 | 1 | 105µs | 1.58ms | Moose::Meta::Attribute::::_process_isa_option Moose::Meta::Attribute::_process_isa_option
8 | 1 | 1 | 91µs | 111µs | Moose::Meta::Attribute::::_check_associated_methods Moose::Meta::Attribute::_check_associated_methods
9 | 2 | 1 | 89µs | 190µs | Moose::Meta::Attribute::::_inline_weaken_value Moose::Meta::Attribute::_inline_weaken_value
9 | 1 | 1 | 80µs | 499µs | Moose::Meta::Attribute::::_inline_check_lazy Moose::Meta::Attribute::_inline_check_lazy
8 | 1 | 1 | 74µs | 1.69ms | Moose::Meta::Attribute::::_inline_tc_code Moose::Meta::Attribute::_inline_tc_code
9 | 1 | 1 | 66µs | 72µs | Moose::Meta::Attribute::::_error_thrower Moose::Meta::Attribute::_error_thrower
9 | 1 | 1 | 61µs | 129µs | Moose::Meta::Attribute::::_auto_deref Moose::Meta::Attribute::_auto_deref
8 | 1 | 1 | 61µs | 160µs | Moose::Meta::Attribute::::_writer_value_needs_copy Moose::Meta::Attribute::_writer_value_needs_copy
8 | 1 | 1 | 58µs | 58µs | Moose::Meta::Attribute::::interpolate_class Moose::Meta::Attribute::interpolate_class
8 | 1 | 1 | 58µs | 133µs | Moose::Meta::Attribute::::_inline_check_required Moose::Meta::Attribute::_inline_check_required
8 | 1 | 1 | 56µs | 121µs | Moose::Meta::Attribute::::_inline_get_old_value_for_trigger Moose::Meta::Attribute::_inline_get_old_value_for_trigger
9 | 1 | 1 | 52µs | 52µs | Moose::Meta::Attribute::::_process_is_option Moose::Meta::Attribute::_process_is_option
9 | 1 | 1 | 51µs | 180µs | Moose::Meta::Attribute::::_inline_return_auto_deref Moose::Meta::Attribute::_inline_return_auto_deref
9 | 2 | 1 | 48µs | 109µs | Moose::Meta::Attribute::::_inline_check_coercion Moose::Meta::Attribute::_inline_check_coercion
3 | 1 | 1 | 42µs | 136µs | Moose::Meta::Attribute::::verify_against_type_constraint Moose::Meta::Attribute::verify_against_type_constraint
8 | 1 | 1 | 41µs | 96µs | Moose::Meta::Attribute::::_inline_trigger Moose::Meta::Attribute::_inline_trigger
4 | 1 | 1 | 38µs | 189µs | Moose::Meta::Attribute::::_coerce_and_verify Moose::Meta::Attribute::_coerce_and_verify
1 | 1 | 1 | 31µs | 279µs | Moose::Meta::Attribute::::_inline_init_from_default Moose::Meta::Attribute::_inline_init_from_default
9 | 1 | 1 | 30µs | 30µs | Moose::Meta::Attribute::::_process_does_option Moose::Meta::Attribute::_process_does_option
9 | 1 | 1 | 29µs | 29µs | Moose::Meta::Attribute::::_process_auto_deref_option Moose::Meta::Attribute::_process_auto_deref_option
9 | 1 | 1 | 28µs | 28µs | Moose::Meta::Attribute::::_process_coerce_option Moose::Meta::Attribute::_process_coerce_option
9 | 1 | 1 | 27µs | 27µs | Moose::Meta::Attribute::::_process_trigger_option Moose::Meta::Attribute::_process_trigger_option
9 | 1 | 1 | 26µs | 26µs | Moose::Meta::Attribute::::_process_required_option Moose::Meta::Attribute::_process_required_option
9 | 1 | 1 | 25µs | 25µs | Moose::Meta::Attribute::::_process_lazy_build_option Moose::Meta::Attribute::_process_lazy_build_option
9 | 1 | 1 | 24µs | 24µs | Moose::Meta::Attribute::::_process_lazy_option Moose::Meta::Attribute::_process_lazy_option
9 | 1 | 1 | 14µs | 14µs | Moose::Meta::Attribute::::accessor_metaclass Moose::Meta::Attribute::accessor_metaclass
1 | 1 | 1 | 14µs | 32µs | Moose::Meta::Attribute::::_inline_init_slot Moose::Meta::Attribute::_inline_init_slot
1 | 1 | 1 | 13µs | 71µs | Moose::Meta::Attribute::::BEGIN@14 Moose::Meta::Attribute::BEGIN@14
1 | 1 | 1 | 12µs | 18µs | Moose::Meta::Attribute::::_inline_generate_default Moose::Meta::Attribute::_inline_generate_default
9 | 1 | 1 | 12µs | 12µs | Moose::Meta::Attribute::::CORE:sort Moose::Meta::Attribute::CORE:sort (opcode)
1 | 1 | 1 | 11µs | 11µs | Moose::Meta::Attribute::Custom::Moose::::BEGIN@1283Moose::Meta::Attribute::Custom::Moose::BEGIN@1283
1 | 1 | 1 | 8µs | 8µs | Moose::Meta::Attribute::::BEGIN@3 Moose::Meta::Attribute::BEGIN@3
1 | 1 | 1 | 8µs | 17µs | Moose::Meta::Attribute::::BEGIN@20 Moose::Meta::Attribute::BEGIN@20
1 | 1 | 1 | 8µs | 36µs | Moose::Meta::Attribute::::BEGIN@15 Moose::Meta::Attribute::BEGIN@15
1 | 1 | 1 | 8µs | 5.83ms | Moose::Meta::Attribute::::BEGIN@27 Moose::Meta::Attribute::BEGIN@27
1 | 1 | 1 | 8µs | 28µs | Moose::Meta::Attribute::::BEGIN@16 Moose::Meta::Attribute::BEGIN@16
1 | 1 | 1 | 8µs | 8µs | Moose::Meta::Attribute::::BEGIN@25 Moose::Meta::Attribute::BEGIN@25
1 | 1 | 1 | 8µs | 20µs | Moose::Meta::Attribute::::BEGIN@11 Moose::Meta::Attribute::BEGIN@11
1 | 1 | 1 | 7µs | 11µs | Moose::Meta::Attribute::::BEGIN@10 Moose::Meta::Attribute::BEGIN@10
1 | 1 | 1 | 7µs | 38µs | Moose::Meta::Attribute::::BEGIN@17 Moose::Meta::Attribute::BEGIN@17
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::Attribute::::BEGIN@23 Moose::Meta::Attribute::BEGIN@23
1 | 1 | 1 | 3µs | 3µs | Moose::Meta::Attribute::::BEGIN@18 Moose::Meta::Attribute::BEGIN@18
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::Custom::Moose::::register_implementationMoose::Meta::Attribute::Custom::Moose::register_implementation
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::__ANON__[:1131] Moose::Meta::Attribute::__ANON__[:1131]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::__ANON__[:154] Moose::Meta::Attribute::__ANON__[:154]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::__ANON__[:350] Moose::Meta::Attribute::__ANON__[:350]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::__ANON__[:45] Moose::Meta::Attribute::__ANON__[:45]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::__ANON__[:566] Moose::Meta::Attribute::__ANON__[:566]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_call_builder Moose::Meta::Attribute::_call_builder
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_canonicalize_handles Moose::Meta::Attribute::_canonicalize_handles
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_find_delegate_metaclass Moose::Meta::Attribute::_find_delegate_metaclass
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_get_delegate_method_list Moose::Meta::Attribute::_get_delegate_method_list
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_inline_copy_value Moose::Meta::Attribute::_inline_copy_value
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_make_delegation_method Moose::Meta::Attribute::_make_delegation_method
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_make_initializer_writer_callback Moose::Meta::Attribute::_make_initializer_writer_callback
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::_weaken_value Moose::Meta::Attribute::_weaken_value
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::clone Moose::Meta::Attribute::clone
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::clone_and_inherit_options Moose::Meta::Attribute::clone_and_inherit_options
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::delegation_metaclass Moose::Meta::Attribute::delegation_metaclass
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::does Moose::Meta::Attribute::does
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::get_value Moose::Meta::Attribute::get_value
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::illegal_options_for_inheritance Moose::Meta::Attribute::illegal_options_for_inheritance
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::install_delegation Moose::Meta::Attribute::install_delegation
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::remove_accessors Moose::Meta::Attribute::remove_accessors
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::remove_delegation Moose::Meta::Attribute::remove_delegation
0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::::set_value Moose::Meta::Attribute::set_value
0 | 0 | 0 | 0s | 0s | Moose::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 |  |  |  |  |
2 |  |  |  |  | package 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 {
4 | 1 | 4µs |  |  | $Moose::Meta::Attribute::AUTHORITY = 'cpan:STEVAN';
5 | 1 | 22µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::Attribute::BEGIN@3
6 |  |  |  |  | {
7 | 2 | 2µs |  |  | $Moose::Meta::Attribute::VERSION = '2.0602';
8 |  |  |  |  | }
9 |  |  |  |  |
10 | 3 | 17µs | 2 | 14µs | # spent 11µs (7+3) within Moose::Meta::Attribute::BEGIN@10 which was called: # once (7µs+3µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 10 use strict; # spent 11µs making 1 call to Moose::Meta::Attribute::BEGIN@10 # spent 3µs making 1 call to strict::import
11 | 3 | 18µs | 2 | 32µs | # spent 20µs (8+12) within Moose::Meta::Attribute::BEGIN@11 which was called: # once (8µs+12µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 11 use warnings; # spent 20µs making 1 call to Moose::Meta::Attribute::BEGIN@11 # spent 12µs making 1 call to warnings::import
12 |  |  |  |  |
13 | 3 | 121µs | 1 | 3.09ms | # spent 3.09ms (1.89+1.20) within Moose::Meta::Attribute::BEGIN@13 which was called: # once (1.89ms+1.20ms) by Moose::Meta::TypeCoercion::BEGIN@14 at line 13 use B (); # spent 3.09ms making 1 call to Moose::Meta::Attribute::BEGIN@13
14 | 3 | 26µs | 2 | 130µs | # spent 71µs (13+58) within Moose::Meta::Attribute::BEGIN@14 which was called: # once (13µs+58µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 14 use Class::Load qw(is_class_loaded load_class); # spent 71µs making 1 call to Moose::Meta::Attribute::BEGIN@14 # spent 58µs making 1 call to Exporter::import
15 | 3 | 20µs | 2 | 63µs | # spent 36µs (8+27) within Moose::Meta::Attribute::BEGIN@15 which was called: # once (8µs+27µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 15 use Scalar::Util 'blessed', 'weaken'; # spent 36µs making 1 call to Moose::Meta::Attribute::BEGIN@15 # spent 27µs making 1 call to Exporter::import
16 | 3 | 18µs | 2 | 48µs | # spent 28µs (8+20) within Moose::Meta::Attribute::BEGIN@16 which was called: # once (8µs+20µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 16 use List::MoreUtils 'any'; # spent 28µs making 1 call to Moose::Meta::Attribute::BEGIN@16 # spent 20µs making 1 call to Exporter::import
17 | 3 | 17µs | 2 | 68µs | # spent 38µs (7+31) within Moose::Meta::Attribute::BEGIN@17 which was called: # once (7µs+31µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 17 use Try::Tiny; # spent 38µs making 1 call to Moose::Meta::Attribute::BEGIN@17 # spent 31µs making 1 call to Exporter::import
18 | 3 | 16µs | 1 | 3µ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 |  |  |  |  |
20 | 3 | 18µs | 2 | 26µs | # spent 17µs (8+9) within Moose::Meta::Attribute::BEGIN@20 which was called: # once (8µs+9µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 20 use Moose::Deprecated; # spent 17µs making 1 call to Moose::Meta::Attribute::BEGIN@20 # spent 9µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61]
21 | 3 | 150µs | 1 | 935µs | # spent 935µs (715+220) within Moose::Meta::Attribute::BEGIN@21 which was called: # once (715µs+220µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 21 use Moose::Meta::Method::Accessor; # spent 935µs making 1 call to Moose::Meta::Attribute::BEGIN@21
22 | 3 | 81µs | 1 | 776µs | # spent 776µs (577+199) within Moose::Meta::Attribute::BEGIN@22 which was called: # once (577µs+199µs) by Moose::Meta::TypeCoercion::BEGIN@14 at line 22 use Moose::Meta::Method::Delegation; # spent 776µs making 1 call to Moose::Meta::Attribute::BEGIN@22
23 | 3 | 17µs | 1 | 4µ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
24 | 3 | 94µs | 1 | 73.5ms | # spent 73.5ms (5.32+68.2) within Moose::Meta::Attribute::BEGIN@24 which was called: # once (5.32ms+68.2ms) by Moose::Meta::TypeCoercion::BEGIN@14 at line 24 use Moose::Util::TypeConstraints (); # spent 73.5ms making 1 call to Moose::Meta::Attribute::BEGIN@24
25 | 3 | 24µs | 1 | 8µs | # spent 8µs within Moose::Meta::Attribute::BEGIN@25 which was called: # once (8µs+0s) by Moose::Meta::TypeCoercion::BEGIN@14 at line 25 use Class::MOP::MiniTrait; # spent 8µs making 1 call to Moose::Meta::Attribute::BEGIN@25
26 |  |  |  |  |
27 | 3 | 4.46ms | 2 | 11.6ms | # spent 5.83ms (8µs+5.82) within Moose::Meta::Attribute::BEGIN@27 which was called: # once (8µs+5.82ms) by Moose::Meta::TypeCoercion::BEGIN@14 at line 27 use base 'Class::MOP::Attribute', 'Moose::Meta::Mixin::AttributeCore'; # spent 5.83ms making 1 call to Moose::Meta::Attribute::BEGIN@27 # spent 5.82ms making 1 call to base::import
28 |  |  |  |  |
29 | 1 | 6µs | 1 | 1.73ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 1.73ms making 1 call to Class::MOP::MiniTrait::apply
30 |  |  |  |  |
31 | 1 | 16µs | 3 | 659µs | __PACKAGE__->meta->add_attribute('traits' => ( # spent 630µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 16µs making 1 call to Class::MOP::Object::meta # spent 12µ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 |  |  |  |  | sub does {
42 |  |  |  |  | my ($self, $role_name) = @_;
43 |  |  |  |  | my $name = try {
44 |  |  |  |  | Moose::Util::resolve_metatrait_alias(Attribute => $role_name)
45 |  |  |  |  | };
46 |  |  |  |  | return 0 if !defined($name); # failed to load class
47 |  |  |  |  | return $self->Moose::Object::does($name);
48 |  |  |  |  | }
49 |  |  |  |  |
50 |  |  |  |  | # spent 72µs (66+6) within Moose::Meta::Attribute::_error_thrower which was called 9 times, avg 8µs/call: # 9 times (66µs+6µs) by Moose::Meta::Attribute::_inline_throw_error at line 69, avg 8µs/call sub _error_thrower {
51 | 27 | 74µs |  |  | my $self = shift;
52 |  |  |  |  | require Moose::Meta::Class;
53 |  |  | 9 | 6µs | ( ref $self && $self->associated_class ) || "Moose::Meta::Class"; # spent 6µs making 9 calls to Class::MOP::Attribute::associated_class, avg 633ns/call
54 |  |  |  |  | }
55 |  |  |  |  |
56 |  |  |  |  | sub 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 1.56ms (240µs+1.32) within Moose::Meta::Attribute::_inline_throw_error which was called 9 times, avg 173µs/call: # 6 times (150µs+862µs) by Moose::Meta::Attribute::_inline_check_constraint at line 707, avg 169µs/call # 3 times (90µs+453µs) by Moose::Meta::Method::_inline_throw_error at line 51 of Moose/Meta/Method.pm, avg 181µs/call sub _inline_throw_error {
67 | 54 | 164µs |  |  | my ( $self, $msg, $args ) = @_;
68 |  |  |  |  |
69 |  |  | 9 | 72µs | my $inv = $self->_error_thrower; # spent 72µs making 9 calls to Moose::Meta::Attribute::_error_thrower, avg 8µs/call
70 |  |  |  |  | # XXX ugh
71 |  |  | 9 | 21µs | $inv = 'Moose::Meta::Class' unless $inv->can('_inline_throw_error'); # spent 21µs making 9 calls to UNIVERSAL::can, avg 2µs/call
72 |  |  |  |  |
73 |  |  |  |  | # XXX ugh ugh UGH
74 |  |  | 9 | 5µs | my $class = $self->associated_class; # spent 5µs making 9 calls to Class::MOP::Attribute::associated_class, avg 533ns/call
75 | 27 | 135µs |  |  | if ($class) {
76 |  |  | 18 | 24µs | my $class_name = B::perlstring($class->name); # spent 19µs making 9 calls to B::perlstring, avg 2µs/call # spent 5µs making 9 calls to Class::MOP::Package::name, avg 567ns/call
77 |  |  | 18 | 12µs | my $attr_name = B::perlstring($self->name); # spent 8µs making 9 calls to B::perlstring, avg 867ns/call # spent 5µs making 9 calls to Class::MOP::Mixin::AttributeCore::name, avg 522ns/call
78 |  |  |  |  | $args = 'attr => Class::MOP::class_of(' . $class_name . ')'
79 |  |  |  |  | . '->find_attribute_by_name(' . $attr_name . '), '
80 |  |  |  |  | . (defined $args ? $args : '');
81 |  |  |  |  | }
82 |  |  |  |  |
83 |  |  | 9 | 1.18ms | return $inv->_inline_throw_error($msg, $args) # spent 1.18ms making 9 calls to Moose::Meta::Class::_inline_throw_error, avg 131µs/call
84 |  |  |  |  | }
85 |  |  |  |  |
86 |  |  |  |  | # spent 5.73ms (1.39+4.34) within Moose::Meta::Attribute::new which was called 9 times, avg 637µs/call: # 8 times (1.25ms+3.47ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 114, avg 590µs/call # once (143µs+875µs) by Moose::BEGIN@30 at line 23 of Moose/Meta/TypeCoercion.pm sub new {
87 | 63 | 767µs |  |  | my ($class, $name, %options) = @_;
88 |  |  | 9 | 2.17ms | $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS # spent 2.17ms making 9 calls to Moose::Meta::Attribute::_process_options, avg 241µs/call
89 |  |  |  |  |
90 |  |  |  |  | delete $options{__hack_no_process_options};
91 |  |  |  |  |
92 |  |  |  |  | my %attrs =
93 |  |  |  |  | ( map { $_ => 1 }
94 |  |  | 252 | 224µs | grep { defined } # spent 224µs making 252 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 888ns/call
95 | 252 | 852µs | 18 | 613µs | map { $_->init_arg() } # spent 313µs making 8 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 39µs/call # spent 192µs making 9 calls to Class::MOP::Object::meta, avg 21µs/call # spent 108µs making 1 call to Class::MOP::Class::get_all_attributes
96 |  |  |  |  | $class->meta()->get_all_attributes()
97 |  |  |  |  | );
98 |  |  |  |  |
99 |  |  | 9 | 12µs | my @bad = sort grep { ! $attrs{$_} } keys %options; # spent 12µs making 9 calls to Moose::Meta::Attribute::CORE:sort, avg 1µs/call
100 |  |  |  |  |
101 |  |  |  |  | if (@bad)
102 |  |  |  |  | {
103 |  |  |  |  | Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad";
104 |  |  |  |  | }
105 |  |  |  |  |
106 |  |  | 9 | 1.33ms | return $class->SUPER::new($name, %options); # spent 1.33ms making 9 calls to Class::MOP::Attribute::new, avg 148µs/call
107 |  |  |  |  | }
108 |  |  |  |  |
109 |  |  |  |  | # spent 4.92ms (143µs+4.77) within Moose::Meta::Attribute::interpolate_class_and_new which was called 8 times, avg 615µs/call: # 6 times (90µs+2.25ms) by Moose::Meta::Class::_process_new_attribute at line 704 of Moose/Meta/Class.pm, avg 391µs/call # 2 times (53µs+2.52ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 91 of Moose/Meta/Role/Attribute.pm, avg 1.29ms/call sub interpolate_class_and_new {
110 | 24 | 127µs |  |  | my ($class, $name, %args) = @_;
111 |  |  |  |  |
112 |  |  | 8 | 58µs | my ( $new_class, @traits ) = $class->interpolate_class(\%args); # spent 58µs making 8 calls to Moose::Meta::Attribute::interpolate_class, avg 7µs/call
113 |  |  |  |  |
114 |  |  | 8 | 4.72ms | $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) ); # spent 4.72ms making 8 calls to Moose::Meta::Attribute::new, avg 590µs/call
115 |  |  |  |  | }
116 |  |  |  |  |
117 |  |  |  |  | # spent 58µs within Moose::Meta::Attribute::interpolate_class which was called 8 times, avg 7µs/call: # 8 times (58µs+0s) by Moose::Meta::Attribute::interpolate_class_and_new at line 112, avg 7µs/call sub interpolate_class {
118 | 48 | 70µs |  |  | my ($class, $options) = @_;
119 |  |  |  |  |
120 |  |  |  |  | $class = ref($class) || $class;
121 |  |  |  |  |
122 |  |  |  |  | if ( my $metaclass_name = delete $options->{metaclass} ) {
123 |  |  |  |  | my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name );
124 |  |  |  |  |
125 |  |  |  |  | if ( $class ne $new_class ) {
126 |  |  |  |  | if ( $new_class->can("interpolate_class") ) {
127 |  |  |  |  | return $new_class->interpolate_class($options);
128 |  |  |  |  | } else {
129 |  |  |  |  | $class = $new_class;
130 |  |  |  |  | }
131 |  |  |  |  | }
132 |  |  |  |  | }
133 |  |  |  |  |
134 |  |  |  |  | my @traits;
135 |  |  |  |  |
136 |  |  |  |  | if (my $traits = $options->{traits}) {
137 |  |  |  |  | my $i = 0;
138 |  |  |  |  | my $has_foreign_options = 0;
139 |  |  |  |  |
140 |  |  |  |  | while ($i < @$traits) {
141 |  |  |  |  | my $trait = $traits->[$i++];
142 |  |  |  |  | next if ref($trait); # options to a trait we discarded
143 |  |  |  |  |
144 |  |  |  |  | $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait)
145 |  |  |  |  | || $trait;
146 |  |  |  |  |
147 |  |  |  |  | next if $class->does($trait);
148 |  |  |  |  |
149 |  |  |  |  | push @traits, $trait;
150 |  |  |  |  |
151 |  |  |  |  | # are there options?
152 |  |  |  |  | if ($traits->[$i] && ref($traits->[$i])) {
153 |  |  |  |  | $has_foreign_options = 1
154 |  |  |  |  | if any { $_ ne '-alias' && $_ ne '-excludes' } keys %{ $traits->[$i] };
155 |  |  |  |  |
156 |  |  |  |  | push @traits, $traits->[$i++];
157 |  |  |  |  | }
158 |  |  |  |  | }
159 |  |  |  |  |
160 |  |  |  |  | if (@traits) {
161 |  |  |  |  | my %options = (
162 |  |  |  |  | superclasses => [ $class ],
163 |  |  |  |  | roles => [ @traits ],
164 |  |  |  |  | );
165 |  |  |  |  |
166 |  |  |  |  | if ($has_foreign_options) {
167 |  |  |  |  | $options{weaken} = 0;
168 |  |  |  |  | }
169 |  |  |  |  | else {
170 |  |  |  |  | $options{cache} = 1;
171 |  |  |  |  | }
172 |  |  |  |  |
173 |  |  |  |  | my $anon_class = Moose::Meta::Class->create_anon_class(%options);
174 |  |  |  |  | $class = $anon_class->name;
175 |  |  |  |  | }
176 |  |  |  |  | }
177 |  |  |  |  |
178 |  |  |  |  | return ( wantarray ? ( $class, @traits ) : $class );
179 |  |  |  |  | }
180 |  |  |  |  |
181 |  |  |  |  | # ...
182 |  |  |  |  |
183 |  |  |  |  | # method-generating options shouldn't be overridden
184 |  |  |  |  | sub illegal_options_for_inheritance {
185 |  |  |  |  | qw(reader writer accessor clearer predicate)
186 |  |  |  |  | }
187 |  |  |  |  |
188 |  |  |  |  | # NOTE/TODO
189 |  |  |  |  | # This method *must* be able to handle
190 |  |  |  |  | # Class::MOP::Attribute instances as
191 |  |  |  |  | # well. Yes, I know that is wrong, but
192 |  |  |  |  | # apparently we didn't realize it was
193 |  |  |  |  | # doing that and now we have some code
194 |  |  |  |  | # which is dependent on it. The real
195 |  |  |  |  | # solution of course is to push this
196 |  |  |  |  | # feature back up into Class::MOP::Attribute
197 |  |  |  |  | # but I not right now, I am too lazy.
198 |  |  |  |  | # However if you are reading this and
199 |  |  |  |  | # looking for something to do,.. please
200 |  |  |  |  | # be my guest.
201 |  |  |  |  | # - stevan
202 |  |  |  |  | sub clone_and_inherit_options {
203 |  |  |  |  | my ($self, %options) = @_;
204 |  |  |  |  |
205 |  |  |  |  | # NOTE:
206 |  |  |  |  | # we may want to extends a Class::MOP::Attribute
207 |  |  |  |  | # in which case we need to be able to use the
208 |  |  |  |  | # core set of legal options that have always
209 |  |  |  |  | # been here. But we allows Moose::Meta::Attribute
210 |  |  |  |  | # instances to changes them.
211 |  |  |  |  | # - SL
212 |  |  |  |  | my @illegal_options = $self->can('illegal_options_for_inheritance')
213 |  |  |  |  | ? $self->illegal_options_for_inheritance
214 |  |  |  |  | : ();
215 |  |  |  |  |
216 |  |  |  |  | my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options;
217 |  |  |  |  | (scalar @found_illegal_options == 0)
218 |  |  |  |  | || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options);
219 |  |  |  |  |
220 |  |  |  |  | if ($options{isa}) {
221 |  |  |  |  | my $type_constraint;
222 |  |  |  |  | if (blessed($options{isa}) && $options{isa}->isa('Moose::Meta::TypeConstraint')) {
223 |  |  |  |  | $type_constraint = $options{isa};
224 |  |  |  |  | }
225 |  |  |  |  | else {
226 |  |  |  |  | $type_constraint = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($options{isa}, { package_defined_in => $options{definition_context}->{package} });
227 |  |  |  |  | (defined $type_constraint)
228 |  |  |  |  | || $self->throw_error("Could not find the type constraint '" . $options{isa} . "'", data => $options{isa});
229 |  |  |  |  | }
230 |  |  |  |  |
231 |  |  |  |  | $options{type_constraint} = $type_constraint;
232 |  |  |  |  | }
233 |  |  |  |  |
234 |  |  |  |  | if ($options{does}) {
235 |  |  |  |  | my $type_constraint;
236 |  |  |  |  | if (blessed($options{does}) && $options{does}->isa('Moose::Meta::TypeConstraint')) {
237 |  |  |  |  | $type_constraint = $options{does};
238 |  |  |  |  | }
239 |  |  |  |  | else {
240 |  |  |  |  | $type_constraint = Moose::Util::TypeConstraints::find_or_create_does_type_constraint($options{does}, { package_defined_in => $options{definition_context}->{package} });
241 |  |  |  |  | (defined $type_constraint)
242 |  |  |  |  | || $self->throw_error("Could not find the type constraint '" . $options{does} . "'", data => $options{does});
243 |  |  |  |  | }
244 |  |  |  |  |
245 |  |  |  |  | $options{type_constraint} = $type_constraint;
246 |  |  |  |  | }
247 |  |  |  |  |
248 |  |  |  |  | # NOTE:
249 |  |  |  |  | # this doesn't apply to Class::MOP::Attributes,
250 |  |  |  |  | # so we can ignore it for them.
251 |  |  |  |  | # - SL
252 |  |  |  |  | if ($self->can('interpolate_class')) {
253 |  |  |  |  | ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options);
254 |  |  |  |  |
255 |  |  |  |  | my %seen;
256 |  |  |  |  | my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits;
257 |  |  |  |  | $options{traits} = \@all_traits if @all_traits;
258 |  |  |  |  | }
259 |  |  |  |  |
260 |  |  |  |  | # This method can be called on a CMOP::Attribute object, so we need to
261 |  |  |  |  | # make sure we can call this method.
262 |  |  |  |  | $self->_process_lazy_build_option( $self->name, \%options )
263 |  |  |  |  | if $self->can('_process_lazy_build_option');
264 |  |  |  |  |
265 |  |  |  |  | $self->clone(%options);
266 |  |  |  |  | }
267 |  |  |  |  |
268 |  |  |  |  | sub clone {
269 |  |  |  |  | my ( $self, %params ) = @_;
270 |  |  |  |  |
271 |  |  |  |  | my $class = delete $params{metaclass} || ref $self;
272 |  |  |  |  |
273 |  |  |  |  | my ( @init, @non_init );
274 |  |  |  |  |
275 |  |  |  |  | foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) {
276 |  |  |  |  | push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr;
277 |  |  |  |  | }
278 |  |  |  |  |
279 |  |  |  |  | my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params );
280 |  |  |  |  |
281 |  |  |  |  | my $name = delete $new_params{name};
282 |  |  |  |  |
283 |  |  |  |  | my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 );
284 |  |  |  |  |
285 |  |  |  |  | foreach my $attr ( @non_init ) {
286 |  |  |  |  | $attr->set_value($clone, $attr->get_value($self));
287 |  |  |  |  | }
288 |  |  |  |  |
289 |  |  |  |  | return $clone;
290 |  |  |  |  | }
291 |  |  |  |  |
292 |  |  |  |  | # spent 2.17ms (348µs+1.82) within Moose::Meta::Attribute::_process_options which was called 9 times, avg 241µs/call: # 9 times (348µs+1.82ms) by Moose::Meta::Attribute::new at line 88, avg 241µs/call sub _process_options {
293 | 90 | 256µs |  |  | my ( $class, $name, $options ) = @_;
294 |  |  |  |  |
295 |  |  | 9 | 52µs | $class->_process_is_option( $name, $options ); # spent 52µs making 9 calls to Moose::Meta::Attribute::_process_is_option, avg 6µs/call
296 |  |  | 9 | 1.58ms | $class->_process_isa_option( $name, $options ); # spent 1.58ms making 9 calls to Moose::Meta::Attribute::_process_isa_option, avg 175µs/call
297 |  |  | 9 | 30µs | $class->_process_does_option( $name, $options ); # spent 30µs making 9 calls to Moose::Meta::Attribute::_process_does_option, avg 3µs/call
298 |  |  | 9 | 28µs | $class->_process_coerce_option( $name, $options ); # spent 28µs making 9 calls to Moose::Meta::Attribute::_process_coerce_option, avg 3µs/call
299 |  |  | 9 | 27µs | $class->_process_trigger_option( $name, $options ); # spent 27µs making 9 calls to Moose::Meta::Attribute::_process_trigger_option, avg 3µs/call
300 |  |  | 9 | 29µs | $class->_process_auto_deref_option( $name, $options ); # spent 29µs making 9 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 3µs/call
301 |  |  | 9 | 25µs | $class->_process_lazy_build_option( $name, $options ); # spent 25µs making 9 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 3µs/call
302 |  |  | 9 | 24µs | $class->_process_lazy_option( $name, $options ); # spent 24µs making 9 calls to Moose::Meta::Attribute::_process_lazy_option, avg 3µs/call
303 |  |  | 9 | 26µs | $class->_process_required_option( $name, $options ); # spent 26µs making 9 calls to Moose::Meta::Attribute::_process_required_option, avg 3µs/call
304 |  |  |  |  | }
305 |  |  |  |  |
306 |  |  |  |  | # spent 52µs within Moose::Meta::Attribute::_process_is_option which was called 9 times, avg 6µs/call: # 9 times (52µs+0s) by Moose::Meta::Attribute::_process_options at line 295, avg 6µs/call sub _process_is_option {
307 | 26 | 60µs |  |  | my ( $class, $name, $options ) = @_;
308 |  |  |  |  |
309 |  |  |  |  | return unless $options->{is};
310 |  |  |  |  |
311 |  |  |  |  | ### -------------------------
312 |  |  |  |  | ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before
313 |  |  |  |  | ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo)
314 |  |  |  |  | ## is => rw, accessor => _foo # turns into (accessor => _foo)
315 |  |  |  |  | ## is => ro, accessor => _foo # error, accesor is rw
316 |  |  |  |  | ### -------------------------
317 |  |  |  |  |
318 | 8 | 8µs |  |  | if ( $options->{is} eq 'ro' ) {
319 |  |  |  |  | $class->throw_error(
320 |  |  |  |  | "Cannot define an accessor name on a read-only attribute, accessors are read/write",
321 |  |  |  |  | data => $options )
322 |  |  |  |  | if exists $options->{accessor};
323 |  |  |  |  | $options->{reader} ||= $name;
324 |  |  |  |  | }
325 |  |  |  |  | elsif ( $options->{is} eq 'rw' ) {
326 |  |  |  |  | if ( $options->{writer} ) {
327 |  |  |  |  | $options->{reader} ||= $name;
328 |  |  |  |  | }
329 |  |  |  |  | else {
330 |  |  |  |  | $options->{accessor} ||= $name;
331 |  |  |  |  | }
332 |  |  |  |  | }
333 |  |  |  |  | elsif ( $options->{is} eq 'bare' ) {
334 |  |  |  |  | return;
335 |  |  |  |  | # do nothing, but don't complain (later) about missing methods
336 |  |  |  |  | }
337 |  |  |  |  | else {
338 |  |  |  |  | $class->throw_error( "I do not understand this option (is => "
339 |  |  |  |  | . $options->{is}
340 |  |  |  |  | . ") on attribute ($name)", data => $options->{is} );
341 |  |  |  |  | }
342 |  |  |  |  | }
343 |  |  |  |  |
344 |  |  |  |  | # spent 1.58ms (105µs+1.47) within Moose::Meta::Attribute::_process_isa_option which was called 9 times, avg 175µs/call: # 9 times (105µs+1.47ms) by Moose::Meta::Attribute::_process_options at line 296, avg 175µs/call sub _process_isa_option {
345 | 30 | 74µs |  |  | my ( $class, $name, $options ) = @_;
346 |  |  |  |  |
347 |  |  |  |  | return unless exists $options->{isa};
348 |  |  |  |  |
349 |  |  |  |  | if ( exists $options->{does} ) {
350 |  |  |  |  | if ( try { $options->{isa}->can('does') } ) {
351 |  |  |  |  | ( $options->{isa}->does( $options->{does} ) )
352 |  |  |  |  | || $class->throw_error(
353 |  |  |  |  | "Cannot have an isa option and a does option if the isa does not do the does on attribute ($name)",
354 |  |  |  |  | data => $options );
355 |  |  |  |  | }
356 |  |  |  |  | else {
357 |  |  |  |  | $class->throw_error(
358 |  |  |  |  | "Cannot have an isa option which cannot ->does() on attribute ($name)",
359 |  |  |  |  | data => $options );
360 |  |  |  |  | }
361 |  |  |  |  | }
362 |  |  |  |  |
363 |  |  |  |  | # allow for anon-subtypes here ...
364 | 6 | 44µs | 6 | 6µs | if ( blessed( $options->{isa} ) # spent 6µs making 6 calls to Scalar::Util::blessed, avg 1µs/call
365 |  |  |  |  | && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) {
366 |  |  |  |  | $options->{type_constraint} = $options->{isa};
367 |  |  |  |  | }
368 |  |  |  |  | else {
369 |  |  | 6 | 1.46ms | $options->{type_constraint} # spent 1.46ms making 6 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 244µs/call
370 |  |  |  |  | = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint(
371 |  |  |  |  | $options->{isa},
372 |  |  |  |  | { package_defined_in => $options->{definition_context}->{package} }
373 |  |  |  |  | );
374 |  |  |  |  | }
375 |  |  |  |  | }
376 |  |  |  |  |
377 |  |  |  |  | # spent 30µs within Moose::Meta::Attribute::_process_does_option which was called 9 times, avg 3µs/call: # 9 times (30µs+0s) by Moose::Meta::Attribute::_process_options at line 297, avg 3µs/call sub _process_does_option {
378 | 18 | 40µs |  |  | my ( $class, $name, $options ) = @_;
379 |  |  |  |  |
380 |  |  |  |  | return unless exists $options->{does} && ! exists $options->{isa};
381 |  |  |  |  |
382 |  |  |  |  | # allow for anon-subtypes here ...
383 |  |  |  |  | if ( blessed( $options->{does} )
384 |  |  |  |  | && $options->{does}->isa('Moose::Meta::TypeConstraint') ) {
385 |  |  |  |  | $options->{type_constraint} = $options->{does};
386 |  |  |  |  | }
387 |  |  |  |  | else {
388 |  |  |  |  | $options->{type_constraint}
389 |  |  |  |  | = Moose::Util::TypeConstraints::find_or_create_does_type_constraint(
390 |  |  |  |  | $options->{does},
391 |  |  |  |  | { package_defined_in => $options->{definition_context}->{package} }
392 |  |  |  |  | );
393 |  |  |  |  | }
394 |  |  |  |  | }
395 |  |  |  |  |
396 |  |  |  |  | # spent 28µs within Moose::Meta::Attribute::_process_coerce_option which was called 9 times, avg 3µs/call: # 9 times (28µs+0s) by Moose::Meta::Attribute::_process_options at line 298, avg 3µs/call sub _process_coerce_option {
397 | 18 | 36µs |  |  | my ( $class, $name, $options ) = @_;
398 |  |  |  |  |
399 |  |  |  |  | return unless $options->{coerce};
400 |  |  |  |  |
401 |  |  |  |  | ( exists $options->{type_constraint} )
402 |  |  |  |  | || $class->throw_error(
403 |  |  |  |  | "You cannot have coercion without specifying a type constraint on attribute ($name)",
404 |  |  |  |  | data => $options );
405 |  |  |  |  |
406 |  |  |  |  | $class->throw_error(
407 |  |  |  |  | "You cannot have a weak reference to a coerced value on attribute ($name)",
408 |  |  |  |  | data => $options )
409 |  |  |  |  | if $options->{weak_ref};
410 |  |  |  |  |
411 |  |  |  |  | unless ( $options->{type_constraint}->has_coercion ) {
412 |  |  |  |  | my $type = $options->{type_constraint}->name;
413 |  |  |  |  |
414 |  |  |  |  | Moose::Deprecated::deprecated(
415 |  |  |  |  | feature => 'coerce without coercion',
416 |  |  |  |  | message =>
417 |  |  |  |  | "You cannot coerce an attribute ($name) unless its type ($type) has a coercion"
418 |  |  |  |  | );
419 |  |  |  |  | }
420 |  |  |  |  | }
421 |  |  |  |  |
422 |  |  |  |  | # spent 27µs within Moose::Meta::Attribute::_process_trigger_option which was called 9 times, avg 3µs/call: # 9 times (27µs+0s) by Moose::Meta::Attribute::_process_options at line 299, avg 3µs/call sub _process_trigger_option {
423 | 18 | 38µs |  |  | my ( $class, $name, $options ) = @_;
424 |  |  |  |  |
425 |  |  |  |  | return unless exists $options->{trigger};
426 |  |  |  |  |
427 |  |  |  |  | ( 'CODE' eq ref $options->{trigger} )
428 |  |  |  |  | || $class->throw_error("Trigger must be a CODE ref on attribute ($name)", data => $options->{trigger});
429 |  |  |  |  | }
430 |  |  |  |  |
431 |  |  |  |  | # spent 29µs within Moose::Meta::Attribute::_process_auto_deref_option which was called 9 times, avg 3µs/call: # 9 times (29µs+0s) by Moose::Meta::Attribute::_process_options at line 300, avg 3µs/call sub _process_auto_deref_option {
432 | 18 | 40µs |  |  | my ( $class, $name, $options ) = @_;
433 |  |  |  |  |
434 |  |  |  |  | return unless $options->{auto_deref};
435 |  |  |  |  |
436 |  |  |  |  | ( exists $options->{type_constraint} )
437 |  |  |  |  | || $class->throw_error(
438 |  |  |  |  | "You cannot auto-dereference without specifying a type constraint on attribute ($name)",
439 |  |  |  |  | data => $options );
440 |  |  |  |  |
441 |  |  |  |  | ( $options->{type_constraint}->is_a_type_of('ArrayRef')
442 |  |  |  |  | || $options->{type_constraint}->is_a_type_of('HashRef') )
443 |  |  |  |  | || $class->throw_error(
444 |  |  |  |  | "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)",
445 |  |  |  |  | data => $options );
446 |  |  |  |  | }
447 |  |  |  |  |
448 |  |  |  |  | # spent 25µs within Moose::Meta::Attribute::_process_lazy_build_option which was called 9 times, avg 3µs/call: # 9 times (25µs+0s) by Moose::Meta::Attribute::_process_options at line 301, avg 3µs/call sub _process_lazy_build_option {
449 | 18 | 33µs |  |  | my ( $class, $name, $options ) = @_;
450 |  |  |  |  |
451 |  |  |  |  | return unless $options->{lazy_build};
452 |  |  |  |  |
453 |  |  |  |  | $class->throw_error(
454 |  |  |  |  | "You can not use lazy_build and default for the same attribute ($name)",
455 |  |  |  |  | data => $options )
456 |  |  |  |  | if exists $options->{default};
457 |  |  |  |  |
458 |  |  |  |  | $options->{lazy} = 1;
459 |  |  |  |  | $options->{builder} ||= "_build_${name}";
460 |  |  |  |  |
461 |  |  |  |  | if ( $name =~ /^_/ ) {
462 |  |  |  |  | $options->{clearer} ||= "_clear${name}";
463 |  |  |  |  | $options->{predicate} ||= "_has${name}";
464 |  |  |  |  | }
465 |  |  |  |  | else {
466 |  |  |  |  | $options->{clearer} ||= "clear_${name}";
467 |  |  |  |  | $options->{predicate} ||= "has_${name}";
468 |  |  |  |  | }
469 |  |  |  |  | }
470 |  |  |  |  |
471 |  |  |  |  | # spent 24µs within Moose::Meta::Attribute::_process_lazy_option which was called 9 times, avg 3µs/call: # 9 times (24µs+0s) by Moose::Meta::Attribute::_process_options at line 302, avg 3µs/call sub _process_lazy_option {
472 | 19 | 33µs |  |  | my ( $class, $name, $options ) = @_;
473 |  |  |  |  |
474 |  |  |  |  | return unless $options->{lazy};
475 |  |  |  |  |
476 |  |  |  |  | ( exists $options->{default} || defined $options->{builder} )
477 |  |  |  |  | || $class->throw_error(
478 |  |  |  |  | "You cannot have a lazy attribute ($name) without specifying a default value for it",
479 |  |  |  |  | data => $options );
480 |  |  |  |  | }
481 |  |  |  |  |
482 |  |  |  |  | # spent 26µs within Moose::Meta::Attribute::_process_required_option which was called 9 times, avg 3µs/call: # 9 times (26µs+0s) by Moose::Meta::Attribute::_process_options at line 303, avg 3µs/call sub _process_required_option {
483 | 18 | 39µs |  |  | my ( $class, $name, $options ) = @_;
484 |  |  |  |  |
485 |  |  |  |  | if (
486 |  |  |  |  | $options->{required}
487 |  |  |  |  | && !(
488 |  |  |  |  | ( !exists $options->{init_arg} || defined $options->{init_arg} )
489 |  |  |  |  | || exists $options->{default}
490 |  |  |  |  | || defined $options->{builder}
491 |  |  |  |  | )
492 |  |  |  |  | ) {
493 |  |  |  |  | $class->throw_error(
494 |  |  |  |  | "You cannot have a required attribute ($name) without a default, builder, or an init_arg",
495 |  |  |  |  | data => $options );
496 |  |  |  |  | }
497 |  |  |  |  | }
498 |  |  |  |  |
499 |  |  |  |  | # spent 3.44ms (190µs+3.25) within Moose::Meta::Attribute::initialize_instance_slot which was called 8 times, avg 430µs/call: # 8 times (190µs+3.25ms) by Class::MOP::Class::_construct_instance at line 525 of Class/MOP/Class.pm, avg 430µs/call sub initialize_instance_slot {
500 | 59 | 98µs |  |  | my ($self, $meta_instance, $instance, $params) = @_;
501 |  |  | 8 | 8µs | my $init_arg = $self->init_arg(); # spent 8µs making 8 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 975ns/call
502 |  |  |  |  | # try to fetch the init arg from the %params ...
503 |  |  |  |  |
504 |  |  |  |  | my $val;
505 |  |  |  |  | my $value_is_set;
506 | 21 | 43µs |  |  | if ( defined($init_arg) and exists $params->{$init_arg}) {
507 |  |  |  |  | $val = $params->{$init_arg};
508 |  |  |  |  | $value_is_set = 1;
509 |  |  |  |  | }
510 |  |  |  |  | else {
511 |  |  |  |  | # skip it if it's lazy
512 |  |  | 7 | 13µs | return if $self->is_lazy; # spent 13µs making 7 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 2µs/call
513 |  |  |  |  | # and die if it's required and doesn't have a default value
514 |  |  | 6 | 11µs | $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params) # spent 11µs making 6 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 2µs/call
515 |  |  |  |  | if $self->is_required && !$self->has_default && !$self->has_builder;
516 |  |  |  |  |
517 |  |  |  |  | # if nothing was in the %params, we can use the
518 |  |  |  |  | # attribute's default value (if it has one)
519 | 6 | 13µs | 9 | 14µs | if ($self->has_default) { # spent 9µs making 6 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call # spent 5µs making 3 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 2µs/call
520 |  |  | 3 | 2.87ms | $val = $self->default($instance); # spent 2.87ms making 3 calls to Class::MOP::Mixin::AttributeCore::default, avg 955µs/call
521 | 1 | 10µs | 1 | 3µs | $value_is_set = 1; # spent 3µs making 1 call to DBIx::Class::Storage::DBI::Cursor::DESTROY
522 |  |  |  |  | }
523 |  |  |  |  | elsif ($self->has_builder) {
524 |  |  |  |  | $val = $self->_call_builder($instance);
525 |  |  |  |  | $value_is_set = 1;
526 |  |  |  |  | }
527 |  |  |  |  | }
528 |  |  |  |  |
529 |  |  |  |  | return unless $value_is_set;
530 |  |  |  |  |
531 |  |  | 4 | 189µs | $val = $self->_coerce_and_verify( $val, $instance ); # spent 189µs making 4 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 47µs/call
532 |  |  |  |  |
533 |  |  | 4 | 138µs | $self->set_initial_value($instance, $val); # spent 138µs making 4 calls to Class::MOP::Attribute::set_initial_value, avg 35µs/call
534 |  |  |  |  |
535 |  |  | 4 | 7µs | if ( ref $val && $self->is_weak_ref ) { # spent 7µs making 4 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 2µs/call
536 |  |  |  |  | $self->_weaken_value($instance);
537 |  |  |  |  | }
538 |  |  |  |  | }
539 |  |  |  |  |
540 |  |  |  |  | sub _call_builder {
541 |  |  |  |  | my ( $self, $instance ) = @_;
542 |  |  |  |  |
543 |  |  |  |  | my $builder = $self->builder();
544 |  |  |  |  |
545 |  |  |  |  | return $instance->$builder()
546 |  |  |  |  | if $instance->can( $self->builder );
547 |  |  |  |  |
548 |  |  |  |  | $self->throw_error( blessed($instance)
549 |  |  |  |  | . " does not support builder method '"
550 |  |  |  |  | . $self->builder
551 |  |  |  |  | . "' for attribute '"
552 |  |  |  |  | . $self->name
553 |  |  |  |  | . "'",
554 |  |  |  |  | object => $instance,
555 |  |  |  |  | );
556 |  |  |  |  | }
557 |  |  |  |  |
558 |  |  |  |  | ## Slot management
559 |  |  |  |  |
560 |  |  |  |  | sub _make_initializer_writer_callback {
561 |  |  |  |  | my $self = shift;
562 |  |  |  |  | my ($meta_instance, $instance, $slot_name) = @_;
563 |  |  |  |  | my $old_callback = $self->SUPER::_make_initializer_writer_callback(@_);
564 |  |  |  |  | return sub {
565 |  |  |  |  | $old_callback->($self->_coerce_and_verify($_[0], $instance));
566 |  |  |  |  | };
567 |  |  |  |  | }
568 |  |  |  |  |
569 |  |  |  |  | sub set_value {
570 |  |  |  |  | my ($self, $instance, @args) = @_;
571 |  |  |  |  | my $value = $args[0];
572 |  |  |  |  |
573 |  |  |  |  | my $attr_name = quotemeta($self->name);
574 |  |  |  |  |
575 |  |  |  |  | if ($self->is_required and not @args) {
576 |  |  |  |  | $self->throw_error("Attribute ($attr_name) is required", object => $instance);
577 |  |  |  |  | }
578 |  |  |  |  |
579 |  |  |  |  | $value = $self->_coerce_and_verify( $value, $instance );
580 |  |  |  |  |
581 |  |  |  |  | my @old;
582 |  |  |  |  | if ( $self->has_trigger && $self->has_value($instance) ) {
583 |  |  |  |  | @old = $self->get_value($instance, 'for trigger');
584 |  |  |  |  | }
585 |  |  |  |  |
586 |  |  |  |  | $self->SUPER::set_value($instance, $value);
587 |  |  |  |  |
588 |  |  |  |  | if ( ref $value && $self->is_weak_ref ) {
589 |  |  |  |  | $self->_weaken_value($instance);
590 |  |  |  |  | }
591 |  |  |  |  |
592 |  |  |  |  | if ($self->has_trigger) {
593 |  |  |  |  | $self->trigger->($instance, $value, @old);
594 |  |  |  |  | }
595 |  |  |  |  | }
596 |  |  |  |  |
597 |  |  |  |  | # spent 3.78ms (285µs+3.49) within Moose::Meta::Attribute::_inline_set_value which was called 8 times, avg 472µs/call: # 6 times (213µs+2.87ms) by Class::MOP::Method::Accessor::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Accessor.pm:120] at line 112 of Class/MOP/Method/Accessor.pm, avg 514µs/call # 2 times (73µs+619µs) by Class::MOP::Class::_inline_init_attr_from_constructor at line 630 of Class/MOP/Class.pm, avg 346µs/call sub _inline_set_value {
598 | 120 | 249µs |  |  | my $self = shift;
599 |  |  |  |  | my ($instance, $value, $tc, $coercion, $message, $for_constructor) = @_;
600 |  |  |  |  |
601 |  |  |  |  | my $old = '@old';
602 |  |  |  |  | my $copy = '$val';
603 |  |  |  |  | $tc ||= '$type_constraint';
604 |  |  |  |  | $coercion ||= '$type_coercion';
605 |  |  |  |  | $message ||= '$type_message';
606 |  |  |  |  |
607 |  |  |  |  | my @code;
608 |  |  | 8 | 160µs | if ($self->_writer_value_needs_copy) { # spent 160µs making 8 calls to Moose::Meta::Attribute::_writer_value_needs_copy, avg 20µs/call
609 |  |  |  |  | push @code, $self->_inline_copy_value($value, $copy);
610 |  |  |  |  | $value = $copy;
611 |  |  |  |  | }
612 |  |  |  |  |
613 |  |  |  |  | # constructors already handle required checks
614 |  |  | 8 | 133µs | push @code, $self->_inline_check_required # spent 133µs making 8 calls to Moose::Meta::Attribute::_inline_check_required, avg 17µs/call
615 |  |  |  |  | unless $for_constructor;
616 |  |  |  |  |
617 |  |  | 8 | 1.69ms | push @code, $self->_inline_tc_code($value, $tc, $coercion, $message); # spent 1.69ms making 8 calls to Moose::Meta::Attribute::_inline_tc_code, avg 211µs/call
618 |  |  |  |  |
619 |  |  |  |  | # constructors do triggers all at once at the end
620 |  |  | 8 | 121µs | push @code, $self->_inline_get_old_value_for_trigger($instance, $old) # spent 121µs making 8 calls to Moose::Meta::Attribute::_inline_get_old_value_for_trigger, avg 15µs/call
621 |  |  |  |  | unless $for_constructor;
622 |  |  |  |  |
623 |  |  | 16 | 1.29ms | push @code, ( # spent 1.11ms making 8 calls to Class::MOP::Attribute::_inline_set_value, avg 139µs/call # spent 185µs making 8 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 23µs/call
624 |  |  |  |  | $self->SUPER::_inline_set_value($instance, $value),
625 |  |  |  |  | $self->_inline_weaken_value($instance, $value),
626 |  |  |  |  | );
627 |  |  |  |  |
628 |  |  |  |  | # constructors do triggers all at once at the end
629 |  |  | 8 | 96µs | push @code, $self->_inline_trigger($instance, $value, $old) # spent 96µs making 8 calls to Moose::Meta::Attribute::_inline_trigger, avg 12µs/call
630 |  |  |  |  | unless $for_constructor;
631 |  |  |  |  |
632 |  |  |  |  | return @code;
633 |  |  |  |  | }
634 |  |  |  |  |
635 |  |  |  |  | # spent 160µs (61+99) within Moose::Meta::Attribute::_writer_value_needs_copy which was called 8 times, avg 20µs/call: # 8 times (61µs+99µs) by Moose::Meta::Attribute::_inline_set_value at line 608, avg 20µs/call sub _writer_value_needs_copy {
636 | 16 | 61µs |  |  | my $self = shift;
637 |  |  | 8 | 99µs | return $self->should_coerce; # spent 99µs making 8 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 12µs/call
638 |  |  |  |  | }
639 |  |  |  |  |
640 |  |  |  |  | sub _inline_copy_value {
641 |  |  |  |  | my $self = shift;
642 |  |  |  |  | my ($value, $copy) = @_;
643 |  |  |  |  |
644 |  |  |  |  | return 'my ' . $copy . ' = ' . $value . ';'
645 |  |  |  |  | }
646 |  |  |  |  |
647 |  |  |  |  | # spent 133µs (58+75) within Moose::Meta::Attribute::_inline_check_required which was called 8 times, avg 17µs/call: # 8 times (58µs+75µs) by Moose::Meta::Attribute::_inline_set_value at line 614, avg 17µs/call sub _inline_check_required {
648 | 16 | 51µs |  |  | my $self = shift;
649 |  |  |  |  |
650 |  |  | 8 | 75µs | return unless $self->is_required; # spent 75µs making 8 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 9µs/call
651 |  |  |  |  |
652 |  |  |  |  | my $attr_name = quotemeta($self->name);
653 |  |  |  |  |
654 |  |  |  |  | return (
655 |  |  |  |  | 'if (@_ < 2) {',
656 |  |  |  |  | $self->_inline_throw_error(
657 |  |  |  |  | '"Attribute (' . $attr_name . ') is required, so cannot '
658 |  |  |  |  | . 'be set to undef"' # defined $_[1] is not good enough
659 |  |  |  |  | ) . ';',
660 |  |  |  |  | '}',
661 |  |  |  |  | );
662 |  |  |  |  | }
663 |  |  |  |  |
664 |  |  |  |  | # spent 1.69ms (74µs+1.61) within Moose::Meta::Attribute::_inline_tc_code which was called 8 times, avg 211µs/call: # 8 times (74µs+1.61ms) by Moose::Meta::Attribute::_inline_set_value at line 617, avg 211µs/call sub _inline_tc_code {
665 | 24 | 66µs |  |  | my $self = shift;
666 |  |  |  |  | my ($value, $tc, $coercion, $message, $is_lazy) = @_;
667 |  |  |  |  | return (
668 |  |  | 16 | 1.61ms | $self->_inline_check_coercion( # spent 1.51ms making 8 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 189µs/call # spent 103µs making 8 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 13µs/call
669 |  |  |  |  | $value, $tc, $coercion, $is_lazy,
670 |  |  |  |  | ),
671 |  |  |  |  | $self->_inline_check_constraint(
672 |  |  |  |  | $value, $tc, $message, $is_lazy,
673 |  |  |  |  | ),
674 |  |  |  |  | );
675 |  |  |  |  | }
676 |  |  |  |  |
677 |  |  |  |  | # spent 109µs (48+61) within Moose::Meta::Attribute::_inline_check_coercion which was called 9 times, avg 12µs/call: # 8 times (44µs+60µs) by Moose::Meta::Attribute::_inline_tc_code at line 668, avg 13µs/call # once (5µs+1µs) by Moose::Meta::Attribute::_inline_init_from_default at line 910 sub _inline_check_coercion {
678 | 27 | 43µs |  |  | my $self = shift;
679 |  |  |  |  | my ($value, $tc, $coercion) = @_;
680 |  |  |  |  |
681 |  |  | 9 | 61µs | return unless $self->should_coerce && $self->type_constraint->has_coercion; # spent 61µs making 9 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 7µs/call
682 |  |  |  |  |
683 |  |  |  |  | if ( $self->type_constraint->can_be_inlined ) {
684 |  |  |  |  | return (
685 |  |  |  |  | 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {',
686 |  |  |  |  | $value . ' = ' . $coercion . '->(' . $value . ');',
687 |  |  |  |  | '}',
688 |  |  |  |  | );
689 |  |  |  |  | }
690 |  |  |  |  | else {
691 |  |  |  |  | return (
692 |  |  |  |  | 'if (!' . $tc . '->(' . $value . ')) {',
693 |  |  |  |  | $value . ' = ' . $coercion . '->(' . $value . ');',
694 |  |  |  |  | '}',
695 |  |  |  |  | );
696 |  |  |  |  | }
697 |  |  |  |  | }
698 |  |  |  |  |
699 |  |  |  |  | # spent 1.70ms (199µs+1.50) within Moose::Meta::Attribute::_inline_check_constraint which was called 9 times, avg 188µs/call: # 8 times (181µs+1.33ms) by Moose::Meta::Attribute::_inline_tc_code at line 668, avg 189µs/call # once (18µs+166µs) by Moose::Meta::Attribute::_inline_init_from_default at line 910 sub _inline_check_constraint {
700 | 39 | 182µs |  |  | my $self = shift;
701 |  |  |  |  | my ($value, $tc, $message) = @_;
702 |  |  |  |  |
703 |  |  | 9 | 76µs | return unless $self->has_type_constraint; # spent 76µs making 9 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 8µs/call
704 |  |  |  |  |
705 |  |  | 6 | 4µs | my $attr_name = quotemeta($self->name); # spent 4µs making 6 calls to Class::MOP::Mixin::AttributeCore::name, avg 633ns/call
706 |  |  |  |  |
707 |  |  | 30 | 1.42ms | if ( $self->type_constraint->can_be_inlined ) { # spent 1.01ms making 6 calls to Moose::Meta::Attribute::_inline_throw_error, avg 169µs/call # spent 257µs making 6 calls to Moose::Meta::TypeConstraint::_inline_check, avg 43µs/call # spent 125µs making 6 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 21µs/call # spent 22µs making 12 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 2µs/call
708 |  |  |  |  | return (
709 |  |  |  |  | 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {',
710 |  |  |  |  | $self->_inline_throw_error(
711 |  |  |  |  | '"Attribute (' . $attr_name . ') does not pass the type '
712 |  |  |  |  | . 'constraint because: " . '
713 |  |  |  |  | . 'do { local $_ = ' . $value . '; '
714 |  |  |  |  | . $message . '->(' . $value . ')'
715 |  |  |  |  | . '}',
716 |  |  |  |  | 'data => ' . $value
717 |  |  |  |  | ) . ';',
718 |  |  |  |  | '}',
719 |  |  |  |  | );
720 |  |  |  |  | }
721 |  |  |  |  | else {
722 |  |  |  |  | return (
723 |  |  |  |  | 'if (!' . $tc . '->(' . $value . ')) {',
724 |  |  |  |  | $self->_inline_throw_error(
725 |  |  |  |  | '"Attribute (' . $attr_name . ') does not pass the type '
726 |  |  |  |  | . 'constraint because: " . '
727 |  |  |  |  | . 'do { local $_ = ' . $value . '; '
728 |  |  |  |  | . $message . '->(' . $value . ')'
729 |  |  |  |  | . '}',
730 |  |  |  |  | 'data => ' . $value
731 |  |  |  |  | ) . ';',
732 |  |  |  |  | '}',
733 |  |  |  |  | );
734 |  |  |  |  | }
735 |  |  |  |  | }
736 |  |  |  |  |
737 |  |  |  |  | # spent 121µs (56+64) within Moose::Meta::Attribute::_inline_get_old_value_for_trigger which was called 8 times, avg 15µs/call: # 8 times (56µs+64µs) by Moose::Meta::Attribute::_inline_set_value at line 620, avg 15µs/call sub _inline_get_old_value_for_trigger {
738 | 24 | 52µs |  |  | my $self = shift;
739 |  |  |  |  | my ($instance, $old) = @_;
740 |  |  |  |  |
741 |  |  | 8 | 64µs | return unless $self->has_trigger; # spent 64µs making 8 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 8µs/call
742 |  |  |  |  |
743 |  |  |  |  | return (
744 |  |  |  |  | 'my ' . $old . ' = ' . $self->_inline_instance_has($instance),
745 |  |  |  |  | '? ' . $self->_inline_instance_get($instance),
746 |  |  |  |  | ': ();',
747 |  |  |  |  | );
748 |  |  |  |  | }
749 |  |  |  |  |
750 |  |  |  |  | # spent 190µs (89+102) within Moose::Meta::Attribute::_inline_weaken_value which was called 9 times, avg 21µs/call: # 8 times (85µs+100µs) by Moose::Meta::Attribute::_inline_set_value at line 623, avg 23µs/call # once (3µs+1µs) by Moose::Meta::Attribute::_inline_init_from_default at line 910 sub _inline_weaken_value {
751 | 31 | 84µs |  |  | my $self = shift;
752 |  |  |  |  | my ($instance, $value) = @_;
753 |  |  |  |  |
754 |  |  | 9 | 76µs | return unless $self->is_weak_ref; # spent 76µs making 9 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 8µs/call
755 |  |  |  |  |
756 |  |  | 4 | 9µs | my $mi = $self->associated_class->get_meta_instance; # spent 7µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance # spent 1µs making 2 calls to Class::MOP::Attribute::associated_class, avg 600ns/call # spent 1µs making 1 call to Class::MOP::Class::get_meta_instance
757 |  |  |  |  | return (
758 |  |  | 4 | 17µs | $mi->inline_weaken_slot_value($instance, $self->name), # spent 16µs making 2 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 8µs/call # spent 1µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 550ns/call
759 |  |  |  |  | 'if ref ' . $value . ';',
760 |  |  |  |  | );
761 |  |  |  |  | }
762 |  |  |  |  |
763 |  |  |  |  | # spent 96µs (41+55) within Moose::Meta::Attribute::_inline_trigger which was called 8 times, avg 12µs/call: # 8 times (41µs+55µs) by Moose::Meta::Attribute::_inline_set_value at line 629, avg 12µs/call sub _inline_trigger {
764 | 24 | 37µs |  |  | my $self = shift;
765 |  |  |  |  | my ($instance, $value, $old) = @_;
766 |  |  |  |  |
767 |  |  | 8 | 55µs | return unless $self->has_trigger; # spent 55µs making 8 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 7µs/call
768 |  |  |  |  |
769 |  |  |  |  | return '$trigger->(' . $instance . ', ' . $value . ', ' . $old . ');';
770 |  |  |  |  | }
771 |  |  |  |  |
772 |  |  |  |  | # spent 696µs (337+359) within Moose::Meta::Attribute::_eval_environment which was called 9 times, avg 77µs/call: # 9 times (337µs+359µs) by Moose::Meta::Method::Accessor::_eval_environment at line 52 of Moose/Meta/Method/Accessor.pm, avg 77µs/call sub _eval_environment {
773 | 72 | 177µs |  |  | my $self = shift;
774 |  |  |  |  |
775 |  |  |  |  | my $env = { };
776 |  |  |  |  |
777 |  |  | 9 | 74µs | $env->{'$trigger'} = \($self->trigger) # spent 74µs making 9 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 8µs/call
778 |  |  |  |  | if $self->has_trigger;
779 |  |  | 14 | 31µs | $env->{'$attr_default'} = \($self->default) # spent 16µs making 9 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 2µs/call # spent 15µs making 5 calls to Class::MOP::Mixin::AttributeCore::default, avg 3µs/call
780 |  |  |  |  | if $self->has_default;
781 |  |  |  |  |
782 | 25 | 90µs | 9 | 57µs | if ($self->has_type_constraint) { # spent 57µs making 9 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 6µs/call
783 |  |  | 5 | 7µs | my $tc_obj = $self->type_constraint; # spent 7µs making 5 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 1µs/call
784 |  |  |  |  |
785 |  |  | 5 | 62µs | $env->{'$type_constraint'} = \( # spent 62µs making 5 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 12µs/call
786 |  |  |  |  | $tc_obj->_compiled_type_constraint
787 |  |  |  |  | ) unless $tc_obj->can_be_inlined;
788 |  |  |  |  | # these two could probably get inlined versions too
789 |  |  | 5 | 12µs | $env->{'$type_coercion'} = \( # spent 12µs making 5 calls to Moose::Meta::TypeConstraint::has_coercion, avg 2µs/call
790 |  |  |  |  | $tc_obj->coercion->_compiled_type_coercion
791 |  |  |  |  | ) if $tc_obj->has_coercion;
792 |  |  | 10 | 23µs | $env->{'$type_message'} = \( # spent 13µs making 5 calls to Moose::Meta::TypeConstraint::_default_message, avg 3µs/call # spent 11µs making 5 calls to Moose::Meta::TypeConstraint::has_message, avg 2µs/call
793 |  |  |  |  | $tc_obj->has_message ? $tc_obj->message : $tc_obj->_default_message
794 |  |  |  |  | );
795 |  |  |  |  |
796 |  |  | 5 | 75µs | $env = { %$env, %{ $tc_obj->inline_environment } }; # spent 75µs making 5 calls to Moose::Meta::TypeConstraint::inline_environment, avg 15µs/call
797 |  |  |  |  | }
798 |  |  |  |  |
799 |  |  |  |  | # XXX ugh, fix these
800 |  |  | 9 | 14µs | $env->{'$attr'} = \$self # spent 14µs making 9 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 2µs/call
801 |  |  |  |  | if $self->has_initializer && $self->is_lazy;
802 |  |  |  |  | # pretty sure this is only going to be closed over if you use a custom
803 |  |  |  |  | # error class at this point, but we should still get rid of this
804 |  |  |  |  | # at some point
805 |  |  | 9 | 6µs | $env->{'$meta'} = \($self->associated_class); # spent 6µs making 9 calls to Class::MOP::Attribute::associated_class, avg 689ns/call
806 |  |  |  |  |
807 |  |  |  |  | return $env;
808 |  |  |  |  | }
809 |  |  |  |  |
810 |  |  |  |  | sub _weaken_value {
811 |  |  |  |  | my ( $self, $instance ) = @_;
812 |  |  |  |  |
813 |  |  |  |  | my $meta_instance = Class::MOP::Class->initialize( blessed($instance) )
814 |  |  |  |  | ->get_meta_instance;
815 |  |  |  |  |
816 |  |  |  |  | $meta_instance->weaken_slot_value( $instance, $self->name );
817 |  |  |  |  | }
818 |  |  |  |  |
819 |  |  |  |  | sub get_value {
820 |  |  |  |  | my ($self, $instance, $for_trigger) = @_;
821 |  |  |  |  |
822 |  |  |  |  | if ($self->is_lazy) {
823 |  |  |  |  | unless ($self->has_value($instance)) {
824 |  |  |  |  | my $value;
825 |  |  |  |  | if ($self->has_default) {
826 |  |  |  |  | $value = $self->default($instance);
827 |  |  |  |  | } elsif ( $self->has_builder ) {
828 |  |  |  |  | $value = $self->_call_builder($instance);
829 |  |  |  |  | }
830 |  |  |  |  |
831 |  |  |  |  | $value = $self->_coerce_and_verify( $value, $instance );
832 |  |  |  |  |
833 |  |  |  |  | $self->set_initial_value($instance, $value);
834 |  |  |  |  |
835 |  |  |  |  | if ( ref $value && $self->is_weak_ref ) {
836 |  |  |  |  | $self->_weaken_value($instance);
837 |  |  |  |  | }
838 |  |  |  |  | }
839 |  |  |  |  | }
840 |  |  |  |  |
841 |  |  |  |  | if ( $self->should_auto_deref && ! $for_trigger ) {
842 |  |  |  |  |
843 |  |  |  |  | my $type_constraint = $self->type_constraint;
844 |  |  |  |  |
845 |  |  |  |  | if ($type_constraint->is_a_type_of('ArrayRef')) {
846 |  |  |  |  | my $rv = $self->SUPER::get_value($instance);
847 |  |  |  |  | return unless defined $rv;
848 |  |  |  |  | return wantarray ? @{ $rv } : $rv;
849 |  |  |  |  | }
850 |  |  |  |  | elsif ($type_constraint->is_a_type_of('HashRef')) {
851 |  |  |  |  | my $rv = $self->SUPER::get_value($instance);
852 |  |  |  |  | return unless defined $rv;
853 |  |  |  |  | return wantarray ? %{ $rv } : $rv;
854 |  |  |  |  | }
855 |  |  |  |  | else {
856 |  |  |  |  | $self->throw_error("Can not auto de-reference the type constraint '" . $type_constraint->name . "'", object => $instance, type_constraint => $type_constraint);
857 |  |  |  |  | }
858 |  |  |  |  |
859 |  |  |  |  | }
860 |  |  |  |  | else {
861 |  |  |  |  |
862 |  |  |  |  | return $self->SUPER::get_value($instance);
863 |  |  |  |  | }
864 |  |  |  |  | }
865 |  |  |  |  |
866 |  |  |  |  | # spent 1.25ms (130µs+1.12) within Moose::Meta::Attribute::_inline_get_value which was called 9 times, avg 139µs/call: # 6 times (82µs+586µs) by Class::MOP::Method::Accessor::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Accessor.pm:120] at line 112 of Class/MOP/Method/Accessor.pm, avg 111µs/call # 3 times (48µs+535µs) by Class::MOP::Method::Accessor::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Accessor.pm:154] at line 142 of Class/MOP/Method/Accessor.pm, avg 194µs/call sub _inline_get_value {
867 | 63 | 122µs |  |  | my $self = shift;
868 |  |  |  |  | my ($instance, $tc, $coercion, $message) = @_;
869 |  |  |  |  |
870 |  |  | 9 | 442µs | my $slot_access = $self->_inline_instance_get($instance); # spent 442µs making 9 calls to Class::MOP::Attribute::_inline_instance_get, avg 49µs/call
871 |  |  |  |  | $tc ||= '$type_constraint';
872 |  |  |  |  | $coercion ||= '$type_coercion';
873 |  |  |  |  | $message ||= '$type_message';
874 |  |  |  |  |
875 |  |  |  |  | return (
876 |  |  | 18 | 679µs | $self->_inline_check_lazy($instance, $tc, $coercion, $message), # spent 499µs making 9 calls to Moose::Meta::Attribute::_inline_check_lazy, avg 55µs/call # spent 180µs making 9 calls to Moose::Meta::Attribute::_inline_return_auto_deref, avg 20µs/call
877 |  |  |  |  | $self->_inline_return_auto_deref($slot_access),
878 |  |  |  |  | );
879 |  |  |  |  | }
880 |  |  |  |  |
881 |  |  |  |  | # spent 499µs (80+419) within Moose::Meta::Attribute::_inline_check_lazy which was called 9 times, avg 55µs/call: # 9 times (80µs+419µs) by Moose::Meta::Attribute::_inline_get_value at line 876, avg 55µs/call sub _inline_check_lazy {
882 | 29 | 76µs |  |  | my $self = shift;
883 |  |  |  |  | my ($instance, $tc, $coercion, $message) = @_;
884 |  |  |  |  |
885 |  |  | 9 | 117µs | return unless $self->is_lazy; # spent 117µs making 9 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 13µs/call
886 |  |  |  |  |
887 |  |  | 1 | 23µs | my $slot_exists = $self->_inline_instance_has($instance); # spent 23µs making 1 call to Class::MOP::Attribute::_inline_instance_has
888 |  |  |  |  |
889 |  |  |  |  | return (
890 |  |  | 1 | 279µs | 'if (!' . $slot_exists . ') {', # spent 279µs making 1 call to Moose::Meta::Attribute::_inline_init_from_default
891 |  |  |  |  | $self->_inline_init_from_default($instance, '$default', $tc, $coercion, $message, 'lazy'),
892 |  |  |  |  | '}',
893 |  |  |  |  | );
894 |  |  |  |  | }
895 |  |  |  |  |
896 |  |  |  |  | # spent 279µs (31+248) within Moose::Meta::Attribute::_inline_init_from_default which was called: # once (31µs+248µs) by Moose::Meta::Attribute::_inline_check_lazy at line 890 sub _inline_init_from_default {
897 | 4 | 20µs |  |  | my $self = shift;
898 |  |  |  |  | my ($instance, $default, $tc, $coercion, $message, $for_lazy) = @_;
899 |  |  |  |  |
900 |  |  | 1 | 2µs | if (!($self->has_default || $self->has_builder)) { # spent 2µs making 1 call to Class::MOP::Mixin::AttributeCore::has_default
901 |  |  |  |  | $self->throw_error(
902 |  |  |  |  | 'You cannot have a lazy attribute '
903 |  |  |  |  | . '(' . $self->name . ') '
904 |  |  |  |  | . 'without specifying a default value for it',
905 |  |  |  |  | attr => $self,
906 |  |  |  |  | );
907 |  |  |  |  | }
908 |  |  |  |  |
909 |  |  |  |  | return (
910 |  |  | 6 | 246µs | $self->_inline_generate_default($instance, $default), # spent 184µs making 1 call to Moose::Meta::Attribute::_inline_check_constraint # spent 32µs making 1 call to Moose::Meta::Attribute::_inline_init_slot # spent 18µs making 1 call to Moose::Meta::Attribute::_inline_generate_default # spent 6µs making 1 call to Moose::Meta::Attribute::_inline_check_coercion # spent 5µs making 1 call to Moose::Meta::Attribute::_inline_weaken_value # spent 1µs making 1 call to Moose::Meta::Mixin::AttributeCore::has_type_constraint
911 |  |  |  |  | # intentionally not using _inline_tc_code, since that can be overridden
912 |  |  |  |  | # to do things like possibly only do member tc checks, which isn't
913 |  |  |  |  | # appropriate for checking the result of a default
914 |  |  |  |  | $self->has_type_constraint
915 |  |  |  |  | ? ($self->_inline_check_coercion($default, $tc, $coercion, $for_lazy),
916 |  |  |  |  | $self->_inline_check_constraint($default, $tc, $message, $for_lazy))
917 |  |  |  |  | : (),
918 |  |  |  |  | $self->_inline_init_slot($instance, $default),
919 |  |  |  |  | $self->_inline_weaken_value($instance, $default),
920 |  |  |  |  | );
921 |  |  |  |  | }
922 |  |  |  |  |
923 |  |  |  |  | # spent 18µs (12+6) within Moose::Meta::Attribute::_inline_generate_default which was called: # once (12µs+6µs) by Moose::Meta::Attribute::_inline_init_from_default at line 910 sub _inline_generate_default {
924 | 3 | 2µs |  |  | my $self = shift;
925 |  |  |  |  | my ($instance, $default) = @_;
926 |  |  |  |  |
927 | 3 | 9µs | 1 | 900ns | if ($self->has_default) { # spent 900ns making 1 call to Class::MOP::Mixin::AttributeCore::has_default
928 |  |  |  |  | my $source = 'my ' . $default . ' = $attr_default';
929 |  |  | 1 | 5µs | $source .= '->(' . $instance . ')' # spent 5µs making 1 call to Class::MOP::Mixin::AttributeCore::is_default_a_coderef
930 |  |  |  |  | if $self->is_default_a_coderef;
931 |  |  |  |  | return $source . ';';
932 |  |  |  |  | }
933 |  |  |  |  | elsif ($self->has_builder) {
934 |  |  |  |  | my $builder = B::perlstring($self->builder);
935 |  |  |  |  | my $builder_str = quotemeta($self->builder);
936 |  |  |  |  | my $attr_name_str = quotemeta($self->name);
937 |  |  |  |  | return (
938 |  |  |  |  | 'my ' . $default . ';',
939 |  |  |  |  | 'if (my $builder = ' . $instance . '->can(' . $builder . ')) {',
940 |  |  |  |  | $default . ' = ' . $instance . '->$builder;',
941 |  |  |  |  | '}',
942 |  |  |  |  | 'else {',
943 |  |  |  |  | 'my $class = ref(' . $instance . ') || ' . $instance . ';',
944 |  |  |  |  | $self->_inline_throw_error(
945 |  |  |  |  | '"$class does not support builder method '
946 |  |  |  |  | . '\'' . $builder_str . '\' for attribute '
947 |  |  |  |  | . '\'' . $attr_name_str . '\'"'
948 |  |  |  |  | ) . ';',
949 |  |  |  |  | '}',
950 |  |  |  |  | );
951 |  |  |  |  | }
952 |  |  |  |  | else {
953 |  |  |  |  | $self->throw_error(
954 |  |  |  |  | "Can't generate a default for " . $self->name
955 |  |  |  |  | . " since no default or builder was specified"
956 |  |  |  |  | );
957 |  |  |  |  | }
958 |  |  |  |  | }
959 |  |  |  |  |
960 |  |  |  |  | # spent 32µs (14+18) within Moose::Meta::Attribute::_inline_init_slot which was called: # once (14µs+18µs) by Moose::Meta::Attribute::_inline_init_from_default at line 910 sub _inline_init_slot {
961 | 3 | 6µs |  |  | my $self = shift;
962 |  |  |  |  | my ($inv, $value) = @_;
963 |  |  |  |  |
964 | 1 | 5µs | 1 | 2µs | if ($self->has_initializer) { # spent 2µs making 1 call to Class::MOP::Mixin::AttributeCore::has_initializer
965 |  |  |  |  | return '$attr->set_initial_value(' . $inv . ', ' . $value . ');';
966 |  |  |  |  | }
967 |  |  |  |  | else {
968 |  |  | 1 | 16µs | return $self->_inline_instance_set($inv, $value) . ';'; # spent 16µs making 1 call to Class::MOP::Attribute::_inline_instance_set
969 |  |  |  |  | }
970 |  |  |  |  | }
971 |  |  |  |  |
972 |  |  |  |  | # spent 180µs (51+129) within Moose::Meta::Attribute::_inline_return_auto_deref which was called 9 times, avg 20µs/call: # 9 times (51µs+129µs) by Moose::Meta::Attribute::_inline_get_value at line 876, avg 20µs/call sub _inline_return_auto_deref {
973 | 18 | 43µs |  |  | my $self = shift;
974 |  |  |  |  |
975 |  |  | 9 | 129µs | return 'return ' . $self->_auto_deref(@_) . ';'; # spent 129µs making 9 calls to Moose::Meta::Attribute::_auto_deref, avg 14µs/call
976 |  |  |  |  | }
977 |  |  |  |  |
978 |  |  |  |  | # spent 129µs (61+68) within Moose::Meta::Attribute::_auto_deref which was called 9 times, avg 14µs/call: # 9 times (61µs+68µs) by Moose::Meta::Attribute::_inline_return_auto_deref at line 975, avg 14µs/call sub _auto_deref {
979 | 27 | 64µs |  |  | my $self = shift;
980 |  |  |  |  | my ($ref_value) = @_;
981 |  |  |  |  |
982 |  |  | 9 | 68µs | return $ref_value unless $self->should_auto_deref; # spent 68µs making 9 calls to Moose::Meta::Mixin::AttributeCore::should_auto_deref, avg 8µs/call
983 |  |  |  |  |
984 |  |  |  |  | my $type_constraint = $self->type_constraint;
985 |  |  |  |  |
986 |  |  |  |  | my $sigil;
987 |  |  |  |  | if ($type_constraint->is_a_type_of('ArrayRef')) {
988 |  |  |  |  | $sigil = '@';
989 |  |  |  |  | }
990 |  |  |  |  | elsif ($type_constraint->is_a_type_of('HashRef')) {
991 |  |  |  |  | $sigil = '%';
992 |  |  |  |  | }
993 |  |  |  |  | else {
994 |  |  |  |  | $self->throw_error(
995 |  |  |  |  | 'Can not auto de-reference the type constraint \''
996 |  |  |  |  | . $type_constraint->name
997 |  |  |  |  | . '\'',
998 |  |  |  |  | type_constraint => $type_constraint,
999 |  |  |  |  | );
1000 |  |  |  |  | }
1001 |  |  |  |  |
1002 |  |  |  |  | return 'wantarray '
1003 |  |  |  |  | . '? ' . $sigil . '{ (' . $ref_value . ') || return } '
1004 |  |  |  |  | . ': (' . $ref_value . ')';
1005 |  |  |  |  | }
1006 |  |  |  |  |
1007 |  |  |  |  | ## installing accessors
1008 |  |  |  |  |
1009 | 9 | 29µs |  |  | # spent 14µs within Moose::Meta::Attribute::accessor_metaclass which was called 9 times, avg 2µs/call: # 9 times (14µs+0s) by Class::MOP::Attribute::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Attribute.pm:398] at line 389 of Class/MOP/Attribute.pm, avg 2µs/call sub accessor_metaclass { 'Moose::Meta::Method::Accessor' }
1010 |  |  |  |  |
1011 |  |  |  |  | # spent 18.0ms (151µs+17.8) within Moose::Meta::Attribute::install_accessors which was called 10 times, avg 1.80ms/call: # 9 times (136µs+16.2ms) by Class::MOP::Class::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Class.pm:892] at line 891 of Class/MOP/Class.pm, avg 1.81ms/call # once (15µs+1.61ms) by Class::MOP::Class::_inline_accessors at line 1413 of Class/MOP/Class.pm sub install_accessors {
1012 | 40 | 149µs |  |  | my $self = shift;
1013 |  |  | 10 | 17.7ms | $self->SUPER::install_accessors(@_); # spent 17.7ms making 10 calls to Class::MOP::Attribute::install_accessors, avg 1.77ms/call
1014 |  |  | 10 | 81µs | $self->install_delegation if $self->has_handles; # spent 81µs making 10 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 8µs/call
1015 |  |  |  |  | return;
1016 |  |  |  |  | }
1017 |  |  |  |  |
1018 |  |  |  |  | # spent 111µs (91+20) within Moose::Meta::Attribute::_check_associated_methods which was called 8 times, avg 14µs/call: # 8 times (91µs+20µs) by Moose::Meta::Class::add_attribute at line 573 of Moose/Meta/Class.pm, avg 14µs/call sub _check_associated_methods {
1019 | 16 | 108µs |  |  | my $self = shift;
1020 |  |  | 9 | 20µs | unless ( # spent 13µs making 8 calls to Class::MOP::Attribute::associated_methods, avg 2µs/call # spent 7µs making 1 call to Moose::Meta::Mixin::AttributeCore::_is_metadata
1021 |  |  |  |  | @{ $self->associated_methods }
1022 |  |  |  |  | || ($self->_is_metadata || '') eq 'bare'
1023 |  |  |  |  | ) {
1024 |  |  |  |  | Carp::cluck(
1025 |  |  |  |  | 'Attribute (' . $self->name . ') of class '
1026 |  |  |  |  | . $self->associated_class->name
1027 |  |  |  |  | . ' has no associated methods'
1028 |  |  |  |  | . ' (did you mean to provide an "is" argument?)'
1029 |  |  |  |  | . "\n"
1030 |  |  |  |  | )
1031 |  |  |  |  | }
1032 |  |  |  |  | }
1033 |  |  |  |  |
1034 |  |  |  |  | # spent 16.3ms (305µs+16.0) within Moose::Meta::Attribute::_process_accessors which was called 9 times, avg 1.81ms/call: # 6 times (187µs+10.8ms) by Class::MOP::Attribute::install_accessors at line 424 of Class/MOP/Attribute.pm, avg 1.83ms/call # 3 times (117µs+5.21ms) by Class::MOP::Attribute::install_accessors at line 428 of Class/MOP/Attribute.pm, avg 1.77ms/call sub _process_accessors {
1035 | 72 | 320µs |  |  | my $self = shift;
1036 |  |  |  |  | my ($type, $accessor, $generate_as_inline_methods) = @_;
1037 |  |  |  |  |
1038 |  |  |  |  | $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH';
1039 |  |  | 18 | 548µs | my $method = $self->associated_class->get_method($accessor); # spent 543µs making 9 calls to Class::MOP::Mixin::HasMethods::get_method, avg 60µs/call # spent 5µs making 9 calls to Class::MOP::Attribute::associated_class, avg 567ns/call
1040 |  |  |  |  |
1041 |  |  | 4 | 4µs | if ( $method # spent 2µ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 1µs making 1 call to UNIVERSAL::isa
1042 |  |  |  |  | && $method->isa('Class::MOP::Method::Accessor')
1043 |  |  |  |  | && $method->associated_attribute->name ne $self->name ) {
1044 |  |  |  |  |
1045 |  |  |  |  | my $other_attr_name = $method->associated_attribute->name;
1046 |  |  |  |  | my $name = $self->name;
1047 |  |  |  |  |
1048 |  |  |  |  | Carp::cluck(
1049 |  |  |  |  | "You are overwriting an accessor ($accessor) for the $other_attr_name attribute"
1050 |  |  |  |  | . " with a new accessor method for the $name attribute" );
1051 |  |  |  |  | }
1052 |  |  |  |  |
1053 |  |  | 2 | 2µs | if ( # spent 1µs making 1 call to Class::MOP::Method::is_stub # spent 600ns making 1 call to UNIVERSAL::isa
1054 |  |  |  |  | $method
1055 |  |  |  |  | && !$method->is_stub
1056 |  |  |  |  | && !$method->isa('Class::MOP::Method::Accessor')
1057 |  |  |  |  | && ( !$self->definition_context
1058 |  |  |  |  | || $method->package_name eq $self->definition_context->{package} )
1059 |  |  |  |  | ) {
1060 |  |  |  |  |
1061 |  |  |  |  | Carp::cluck(
1062 |  |  |  |  | "You are overwriting a locally defined method ($accessor) with "
1063 |  |  |  |  | . "an accessor" );
1064 |  |  |  |  | }
1065 |  |  |  |  |
1066 |  |  | 34 | 285µs | if ( !$self->associated_class->has_method($accessor) # spent 185µs making 9 calls to Class::MOP::Mixin::HasMethods::has_method, avg 21µs/call # spent 89µs making 8 calls to Class::MOP::Package::has_package_symbol, avg 11µs/call # spent 11µs making 17 calls to Class::MOP::Attribute::associated_class, avg 647ns/call
1067 |  |  |  |  | && $self->associated_class->has_package_symbol( '&' . $accessor ) ) {
1068 |  |  |  |  |
1069 |  |  |  |  | Carp::cluck(
1070 |  |  |  |  | "You are overwriting a locally defined function ($accessor) with "
1071 |  |  |  |  | . "an accessor" );
1072 |  |  |  |  | }
1073 |  |  |  |  |
1074 |  |  | 9 | 15.1ms | $self->SUPER::_process_accessors(@_); # spent 15.1ms making 9 calls to Class::MOP::Attribute::_process_accessors, avg 1.68ms/call
1075 |  |  |  |  | }
1076 |  |  |  |  |
1077 |  |  |  |  | sub remove_accessors {
1078 |  |  |  |  | my $self = shift;
1079 |  |  |  |  | $self->SUPER::remove_accessors(@_);
1080 |  |  |  |  | $self->remove_delegation if $self->has_handles;
1081 |  |  |  |  | return;
1082 |  |  |  |  | }
1083 |  |  |  |  |
1084 |  |  |  |  | sub install_delegation {
1085 |  |  |  |  | my $self = shift;
1086 |  |  |  |  |
1087 |  |  |  |  | # NOTE:
1088 |  |  |  |  | # Here we canonicalize the 'handles' option
1089 |  |  |  |  | # this will sort out any details and always
1090 |  |  |  |  | # return an hash of methods which we want
1091 |  |  |  |  | # to delagate to, see that method for details
1092 |  |  |  |  | my %handles = $self->_canonicalize_handles;
1093 |  |  |  |  |
1094 |  |  |  |  |
1095 |  |  |  |  | # install the delegation ...
1096 |  |  |  |  | my $associated_class = $self->associated_class;
1097 |  |  |  |  | foreach my $handle (sort keys %handles) {
1098 |  |  |  |  | my $method_to_call = $handles{$handle};
1099 |  |  |  |  | my $class_name = $associated_class->name;
1100 |  |  |  |  | my $name = "${class_name}::${handle}";
1101 |  |  |  |  |
1102 |  |  |  |  | if ( my $method = $associated_class->get_method($handle) ) {
1103 |  |  |  |  | $self->throw_error(
1104 |  |  |  |  | "You cannot overwrite a locally defined method ($handle) with a delegation",
1105 |  |  |  |  | method_name => $handle
1106 |  |  |  |  | ) unless $method->is_stub;
1107 |  |  |  |  | }
1108 |  |  |  |  |
1109 |  |  |  |  | # NOTE:
1110 |  |  |  |  | # handles is not allowed to delegate
1111 |  |  |  |  | # any of these methods, as they will
1112 |  |  |  |  | # override the ones in your class, which
1113 |  |  |  |  | # is almost certainly not what you want.
1114 |  |  |  |  |
1115 |  |  |  |  | # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something
1116 |  |  |  |  | #cluck("Not delegating method '$handle' because it is a core method") and
1117 |  |  |  |  | next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle);
1118 |  |  |  |  |
1119 |  |  |  |  | my $method = $self->_make_delegation_method($handle, $method_to_call);
1120 |  |  |  |  |
1121 |  |  |  |  | $self->associated_class->add_method($method->name, $method);
1122 |  |  |  |  | $self->associate_method($method);
1123 |  |  |  |  | }
1124 |  |  |  |  | }
1125 |  |  |  |  |
1126 |  |  |  |  | sub remove_delegation {
1127 |  |  |  |  | my $self = shift;
1128 |  |  |  |  | my %handles = $self->_canonicalize_handles;
1129 |  |  |  |  | my $associated_class = $self->associated_class;
1130 |  |  |  |  | foreach my $handle (keys %handles) {
1131 |  |  |  |  | next unless any { $handle eq $_ }
1132 |  |  |  |  | map { $_->name }
1133 |  |  |  |  | @{ $self->associated_methods };
1134 |  |  |  |  | $self->associated_class->remove_method($handle);
1135 |  |  |  |  | }
1136 |  |  |  |  | }
1137 |  |  |  |  |
1138 |  |  |  |  | # private methods to help delegation ...
1139 |  |  |  |  |
1140 |  |  |  |  | sub _canonicalize_handles {
1141 |  |  |  |  | my $self = shift;
1142 |  |  |  |  | my $handles = $self->handles;
1143 |  |  |  |  | if (my $handle_type = ref($handles)) {
1144 |  |  |  |  | if ($handle_type eq 'HASH') {
1145 |  |  |  |  | return %{$handles};
1146 |  |  |  |  | }
1147 |  |  |  |  | elsif ($handle_type eq 'ARRAY') {
1148 |  |  |  |  | return map { $_ => $_ } @{$handles};
1149 |  |  |  |  | }
1150 |  |  |  |  | elsif ($handle_type eq 'Regexp') {
1151 |  |  |  |  | ($self->has_type_constraint)
1152 |  |  |  |  | || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)", data => $handles);
1153 |  |  |  |  | return map { ($_ => $_) }
1154 |  |  |  |  | grep { /$handles/ } $self->_get_delegate_method_list;
1155 |  |  |  |  | }
1156 |  |  |  |  | elsif ($handle_type eq 'CODE') {
1157 |  |  |  |  | return $handles->($self, $self->_find_delegate_metaclass);
1158 |  |  |  |  | }
1159 |  |  |  |  | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) {
1160 |  |  |  |  | return map { $_ => $_ } @{ $handles->methods };
1161 |  |  |  |  | }
1162 |  |  |  |  | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) {
1163 |  |  |  |  | $handles = $handles->role;
1164 |  |  |  |  | }
1165 |  |  |  |  | else {
1166 |  |  |  |  | $self->throw_error("Unable to canonicalize the 'handles' option with $handles", data => $handles);
1167 |  |  |  |  | }
1168 |  |  |  |  | }
1169 |  |  |  |  |
1170 |  |  |  |  | load_class($handles);
1171 |  |  |  |  | my $role_meta = Class::MOP::class_of($handles);
1172 |  |  |  |  |
1173 |  |  |  |  | (blessed $role_meta && $role_meta->isa('Moose::Meta::Role'))
1174 |  |  |  |  | || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles);
1175 |  |  |  |  |
1176 |  |  |  |  | return map { $_ => $_ }
1177 |  |  |  |  | map { $_->name }
1178 |  |  |  |  | grep { !$_->isa('Class::MOP::Method::Meta') } (
1179 |  |  |  |  | $role_meta->_get_local_methods,
1180 |  |  |  |  | $role_meta->get_required_method_list,
1181 |  |  |  |  | );
1182 |  |  |  |  | }
1183 |  |  |  |  |
1184 |  |  |  |  | sub _get_delegate_method_list {
1185 |  |  |  |  | my $self = shift;
1186 |  |  |  |  | my $meta = $self->_find_delegate_metaclass;
1187 |  |  |  |  | if ($meta->isa('Class::MOP::Class')) {
1188 |  |  |  |  | return map { $_->name } # NOTE: !never! delegate &meta
1189 |  |  |  |  | grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') }
1190 |  |  |  |  | $meta->get_all_methods;
1191 |  |  |  |  | }
1192 |  |  |  |  | elsif ($meta->isa('Moose::Meta::Role')) {
1193 |  |  |  |  | return $meta->get_method_list;
1194 |  |  |  |  | }
1195 |  |  |  |  | else {
1196 |  |  |  |  | $self->throw_error("Unable to recognize the delegate metaclass '$meta'", data => $meta);
1197 |  |  |  |  | }
1198 |  |  |  |  | }
1199 |  |  |  |  |
1200 |  |  |  |  | sub _find_delegate_metaclass {
1201 |  |  |  |  | my $self = shift;
1202 |  |  |  |  | if (my $class = $self->_isa_metadata) {
1203 |  |  |  |  | unless ( is_class_loaded($class) ) {
1204 |  |  |  |  | $self->throw_error(
1205 |  |  |  |  | sprintf(
1206 |  |  |  |  | 'The %s attribute is trying to delegate to a class which has not been loaded - %s',
1207 |  |  |  |  | $self->name, $class
1208 |  |  |  |  | )
1209 |  |  |  |  | );
1210 |  |  |  |  | }
1211 |  |  |  |  | # we might be dealing with a non-Moose class,
1212 |  |  |  |  | # and need to make our own metaclass. if there's
1213 |  |  |  |  | # already a metaclass, it will be returned
1214 |  |  |  |  | return Class::MOP::Class->initialize($class);
1215 |  |  |  |  | }
1216 |  |  |  |  | elsif (my $role = $self->_does_metadata) {
1217 |  |  |  |  | unless ( is_class_loaded($class) ) {
1218 |  |  |  |  | $self->throw_error(
1219 |  |  |  |  | sprintf(
1220 |  |  |  |  | 'The %s attribute is trying to delegate to a role which has not been loaded - %s',
1221 |  |  |  |  | $self->name, $role
1222 |  |  |  |  | )
1223 |  |  |  |  | );
1224 |  |  |  |  | }
1225 |  |  |  |  |
1226 |  |  |  |  | return Class::MOP::class_of($role);
1227 |  |  |  |  | }
1228 |  |  |  |  | else {
1229 |  |  |  |  | $self->throw_error("Cannot find delegate metaclass for attribute " . $self->name);
1230 |  |  |  |  | }
1231 |  |  |  |  | }
1232 |  |  |  |  |
1233 |  |  |  |  | sub delegation_metaclass { 'Moose::Meta::Method::Delegation' }
1234 |  |  |  |  |
1235 |  |  |  |  | sub _make_delegation_method {
1236 |  |  |  |  | my ( $self, $handle_name, $method_to_call ) = @_;
1237 |  |  |  |  |
1238 |  |  |  |  | my @curried_arguments;
1239 |  |  |  |  |
1240 |  |  |  |  | ($method_to_call, @curried_arguments) = @$method_to_call
1241 |  |  |  |  | if 'ARRAY' eq ref($method_to_call);
1242 |  |  |  |  |
1243 |  |  |  |  | return $self->delegation_metaclass->new(
1244 |  |  |  |  | name => $handle_name,
1245 |  |  |  |  | package_name => $self->associated_class->name,
1246 |  |  |  |  | attribute => $self,
1247 |  |  |  |  | delegate_to_method => $method_to_call,
1248 |  |  |  |  | curried_arguments => \@curried_arguments,
1249 |  |  |  |  | );
1250 |  |  |  |  | }
1251 |  |  |  |  |
1252 |  |  |  |  | # spent 189µs (38+150) within Moose::Meta::Attribute::_coerce_and_verify which was called 4 times, avg 47µs/call: # 4 times (38µs+150µs) by Moose::Meta::Attribute::initialize_instance_slot at line 531, avg 47µs/call sub _coerce_and_verify {
1253 | 25 | 31µs |  |  | my $self = shift;
1254 |  |  |  |  | my $val = shift;
1255 |  |  |  |  | my $instance = shift;
1256 |  |  |  |  |
1257 |  |  | 4 | 8µs | return $val unless $self->has_type_constraint; # spent 8µs making 4 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 2µs/call
1258 |  |  |  |  |
1259 |  |  | 3 | 6µs | $val = $self->type_constraint->coerce($val) # spent 6µs making 3 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 2µs/call
1260 |  |  |  |  | if $self->should_coerce && $self->type_constraint->has_coercion;
1261 |  |  |  |  |
1262 |  |  | 3 | 136µs | $self->verify_against_type_constraint($val, instance => $instance); # spent 136µs making 3 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 45µs/call
1263 |  |  |  |  |
1264 |  |  |  |  | return $val;
1265 |  |  |  |  | }
1266 |  |  |  |  |
1267 |  |  |  |  | # spent 136µs (42+95) within Moose::Meta::Attribute::verify_against_type_constraint which was called 3 times, avg 45µs/call: # 3 times (42µs+95µs) by Moose::Meta::Attribute::_coerce_and_verify at line 1262, avg 45µs/call sub verify_against_type_constraint {
1268 | 15 | 36µs |  |  | my $self = shift;
1269 |  |  |  |  | my $val = shift;
1270 |  |  |  |  |
1271 |  |  | 3 | 3µs | return 1 if !$self->has_type_constraint; # spent 3µs making 3 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call
1272 |  |  |  |  |
1273 |  |  | 3 | 6µs | my $type_constraint = $self->type_constraint; # spent 6µs making 3 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 2µs/call
1274 |  |  |  |  |
1275 |  |  | 3 | 85µs | $type_constraint->check($val) # spent 85µs making 3 calls to Moose::Meta::TypeConstraint::check, avg 28µs/call
1276 |  |  |  |  | || $self->throw_error("Attribute ("
1277 |  |  |  |  | . $self->name
1278 |  |  |  |  | . ") does not pass the type constraint because: "
1279 |  |  |  |  | . $type_constraint->get_message($val), data => $val, @_);
1280 |  |  |  |  | }
1281 |  |  |  |  |
1282 |  |  |  |  | package Moose::Meta::Attribute::Custom::Moose;
1283 |  |  |  |  | # spent 11µs within Moose::Meta::Attribute::Custom::Moose::BEGIN@1283 which was called: # once (11µs+0s) by Moose::Meta::TypeCoercion::BEGIN@14 at line 1285 BEGIN {
1284 | 1 | 14µs |  |  | $Moose::Meta::Attribute::Custom::Moose::AUTHORITY = 'cpan:STEVAN';
1285 | 1 | 193µs | 1 | 11µs | } # spent 11µs making 1 call to Moose::Meta::Attribute::Custom::Moose::BEGIN@1283
1286 |  |  |  |  | {
1287 | 2 | 2µs |  |  | $Moose::Meta::Attribute::Custom::Moose::VERSION = '2.0602';
1288 |  |  |  |  | }
1289 |  |  |  |  | sub register_implementation { 'Moose::Meta::Attribute' }
1290 |  |  |  |  |
1291 | 1 | 13µs |  |  | 1;
1292 |  |  |  |  |
1293 |  |  |  |  | # ABSTRACT: The Moose attribute metaclass
1294 |  |  |  |  |
- - |  |  |  |  |
1297 |  |  |  |  | =pod
1298 |  |  |  |  |
1299 |  |  |  |  | =head1 NAME
1300 |  |  |  |  |
1301 |  |  |  |  | Moose::Meta::Attribute - The Moose attribute metaclass
1302 |  |  |  |  |
1303 |  |  |  |  | =head1 VERSION
1304 |  |  |  |  |
1305 |  |  |  |  | version 2.0602
1306 |  |  |  |  |
1307 |  |  |  |  | =head1 DESCRIPTION
1308 |  |  |  |  |
1309 |  |  |  |  | This class is a subclass of L<Class::MOP::Attribute> that provides
1310 |  |  |  |  | additional Moose-specific functionality.
1311 |  |  |  |  |
1312 |  |  |  |  | To really understand this class, you will need to start with the
1313 |  |  |  |  | L<Class::MOP::Attribute> documentation. This class can be understood
1314 |  |  |  |  | as a set of additional features on top of the basic feature provided
1315 |  |  |  |  | by that parent class.
1316 |  |  |  |  |
1317 |  |  |  |  | =head1 INHERITANCE
1318 |  |  |  |  |
1319 |  |  |  |  | C<Moose::Meta::Attribute> is a subclass of L<Class::MOP::Attribute>.
1320 |  |  |  |  |
1321 |  |  |  |  | =head1 METHODS
1322 |  |  |  |  |
1323 |  |  |  |  | Many of the documented below override methods in
1324 |  |  |  |  | L<Class::MOP::Attribute> and add Moose specific features.
1325 |  |  |  |  |
1326 |  |  |  |  | =head2 Creation
1327 |  |  |  |  |
1328 |  |  |  |  | =over 4
1329 |  |  |  |  |
1330 |  |  |  |  | =item B<< Moose::Meta::Attribute->new(%options) >>
1331 |  |  |  |  |
1332 |  |  |  |  | This method overrides the L<Class::MOP::Attribute> constructor.
1333 |  |  |  |  |
1334 |  |  |  |  | Many of the options below are described in more detail in the
1335 |  |  |  |  | L<Moose::Manual::Attributes> document.
1336 |  |  |  |  |
1337 |  |  |  |  | It adds the following options to the constructor:
1338 |  |  |  |  |
1339 |  |  |  |  | =over 8
1340 |  |  |  |  |
1341 |  |  |  |  | =item * is => 'ro', 'rw', 'bare'
1342 |  |  |  |  |
1343 |  |  |  |  | This provides a shorthand for specifying the C<reader>, C<writer>, or
1344 |  |  |  |  | C<accessor> names. If the attribute is read-only ('ro') then it will
1345 |  |  |  |  | have a C<reader> method with the same attribute as the name.
1346 |  |  |  |  |
1347 |  |  |  |  | If it is read-write ('rw') then it will have an C<accessor> method
1348 |  |  |  |  | with the same name. If you provide an explicit C<writer> for a
1349 |  |  |  |  | read-write attribute, then you will have a C<reader> with the same
1350 |  |  |  |  | name as the attribute, and a C<writer> with the name you provided.
1351 |  |  |  |  |
1352 |  |  |  |  | Use 'bare' when you are deliberately not installing any methods
1353 |  |  |  |  | (accessor, reader, etc.) associated with this attribute; otherwise,
1354 |  |  |  |  | Moose will issue a deprecation warning when this attribute is added to a
1355 |  |  |  |  | metaclass.
1356 |  |  |  |  |
1357 |  |  |  |  | =item * isa => $type
1358 |  |  |  |  |
1359 |  |  |  |  | This option accepts a type. The type can be a string, which should be
1360 |  |  |  |  | a type name. If the type name is unknown, it is assumed to be a class
1361 |  |  |  |  | name.
1362 |  |  |  |  |
1363 |  |  |  |  | This option can also accept a L<Moose::Meta::TypeConstraint> object.
1364 |  |  |  |  |
1365 |  |  |  |  | If you I<also> provide a C<does> option, then your C<isa> option must
1366 |  |  |  |  | be a class name, and that class must do the role specified with
1367 |  |  |  |  | C<does>.
1368 |  |  |  |  |
1369 |  |  |  |  | =item * does => $role
1370 |  |  |  |  |
1371 |  |  |  |  | This is short-hand for saying that the attribute's type must be an
1372 |  |  |  |  | object which does the named role.
1373 |  |  |  |  |
1374 |  |  |  |  | =item * coerce => $bool
1375 |  |  |  |  |
1376 |  |  |  |  | This option is only valid for objects with a type constraint
1377 |  |  |  |  | (C<isa>) that defined a coercion. If this is true, then coercions will be applied whenever
1378 |  |  |  |  | this attribute is set.
1379 |  |  |  |  |
1380 |  |  |  |  | You can make both this and the C<weak_ref> option true.
1381 |  |  |  |  |
1382 |  |  |  |  | =item * trigger => $sub
1383 |  |  |  |  |
1384 |  |  |  |  | This option accepts a subroutine reference, which will be called after
1385 |  |  |  |  | the attribute is set.
1386 |  |  |  |  |
1387 |  |  |  |  | =item * required => $bool
1388 |  |  |  |  |
1389 |  |  |  |  | An attribute which is required must be provided to the constructor. An
1390 |  |  |  |  | attribute which is required can also have a C<default> or C<builder>,
1391 |  |  |  |  | which will satisfy its required-ness.
1392 |  |  |  |  |
1393 |  |  |  |  | A required attribute must have a C<default>, C<builder> or a
1394 |  |  |  |  | non-C<undef> C<init_arg>
1395 |  |  |  |  |
1396 |  |  |  |  | =item * lazy => $bool
1397 |  |  |  |  |
1398 |  |  |  |  | A lazy attribute must have a C<default> or C<builder>. When an
1399 |  |  |  |  | attribute is lazy, the default value will not be calculated until the
1400 |  |  |  |  | attribute is read.
1401 |  |  |  |  |
1402 |  |  |  |  | =item * weak_ref => $bool
1403 |  |  |  |  |
1404 |  |  |  |  | If this is true, the attribute's value will be stored as a weak
1405 |  |  |  |  | reference.
1406 |  |  |  |  |
1407 |  |  |  |  | =item * auto_deref => $bool
1408 |  |  |  |  |
1409 |  |  |  |  | If this is true, then the reader will dereference the value when it is
1410 |  |  |  |  | called. The attribute must have a type constraint which defines the
1411 |  |  |  |  | attribute as an array or hash reference.
1412 |  |  |  |  |
1413 |  |  |  |  | =item * lazy_build => $bool
1414 |  |  |  |  |
1415 |  |  |  |  | Setting this to true makes the attribute lazy and provides a number of
1416 |  |  |  |  | default methods.
1417 |  |  |  |  |
1418 |  |  |  |  | has 'size' => (
1419 |  |  |  |  | is => 'ro',
1420 |  |  |  |  | lazy_build => 1,
1421 |  |  |  |  | );
1422 |  |  |  |  |
1423 |  |  |  |  | is equivalent to this:
1424 |  |  |  |  |
1425 |  |  |  |  | has 'size' => (
1426 |  |  |  |  | is => 'ro',
1427 |  |  |  |  | lazy => 1,
1428 |  |  |  |  | builder => '_build_size',
1429 |  |  |  |  | clearer => 'clear_size',
1430 |  |  |  |  | predicate => 'has_size',
1431 |  |  |  |  | );
1432 |  |  |  |  |
1433 |  |  |  |  | If your attribute name starts with an underscore (C<_>), then the clearer
1434 |  |  |  |  | and predicate will as well:
1435 |  |  |  |  |
1436 |  |  |  |  | has '_size' => (
1437 |  |  |  |  | is => 'ro',
1438 |  |  |  |  | lazy_build => 1,
1439 |  |  |  |  | );
1440 |  |  |  |  |
1441 |  |  |  |  | becomes:
1442 |  |  |  |  |
1443 |  |  |  |  | has '_size' => (
1444 |  |  |  |  | is => 'ro',
1445 |  |  |  |  | lazy => 1,
1446 |  |  |  |  | builder => '_build__size',
1447 |  |  |  |  | clearer => '_clear_size',
1448 |  |  |  |  | predicate => '_has_size',
1449 |  |  |  |  | );
1450 |  |  |  |  |
1451 |  |  |  |  | Note the doubled underscore in the builder name. Internally, Moose
1452 |  |  |  |  | simply prepends the attribute name with "_build_" to come up with the
1453 |  |  |  |  | builder name.
1454 |  |  |  |  |
1455 |  |  |  |  | =item * documentation
1456 |  |  |  |  |
1457 |  |  |  |  | An arbitrary string that can be retrieved later by calling C<<
1458 |  |  |  |  | $attr->documentation >>.
1459 |  |  |  |  |
1460 |  |  |  |  | =back
1461 |  |  |  |  |
1462 |  |  |  |  | =item B<< $attr->clone(%options) >>
1463 |  |  |  |  |
1464 |  |  |  |  | This creates a new attribute based on attribute being cloned. You must
1465 |  |  |  |  | supply a C<name> option to provide a new name for the attribute.
1466 |  |  |  |  |
1467 |  |  |  |  | The C<%options> can only specify options handled by
1468 |  |  |  |  | L<Class::MOP::Attribute>.
1469 |  |  |  |  |
1470 |  |  |  |  | =back
1471 |  |  |  |  |
1472 |  |  |  |  | =head2 Value management
1473 |  |  |  |  |
1474 |  |  |  |  | =over 4
1475 |  |  |  |  |
1476 |  |  |  |  | =item B<< $attr->initialize_instance_slot($meta_instance, $instance, $params) >>
1477 |  |  |  |  |
1478 |  |  |  |  | This method is used internally to initialize the attribute's slot in
1479 |  |  |  |  | the object C<$instance>.
1480 |  |  |  |  |
1481 |  |  |  |  | This overrides the L<Class::MOP::Attribute> method to handle lazy
1482 |  |  |  |  | attributes, weak references, and type constraints.
1483 |  |  |  |  |
1484 |  |  |  |  | =item B<get_value>
1485 |  |  |  |  |
1486 |  |  |  |  | =item B<set_value>
1487 |  |  |  |  |
1488 |  |  |  |  | eval { $point->meta->get_attribute('x')->set_value($point, 'forty-two') };
1489 |  |  |  |  | if($@) {
1490 |  |  |  |  | print "Oops: $@\n";
1491 |  |  |  |  | }
1492 |  |  |  |  |
1493 |  |  |  |  | I<Attribute (x) does not pass the type constraint (Int) with 'forty-two'>
1494 |  |  |  |  |
1495 |  |  |  |  | Before setting the value, a check is made on the type constraint of
1496 |  |  |  |  | the attribute, if it has one, to see if the value passes it. If the
1497 |  |  |  |  | value fails to pass, the set operation dies.
1498 |  |  |  |  |
1499 |  |  |  |  | Any coercion to convert values is done before checking the type constraint.
1500 |  |  |  |  |
1501 |  |  |  |  | To check a value against a type constraint before setting it, fetch the
1502 |  |  |  |  | attribute instance using L<Class::MOP::Class/find_attribute_by_name>,
1503 |  |  |  |  | fetch the type_constraint from the attribute using L<Moose::Meta::Attribute/type_constraint>
1504 |  |  |  |  | and call L<Moose::Meta::TypeConstraint/check>. See L<Moose::Cookbook::Basics::Company_Subtypes>
1505 |  |  |  |  | for an example.
1506 |  |  |  |  |
1507 |  |  |  |  | =back
1508 |  |  |  |  |
1509 |  |  |  |  | =head2 Attribute Accessor generation
1510 |  |  |  |  |
1511 |  |  |  |  | =over 4
1512 |  |  |  |  |
1513 |  |  |  |  | =item B<< $attr->install_accessors >>
1514 |  |  |  |  |
1515 |  |  |  |  | This method overrides the parent to also install delegation methods.
1516 |  |  |  |  |
1517 |  |  |  |  | If, after installing all methods, the attribute object has no associated
1518 |  |  |  |  | methods, it throws an error unless C<< is => 'bare' >> was passed to the
1519 |  |  |  |  | attribute constructor. (Trying to add an attribute that has no associated
1520 |  |  |  |  | methods is almost always an error.)
1521 |  |  |  |  |
1522 |  |  |  |  | =item B<< $attr->remove_accessors >>
1523 |  |  |  |  |
1524 |  |  |  |  | This method overrides the parent to also remove delegation methods.
1525 |  |  |  |  |
1526 |  |  |  |  | =item B<< $attr->inline_set($instance_var, $value_var) >>
1527 |  |  |  |  |
1528 |  |  |  |  | This method return a code snippet suitable for inlining the relevant
1529 |  |  |  |  | operation. It expect strings containing variable names to be used in the
1530 |  |  |  |  | inlining, like C<'$self'> or C<'$_[1]'>.
1531 |  |  |  |  |
1532 |  |  |  |  | =item B<< $attr->install_delegation >>
1533 |  |  |  |  |
1534 |  |  |  |  | This method adds its delegation methods to the attribute's associated
1535 |  |  |  |  | class, if it has any to add.
1536 |  |  |  |  |
1537 |  |  |  |  | =item B<< $attr->remove_delegation >>
1538 |  |  |  |  |
1539 |  |  |  |  | This method remove its delegation methods from the attribute's
1540 |  |  |  |  | associated class.
1541 |  |  |  |  |
1542 |  |  |  |  | =item B<< $attr->accessor_metaclass >>
1543 |  |  |  |  |
1544 |  |  |  |  | Returns the accessor metaclass name, which defaults to
1545 |  |  |  |  | L<Moose::Meta::Method::Accessor>.
1546 |  |  |  |  |
1547 |  |  |  |  | =item B<< $attr->delegation_metaclass >>
1548 |  |  |  |  |
1549 |  |  |  |  | Returns the delegation metaclass name, which defaults to
1550 |  |  |  |  | L<Moose::Meta::Method::Delegation>.
1551 |  |  |  |  |
1552 |  |  |  |  | =back
1553 |  |  |  |  |
1554 |  |  |  |  | =head2 Additional Moose features
1555 |  |  |  |  |
1556 |  |  |  |  | These methods are not found in the superclass. They support features
1557 |  |  |  |  | provided by Moose.
1558 |  |  |  |  |
1559 |  |  |  |  | =over 4
1560 |  |  |  |  |
1561 |  |  |  |  | =item B<< $attr->does($role) >>
1562 |  |  |  |  |
1563 |  |  |  |  | This indicates whether the I<attribute itself> does the given
1564 |  |  |  |  | role. The role can be given as a full class name, or as a resolvable
1565 |  |  |  |  | trait name.
1566 |  |  |  |  |
1567 |  |  |  |  | Note that this checks the attribute itself, not its type constraint,
1568 |  |  |  |  | so it is checking the attribute's metaclass and any traits applied to
1569 |  |  |  |  | the attribute.
1570 |  |  |  |  |
1571 |  |  |  |  | =item B<< Moose::Meta::Class->interpolate_class_and_new($name, %options) >>
1572 |  |  |  |  |
1573 |  |  |  |  | This is an alternate constructor that handles the C<metaclass> and
1574 |  |  |  |  | C<traits> options.
1575 |  |  |  |  |
1576 |  |  |  |  | Effectively, this method is a factory that finds or creates the
1577 |  |  |  |  | appropriate class for the given C<metaclass> and/or C<traits>.
1578 |  |  |  |  |
1579 |  |  |  |  | Once it has the appropriate class, it will call C<< $class->new($name,
1580 |  |  |  |  | %options) >> on that class.
1581 |  |  |  |  |
1582 |  |  |  |  | =item B<< $attr->clone_and_inherit_options(%options) >>
1583 |  |  |  |  |
1584 |  |  |  |  | This method supports the C<has '+foo'> feature. It does various bits
1585 |  |  |  |  | of processing on the supplied C<%options> before ultimately calling
1586 |  |  |  |  | the C<clone> method.
1587 |  |  |  |  |
1588 |  |  |  |  | One of its main tasks is to make sure that the C<%options> provided
1589 |  |  |  |  | does not include the options returned by the
1590 |  |  |  |  | C<illegal_options_for_inheritance> method.
1591 |  |  |  |  |
1592 |  |  |  |  | =item B<< $attr->illegal_options_for_inheritance >>
1593 |  |  |  |  |
1594 |  |  |  |  | This returns a blacklist of options that can not be overridden in a
1595 |  |  |  |  | subclass's attribute definition.
1596 |  |  |  |  |
1597 |  |  |  |  | This exists to allow a custom metaclass to change or add to the list
1598 |  |  |  |  | of options which can not be changed.
1599 |  |  |  |  |
1600 |  |  |  |  | =item B<< $attr->type_constraint >>
1601 |  |  |  |  |
1602 |  |  |  |  | Returns the L<Moose::Meta::TypeConstraint> object for this attribute,
1603 |  |  |  |  | if it has one.
1604 |  |  |  |  |
1605 |  |  |  |  | =item B<< $attr->has_type_constraint >>
1606 |  |  |  |  |
1607 |  |  |  |  | Returns true if this attribute has a type constraint.
1608 |  |  |  |  |
1609 |  |  |  |  | =item B<< $attr->verify_against_type_constraint($value) >>
1610 |  |  |  |  |
1611 |  |  |  |  | Given a value, this method returns true if the value is valid for the
1612 |  |  |  |  | attribute's type constraint. If the value is not valid, it throws an
1613 |  |  |  |  | error.
1614 |  |  |  |  |
1615 |  |  |  |  | =item B<< $attr->handles >>
1616 |  |  |  |  |
1617 |  |  |  |  | This returns the value of the C<handles> option passed to the
1618 |  |  |  |  | constructor.
1619 |  |  |  |  |
1620 |  |  |  |  | =item B<< $attr->has_handles >>
1621 |  |  |  |  |
1622 |  |  |  |  | Returns true if this attribute performs delegation.
1623 |  |  |  |  |
1624 |  |  |  |  | =item B<< $attr->is_weak_ref >>
1625 |  |  |  |  |
1626 |  |  |  |  | Returns true if this attribute stores its value as a weak reference.
1627 |  |  |  |  |
1628 |  |  |  |  | =item B<< $attr->is_required >>
1629 |  |  |  |  |
1630 |  |  |  |  | Returns true if this attribute is required to have a value.
1631 |  |  |  |  |
1632 |  |  |  |  | =item B<< $attr->is_lazy >>
1633 |  |  |  |  |
1634 |  |  |  |  | Returns true if this attribute is lazy.
1635 |  |  |  |  |
1636 |  |  |  |  | =item B<< $attr->is_lazy_build >>
1637 |  |  |  |  |
1638 |  |  |  |  | Returns true if the C<lazy_build> option was true when passed to the
1639 |  |  |  |  | constructor.
1640 |  |  |  |  |
1641 |  |  |  |  | =item B<< $attr->should_coerce >>
1642 |  |  |  |  |
1643 |  |  |  |  | Returns true if the C<coerce> option passed to the constructor was
1644 |  |  |  |  | true.
1645 |  |  |  |  |
1646 |  |  |  |  | =item B<< $attr->should_auto_deref >>
1647 |  |  |  |  |
1648 |  |  |  |  | Returns true if the C<auto_deref> option passed to the constructor was
1649 |  |  |  |  | true.
1650 |  |  |  |  |
1651 |  |  |  |  | =item B<< $attr->trigger >>
1652 |  |  |  |  |
1653 |  |  |  |  | This is the subroutine reference that was in the C<trigger> option
1654 |  |  |  |  | passed to the constructor, if any.
1655 |  |  |  |  |
1656 |  |  |  |  | =item B<< $attr->has_trigger >>
1657 |  |  |  |  |
1658 |  |  |  |  | Returns true if this attribute has a trigger set.
1659 |  |  |  |  |
1660 |  |  |  |  | =item B<< $attr->documentation >>
1661 |  |  |  |  |
1662 |  |  |  |  | Returns the value that was in the C<documentation> option passed to
1663 |  |  |  |  | the constructor, if any.
1664 |  |  |  |  |
1665 |  |  |  |  | =item B<< $attr->has_documentation >>
1666 |  |  |  |  |
1667 |  |  |  |  | Returns true if this attribute has any documentation.
1668 |  |  |  |  |
1669 |  |  |  |  | =item B<< $attr->applied_traits >>
1670 |  |  |  |  |
1671 |  |  |  |  | This returns an array reference of all the traits which were applied
1672 |  |  |  |  | to this attribute. If none were applied, this returns C<undef>.
1673 |  |  |  |  |
1674 |  |  |  |  | =item B<< $attr->has_applied_traits >>
1675 |  |  |  |  |
1676 |  |  |  |  | Returns true if this attribute has any traits applied.
1677 |  |  |  |  |
1678 |  |  |  |  | =back
1679 |  |  |  |  |
1680 |  |  |  |  | =head1 BUGS
1681 |  |  |  |  |
1682 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
1683 |  |  |  |  |
1684 |  |  |  |  | =head1 AUTHOR
1685 |  |  |  |  |
1686 |  |  |  |  | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
1687 |  |  |  |  |
1688 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
1689 |  |  |  |  |
1690 |  |  |  |  | This software is copyright (c) 2012 by Infinity Interactive, Inc..
1691 |  |  |  |  |
1692 |  |  |  |  | This is free software; you can redistribute it and/or modify it under
1693 |  |  |  |  | the same terms as the Perl 5 programming language system itself.
1694 |  |  |  |  |
1695 |  |  |  |  | =cut
1696 |  |  |  |  |
1697 |  |  |  |  |
1698 |  |  |  |  | __END__
|  |  |  |  | # spent 12µs within Moose::Meta::Attribute::CORE:sort which was called 9 times, avg 1µs/call: # 9 times (12µs+0s) by Moose::Meta::Attribute::new at line 99, avg 1µs/call sub Moose::Meta::Attribute::CORE:sort; # opcode