File | /usr/local/lib/perl/5.10.0/Class/MOP/Mixin/HasAttributes.pm |
Statements Executed | 3630 |
Total Time | 0.0119933 seconds |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
123 | 113 | 23 | 3.43ms | 79.3ms | add_attribute | Class::MOP::Mixin::HasAttributes::
181 | 2 | 2 | 1.28ms | 2.06ms | has_attribute | Class::MOP::Mixin::HasAttributes::
126 | 2 | 1 | 1.03ms | 1.52ms | get_attribute | Class::MOP::Mixin::HasAttributes::
32 | 1 | 1 | 196µs | 391µs | get_attribute_list | Class::MOP::Mixin::HasAttributes::
0 | 0 | 0 | 0s | 0s | BEGIN | Class::MOP::Mixin::HasAttributes::
0 | 0 | 0 | 0s | 0s | _restore_metaattributes_from | Class::MOP::Mixin::HasAttributes::
0 | 0 | 0 | 0s | 0s | remove_attribute | Class::MOP::Mixin::HasAttributes::
Line | Stmts. | Exclusive Time | Avg. | Code |
---|---|---|---|---|
1 | package Class::MOP::Mixin::HasAttributes; | |||
2 | ||||
3 | 3 | 29µs | 10µs | use strict; # spent 9µs making 1 call to strict::import |
4 | 3 | 57µs | 19µs | use warnings; # spent 17µs making 1 call to warnings::import |
5 | ||||
6 | 1 | 700ns | 700ns | our $VERSION = '1.09'; |
7 | 1 | 29µs | 29µs | $VERSION = eval $VERSION; |
8 | 1 | 500ns | 500ns | our $AUTHORITY = 'cpan:STEVAN'; |
9 | ||||
10 | 3 | 26µs | 9µs | use Carp 'confess'; # spent 50µs making 1 call to Exporter::import |
11 | 3 | 24µs | 8µs | use Scalar::Util 'blessed'; # spent 40µs making 1 call to Exporter::import |
12 | ||||
13 | 3 | 561µs | 187µs | use base 'Class::MOP::Mixin'; # spent 71µs making 1 call to base::import |
14 | ||||
15 | 1007 | 1.80ms | 2µs | sub _attribute_map { $_[0]->{'attributes'} } |
16 | 266 | 572µs | 2µs | sub attribute_metaclass { $_[0]->{'attribute_metaclass'} } |
17 | ||||
18 | # spent 79.3ms (3.43+75.8) within Class::MOP::Mixin::HasAttributes::add_attribute which was called 123 times, avg 644µs/call:
# 8 times (237µs+15.4ms) by Moose::Meta::Class::add_attribute at line 298 of /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm, avg 1.95ms/call
# 3 times (88µs+1.55ms) at line 280 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm, avg 544µs/call
# 2 times (68µs+1.06ms) at line 90 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm, avg 563µs/call
# once (46µs+3.68ms) at line 20 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeCoercion.pm
# once (34µs+1.67ms) at line 43 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (27µs+1.13ms) at line 16 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Registry.pm
# once (23µs+991µs) at line 35 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (37µs+898µs) at line 36 of /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm
# once (36µs+868µs) at line 17 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Parameterized.pm
# once (32µs+872µs) at line 15 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Parameterizable.pm
# once (40µs+791µs) at line 192 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (28µs+785µs) at line 26 of /usr/local/lib/perl/5.10.0/Moose/Meta/Attribute.pm
# once (25µs+774µs) at line 20 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Method/Required.pm
# once (29µs+768µs) at line 23 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (34µs+761µs) at line 23 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (33µs+758µs) at line 33 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (30µs+744µs) at line 22 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (33µs+709µs) at line 56 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (28µs+707µs) at line 38 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (24µs+698µs) at line 42 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (28µs+684µs) at line 29 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (32µs+680µs) at line 34 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (36µs+617µs) at line 18 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeCoercion.pm
# once (18µs+631µs) at line 482 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (44µs+594µs) at line 20 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Application/RoleSummation.pm
# once (27µs+603µs) at line 15 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Enum.pm
# once (49µs+571µs) at line 16 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Class.pm
# once (31µs+576µs) at line 15 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Attribute.pm
# once (28µs+575µs) at line 21 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Composite.pm
# once (42µs+558µs) at line 16 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Application/ToClass.pm
# once (40µs+559µs) at line 15 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Application.pm
# once (34µs+563µs) at line 21 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Union.pm
# once (33µs+559µs) at line 15 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Method/Conflicting.pm
# once (32µs+555µs) at line 18 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Application/ToInstance.pm
# once (40µs+547µs) at line 125 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (36µs+549µs) at line 41 of /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm
# once (36µs+547µs) at line 28 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeCoercion.pm
# once (36µs+546µs) at line 16 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Role.pm
# once (32µs+548µs) at line 11 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (24µs+552µs) at line 25 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Registry.pm
# once (31µs+544µs) at line 21 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Attribute.pm
# once (28µs+546µs) at line 19 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/DuckType.pm
# once (30µs+536µs) at line 12 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (35µs+524µs) at line 325 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (31µs+509µs) at line 20 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Application/ToClass.pm
# once (40µs+494µs) at line 130 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (28µs+497µs) at line 21 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Application.pm
# once (36µs+489µs) at line 13 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (19µs+501µs) at line 440 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (24µs+494µs) at line 43 of /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm
# once (42µs+473µs) at line 27 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Attribute.pm
# once (18µs+496µs) at line 413 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (36µs+474µs) at line 31 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Composite.pm
# once (29µs+476µs) at line 16 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (31µs+472µs) at line 33 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Attribute.pm
# once (36µs+467µs) at line 20 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (48µs+454µs) at line 454 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (34µs+464µs) at line 15 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (23µs+476µs) at line 377 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (22µs+474µs) at line 21 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (23µs+472µs) at line 50 of /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm
# once (23µs+470µs) at line 420 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (27µs+465µs) at line 136 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (36µs+455µs) at line 17 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (19µs+469µs) at line 447 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (23µs+460µs) at line 60 of /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm
# once (23µs+460µs) at line 33 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Composite.pm
# once (18µs+461µs) at line 427 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (33µs+441µs) at line 19 of /usr/local/lib/perl/5.10.0/Moose/Meta/Mixin/AttributeCore.pm
# once (18µs+451µs) at line 544 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+450µs) at line 468 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (28µs+439µs) at line 148 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (24µs+441µs) at line 154 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (33µs+429µs) at line 142 of /usr/local/lib/perl/5.10.0/Moose/Meta/Role.pm
# once (24µs+435µs) at line 55 of /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm
# once (18µs+434µs) at line 461 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (29µs+416µs) at line 60 of /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint.pm
# once (24µs+385µs) at line 195 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (24µs+356µs) at line 276 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (30µs+339µs) at line 302 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (30µs+338µs) at line 207 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (20µs+345µs) at line 615 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (20µs+340µs) at line 566 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (28µs+330µs) at line 252 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (24µs+334µs) at line 337 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (20µs+335µs) at line 234 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (25µs+328µs) at line 399 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (23µs+326µs) at line 364 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (20µs+326µs) at line 492 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (19µs+326µs) at line 583 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (19µs+324µs) at line 634 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (20µs+323µs) at line 373 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+323µs) at line 321 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (23µs+312µs) at line 237 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (28µs+305µs) at line 592 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (24µs+308µs) at line 520 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+313µs) at line 340 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+311µs) at line 510 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+302µs) at line 526 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (27µs+291µs) at line 600 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+300µs) at line 640 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (19µs+299µs) at line 618 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+299µs) at line 649 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+296µs) at line 355 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+296µs) at line 383 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+292µs) at line 655 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (28µs+281µs) at line 538 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+286µs) at line 573 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (19µs+285µs) at line 434 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+281µs) at line 661 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+277µs) at line 475 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (18µs+275µs) at line 532 of /usr/local/lib/perl/5.10.0/Class/MOP.pm
# once (25µs+160µs) at line 559 of /usr/local/lib/perl/5.10.0/Class/MOP.pm | |||
19 | 123 | 56µs | 457ns | my $self = shift; |
20 | ||||
21 | 123 | 1.07ms | 9µs | my $attribute # spent 2.88ms making 66 calls to Class::MOP::Attribute::new, avg 44µs/call
# spent 310µs making 123 calls to Scalar::Util::blessed, avg 3µs/call
# spent 299µs making 66 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 5µs/call |
22 | = blessed( $_[0] ) ? $_[0] : $self->attribute_metaclass->new(@_); | |||
23 | ||||
24 | 123 | 859µs | 7µs | ( $attribute->isa('Class::MOP::Mixin::AttributeCore') ) # spent 710µs making 123 calls to UNIVERSAL::isa, avg 6µs/call |
25 | || confess | |||
26 | "Your attribute must be an instance of Class::MOP::Mixin::AttributeCore (or a subclass)"; | |||
27 | ||||
28 | 123 | 441µs | 4µs | $self->_attach_attribute($attribute); # spent 2.51ms making 123 calls to Class::MOP::Class::_attach_attribute, avg 20µs/call |
29 | ||||
30 | 123 | 534µs | 4µs | my $attr_name = $attribute->name; # spent 384µs making 123 calls to Class::MOP::Mixin::AttributeCore::name, avg 3µs/call |
31 | ||||
32 | 123 | 459µs | 4µs | $self->remove_attribute($attr_name) # spent 1.32ms making 123 calls to Class::MOP::Mixin::HasAttributes::has_attribute, avg 11µs/call |
33 | if $self->has_attribute($attr_name); | |||
34 | ||||
35 | 123 | 542µs | 4µs | my $order = ( scalar keys %{ $self->_attribute_map } ); # spent 413µs making 123 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 3µs/call |
36 | 123 | 473µs | 4µs | $attribute->_set_insertion_order($order); # spent 477µs making 123 calls to Class::MOP::Mixin::AttributeCore::_set_insertion_order, avg 4µs/call |
37 | ||||
38 | 123 | 562µs | 5µs | $self->_attribute_map->{$attr_name} = $attribute; # spent 393µs making 123 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 3µs/call |
39 | ||||
40 | # This method is called to allow for installing accessors. Ideally, we'd | |||
41 | # use method overriding, but then the subclass would be responsible for | |||
42 | # making the attribute, which would end up with lots of code | |||
43 | # duplication. Even more ideally, we'd use augment/inner, but this is | |||
44 | # Class::MOP! | |||
45 | 123 | 1.37ms | 11µs | $self->_post_add_attribute($attribute) # spent 65.8ms making 123 calls to Class::MOP::Class::_post_add_attribute, avg 535µs/call
# spent 367µs making 123 calls to UNIVERSAL::can, avg 3µs/call |
46 | if $self->can('_post_add_attribute'); | |||
47 | ||||
48 | 123 | 154µs | 1µs | return $attribute; |
49 | } | |||
50 | ||||
51 | # spent 2.06ms (1.28+786µs) within Class::MOP::Mixin::HasAttributes::has_attribute which was called 181 times, avg 11µs/call:
# 123 times (807µs+518µs) by Class::MOP::Mixin::HasAttributes::add_attribute at line 32, avg 11µs/call
# 58 times (469µs+267µs) by Class::MOP::Class::find_attribute_by_name at line 795 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 13µs/call | |||
52 | 181 | 245µs | 1µs | my ( $self, $attribute_name ) = @_; |
53 | ||||
54 | 181 | 65µs | 358ns | ( defined $attribute_name ) |
55 | || confess "You must define an attribute name"; | |||
56 | ||||
57 | 181 | 911µs | 5µs | exists $self->_attribute_map->{$attribute_name}; # spent 786µs making 181 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 4µs/call |
58 | } | |||
59 | ||||
60 | # spent 1.52ms (1.03+486µs) within Class::MOP::Mixin::HasAttributes::get_attribute which was called 126 times, avg 12µs/call:
# 68 times (622µs+298µs) by Class::MOP::Class::_inline_accessors at line 1273 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 14µs/call
# 58 times (409µs+188µs) by Class::MOP::Class::find_attribute_by_name at line 795 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 10µs/call | |||
61 | 126 | 159µs | 1µs | my ( $self, $attribute_name ) = @_; |
62 | ||||
63 | 126 | 45µs | 360ns | ( defined $attribute_name ) |
64 | || confess "You must define an attribute name"; | |||
65 | ||||
66 | 126 | 770µs | 6µs | return $self->_attribute_map->{$attribute_name}; # spent 486µs making 126 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 4µs/call |
67 | } | |||
68 | ||||
69 | sub remove_attribute { | |||
70 | my ( $self, $attribute_name ) = @_; | |||
71 | ||||
72 | ( defined $attribute_name ) | |||
73 | || confess "You must define an attribute name"; | |||
74 | ||||
75 | my $removed_attribute = $self->_attribute_map->{$attribute_name}; | |||
76 | return unless defined $removed_attribute; | |||
77 | ||||
78 | delete $self->_attribute_map->{$attribute_name}; | |||
79 | ||||
80 | return $removed_attribute; | |||
81 | } | |||
82 | ||||
83 | # spent 391µs (196+195) within Class::MOP::Mixin::HasAttributes::get_attribute_list which was called 32 times, avg 12µs/call:
# 32 times (196µs+195µs) by Class::MOP::Class::_inline_accessors at line 1272 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 12µs/call | |||
84 | 32 | 14µs | 450ns | my $self = shift; |
85 | 32 | 164µs | 5µs | keys %{ $self->_attribute_map }; # spent 195µs making 32 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 6µs/call |
86 | } | |||
87 | ||||
88 | sub _restore_metaattributes_from { | |||
89 | my $self = shift; | |||
90 | my ($old_meta) = @_; | |||
91 | ||||
92 | for my $attr (sort { $a->insertion_order <=> $b->insertion_order } | |||
93 | map { $old_meta->get_attribute($_) } | |||
94 | $old_meta->get_attribute_list) { | |||
95 | $attr->_make_compatible_with($self->attribute_metaclass); | |||
96 | $self->add_attribute($attr); | |||
97 | } | |||
98 | } | |||
99 | ||||
100 | 1 | 4µs | 4µs | 1; |
101 | ||||
102 | __END__ | |||
103 | ||||
104 | =pod | |||
105 | ||||
106 | =head1 NAME | |||
107 | ||||
108 | Class::MOP::Mixin::HasMethods - Methods for metaclasses which have attributes | |||
109 | ||||
110 | =head1 DESCRIPTION | |||
111 | ||||
112 | This class implements methods for metaclasses which have attributes | |||
113 | (L<Class::MOP::Class> and L<Moose::Meta::Role>). See L<Class::MOP::Class> for | |||
114 | API details. | |||
115 | ||||
116 | =head1 AUTHORS | |||
117 | ||||
118 | Dave Rolsky E<lt>autarch@urth.orgE<gt> | |||
119 | ||||
120 | =head1 COPYRIGHT AND LICENSE | |||
121 | ||||
122 | Copyright 2006-2010 by Infinity Interactive, Inc. | |||
123 | ||||
124 | L<http://www.iinteractive.com> | |||
125 | ||||
126 | This library is free software; you can redistribute it and/or modify | |||
127 | it under the same terms as Perl itself. | |||
128 | ||||
129 | =cut |