File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Role/Attribute.pm |
Statements Executed | 460 |
Statement Execution Time | 1.80ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
37 | 1 | 1 | 349µs | 14.6ms | attribute_for_class | Moose::Meta::Role::Attribute::
44 | 2 | 2 | 326µs | 326µs | new | Moose::Meta::Role::Attribute::
44 | 1 | 1 | 287µs | 361µs | attach_to_role | Moose::Meta::Role::Attribute::
30 | 1 | 1 | 229µs | 495µs | clone | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 15µs | 17µs | BEGIN@3 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 9µs | 33µs | BEGIN@7 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 7µs | 50µs | BEGIN@13 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 7µs | 15µs | BEGIN@4 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 6µs | 31µs | BEGIN@8 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 6µs | 29µs | BEGIN@6 | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:90] | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | is_same_as | Moose::Meta::Role::Attribute::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Role::Attribute; | ||||
2 | |||||
3 | 3 | 20µs | 2 | 20µs | # spent 17µs (15+3) within Moose::Meta::Role::Attribute::BEGIN@3 which was called
# once (15µs+3µs) by Moose::Meta::Role::BEGIN@17 at line 3 # spent 17µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@3
# spent 3µs making 1 call to strict::import |
4 | 3 | 20µs | 2 | 24µs | # spent 15µs (7+9) within Moose::Meta::Role::Attribute::BEGIN@4 which was called
# once (7µs+9µs) by Moose::Meta::Role::BEGIN@17 at line 4 # spent 15µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@4
# spent 9µs making 1 call to warnings::import |
5 | |||||
6 | 3 | 33µs | 2 | 52µs | # spent 29µs (6+23) within Moose::Meta::Role::Attribute::BEGIN@6 which was called
# once (6µs+23µs) by Moose::Meta::Role::BEGIN@17 at line 6 # spent 29µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@6
# spent 23µs making 1 call to Exporter::import |
7 | 3 | 25µs | 2 | 57µs | # spent 33µs (9+24) within Moose::Meta::Role::Attribute::BEGIN@7 which was called
# once (9µs+24µs) by Moose::Meta::Role::BEGIN@17 at line 7 # spent 33µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@7
# spent 24µs making 1 call to Exporter::import |
8 | 3 | 46µs | 2 | 56µs | # spent 31µs (6+25) within Moose::Meta::Role::Attribute::BEGIN@8 which was called
# once (6µs+25µs) by Moose::Meta::Role::BEGIN@17 at line 8 # spent 31µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@8
# spent 25µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 600ns | our $VERSION = '0.98'; | ||
11 | 1 | 200ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
12 | |||||
13 | 3 | 324µs | 2 | 92µs | # spent 50µs (7+43) within Moose::Meta::Role::Attribute::BEGIN@13 which was called
# once (7µs+43µs) by Moose::Meta::Role::BEGIN@17 at line 13 # spent 50µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@13
# spent 42µs making 1 call to base::import |
14 | |||||
15 | 1 | 9µs | 2 | 342µs | __PACKAGE__->meta->add_attribute( # spent 287µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 56µs making 1 call to Class::MOP::Mixin::meta |
16 | 'metaclass' => ( | ||||
17 | reader => 'metaclass', | ||||
18 | ) | ||||
19 | ); | ||||
20 | |||||
21 | 1 | 2µs | 2 | 269µs | __PACKAGE__->meta->add_attribute( # spent 258µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Class::MOP::Mixin::meta |
22 | 'associated_role' => ( | ||||
23 | reader => 'associated_role', | ||||
24 | ) | ||||
25 | ); | ||||
26 | |||||
27 | 1 | 2µs | 2 | 261µs | __PACKAGE__->meta->add_attribute( # spent 250µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Class::MOP::Mixin::meta |
28 | 'is' => ( | ||||
29 | reader => 'is', | ||||
30 | ) | ||||
31 | ); | ||||
32 | |||||
33 | 1 | 2µs | 2 | 270µs | __PACKAGE__->meta->add_attribute( # spent 259µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Class::MOP::Mixin::meta |
34 | 'original_options' => ( | ||||
35 | reader => 'original_options', | ||||
36 | ) | ||||
37 | ); | ||||
38 | |||||
39 | # spent 326µs within Moose::Meta::Role::Attribute::new which was called 44 times, avg 7µs/call:
# 30 times (196µs+0s) by Moose::Meta::Role::Attribute::clone at line 73, avg 7µs/call
# 14 times (130µs+0s) by Class::MOP::Mixin::HasAttributes::add_attribute at line 21 of Class/MOP/Mixin/HasAttributes.pm, avg 9µs/call | ||||
40 | 132 | 349µs | my ( $class, $name, %options ) = @_; | ||
41 | |||||
42 | (defined $name) | ||||
43 | || confess "You must provide a name for the attribute"; | ||||
44 | |||||
45 | return bless { | ||||
46 | name => $name, | ||||
47 | original_options => \%options, | ||||
48 | %options, | ||||
49 | }, $class; | ||||
50 | } | ||||
51 | |||||
52 | # spent 361µs (287+74) within Moose::Meta::Role::Attribute::attach_to_role which was called 44 times, avg 8µs/call:
# 44 times (287µs+74µs) by Moose::Meta::Role::_attach_attribute at line 207 of Moose/Meta/Role.pm, avg 8µs/call | ||||
53 | 132 | 385µs | my ( $self, $role ) = @_; | ||
54 | |||||
55 | ( blessed($role) && $role->isa('Moose::Meta::Role') ) # spent 24µs making 44 calls to UNIVERSAL::isa, avg 545ns/call
# spent 20µs making 44 calls to Scalar::Util::blessed, avg 466ns/call | ||||
56 | || confess | ||||
57 | "You must pass a Moose::Meta::Role instance (or a subclass)"; | ||||
58 | |||||
59 | weaken( $self->{'associated_role'} = $role ); # spent 29µs making 44 calls to Scalar::Util::weaken, avg 668ns/call | ||||
60 | } | ||||
61 | |||||
62 | # spent 14.6ms (349µs+14.2) within Moose::Meta::Role::Attribute::attribute_for_class which was called 37 times, avg 394µs/call:
# 37 times (349µs+14.2ms) by Moose::Meta::Role::Application::ToClass::apply_attributes at line 142 of Moose/Meta/Role/Application/ToClass.pm, avg 394µs/call | ||||
63 | 111 | 351µs | my $self = shift; | ||
64 | my $metaclass = shift; | ||||
65 | |||||
66 | return $metaclass->interpolate_class_and_new( | ||||
67 | $self->name => %{ $self->original_options } ); # spent 14.1ms making 37 calls to Moose::Meta::Attribute::interpolate_class_and_new, avg 381µs/call
# spent 74µs making 37 calls to Moose::Meta::Role::Attribute::original_options, avg 2µs/call
# spent 34µs making 37 calls to Class::MOP::Mixin::AttributeCore::name, avg 927ns/call | ||||
68 | } | ||||
69 | |||||
70 | # spent 495µs (229+266) within Moose::Meta::Role::Attribute::clone which was called 30 times, avg 16µs/call:
# 30 times (229µs+266µs) by Moose::Meta::Role::Application::ToRole::apply_attributes at line 65 of Moose/Meta/Role/Application/ToRole.pm, avg 16µs/call | ||||
71 | 60 | 216µs | my $self = shift; | ||
72 | |||||
73 | return ( ref $self )->new( $self->name, %{ $self->original_options } ); # spent 196µs making 30 calls to Moose::Meta::Role::Attribute::new, avg 7µs/call
# spent 48µs making 30 calls to Moose::Meta::Role::Attribute::original_options, avg 2µs/call
# spent 22µs making 30 calls to Class::MOP::Mixin::AttributeCore::name, avg 727ns/call | ||||
74 | } | ||||
75 | |||||
76 | sub is_same_as { | ||||
77 | my $self = shift; | ||||
78 | my $attr = shift; | ||||
79 | |||||
80 | my $self_options = $self->original_options; | ||||
81 | my $other_options = $attr->original_options; | ||||
82 | |||||
83 | return 0 | ||||
84 | unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); | ||||
85 | |||||
86 | for my $key ( keys %{$self_options} ) { | ||||
87 | return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; | ||||
88 | return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; | ||||
89 | |||||
90 | next if all { ! defined } $self_options->{$key}, $other_options->{$key}; | ||||
91 | |||||
92 | return 0 unless $self_options->{$key} eq $other_options->{$key}; | ||||
93 | } | ||||
94 | |||||
95 | return 1; | ||||
96 | } | ||||
97 | |||||
98 | 1 | 12µs | 1; | ||
99 | |||||
100 | =pod | ||||
101 | |||||
102 | =head1 NAME | ||||
103 | |||||
104 | Moose::Meta::Role::Attribute - A Moose Attribute metaclass for Roles | ||||
105 | |||||
106 | =head1 DESCRIPTION | ||||
107 | |||||
108 | This class implements the API for attributes in roles. Attributes in roles are | ||||
109 | more like attribute prototypes than full blown attributes. While they are | ||||
110 | introspectable, they have very little behavior. | ||||
111 | |||||
112 | =head1 METHODS | ||||
113 | |||||
114 | This class provides the following methods: | ||||
115 | |||||
116 | =over 4 | ||||
117 | |||||
118 | =item B<< Moose::Meta::Role::Attribute->new(...) >> | ||||
119 | |||||
120 | This method accepts all the options that would be passed to the constructor | ||||
121 | for L<Moose::Meta::Attribute>. | ||||
122 | |||||
123 | =item B<< $attr->metaclass >> | ||||
124 | |||||
125 | =item B<< $attr->is >> | ||||
126 | |||||
127 | Returns the option as passed to the constructor. | ||||
128 | |||||
129 | =item B<< $attr->associated_role >> | ||||
130 | |||||
131 | Returns the L<Moose::Meta::Role> to which this attribute belongs, if any. | ||||
132 | |||||
133 | =item B<< $attr->original_options >> | ||||
134 | |||||
135 | Returns a hash reference of options passed to the constructor. This is used | ||||
136 | when creating a L<Moose::Meta::Attribute> object from this object. | ||||
137 | |||||
138 | =item B<< $attr->attach_to_role($role) >> | ||||
139 | |||||
140 | Attaches the attribute to the given L<Moose::Meta::Role>. | ||||
141 | |||||
142 | =item B<< $attr->attribute_for_class($metaclass) >> | ||||
143 | |||||
144 | Given an attribute metaclass name, this method calls C<< | ||||
145 | $metaclass->interpolate_class_and_new >> to construct an attribute object | ||||
146 | which can be added to a L<Moose::Meta::Class>. | ||||
147 | |||||
148 | =item B<< $attr->clone >> | ||||
149 | |||||
150 | Creates a new object identical to the object on which the method is called. | ||||
151 | |||||
152 | =item B<< $attr->is_same_as($other_attr) >> | ||||
153 | |||||
154 | Compares two role attributes and returns true if they are identical. | ||||
155 | |||||
156 | =back | ||||
157 | |||||
158 | In addition, this class implements all informational predicates implements by | ||||
159 | L<Moose::Meta::Attribute> (and L<Class::MOP::Attribute>). | ||||
160 | |||||
161 | =head1 BUGS | ||||
162 | |||||
163 | See L<Moose/BUGS> for details on reporting bugs. | ||||
164 | |||||
165 | =head1 AUTHOR | ||||
166 | |||||
167 | Dave Rolsky E<lt>autarch@urth.orgE<gt> | ||||
168 | |||||
169 | =head1 COPYRIGHT AND LICENSE | ||||
170 | |||||
171 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
172 | |||||
173 | L<http://www.iinteractive.com> | ||||
174 | |||||
175 | This library is free software; you can redistribute it and/or modify | ||||
176 | it under the same terms as Perl itself. | ||||
177 | |||||
178 | =cut |