Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Role/Attribute.pm |
Statements | Executed 51 statements in 852µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 94µs | 94µs | new | Moose::Meta::Role::Attribute::
2 | 1 | 1 | 82µs | 2.72ms | attribute_for_class | Moose::Meta::Role::Attribute::
2 | 1 | 1 | 38µs | 49µs | attach_to_role | Moose::Meta::Role::Attribute::
2 | 1 | 1 | 26µs | 43µs | original_role | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 11µs | 25µs | BEGIN@10 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 9µs | 9µs | BEGIN@2 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 8µs | 131µs | BEGIN@16 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 7µs | 27µs | BEGIN@13 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 7µs | 11µs | BEGIN@9 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 6µs | 28µs | BEGIN@14 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 6µs | 26µs | BEGIN@12 | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:120] | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | clone | 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 | # spent 9µs within Moose::Meta::Role::Attribute::BEGIN@2 which was called:
# once (9µs+0s) by Moose::Meta::Role::BEGIN@19 at line 4 | ||||
3 | 1 | 4µs | $Moose::Meta::Role::Attribute::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 22µs | 1 | 9µs | } # spent 9µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::Role::Attribute::VERSION = '2.0602'; | ||
7 | } | ||||
8 | |||||
9 | 3 | 19µs | 2 | 15µs | # spent 11µs (7+4) within Moose::Meta::Role::Attribute::BEGIN@9 which was called:
# once (7µs+4µs) by Moose::Meta::Role::BEGIN@19 at line 9 # spent 11µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@9
# spent 4µs making 1 call to strict::import |
10 | 3 | 19µs | 2 | 39µs | # spent 25µs (11+14) within Moose::Meta::Role::Attribute::BEGIN@10 which was called:
# once (11µs+14µs) by Moose::Meta::Role::BEGIN@19 at line 10 # spent 25µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@10
# spent 14µs making 1 call to warnings::import |
11 | |||||
12 | 3 | 18µs | 2 | 47µs | # spent 26µs (6+21) within Moose::Meta::Role::Attribute::BEGIN@12 which was called:
# once (6µs+21µs) by Moose::Meta::Role::BEGIN@19 at line 12 # spent 26µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@12
# spent 21µs making 1 call to Exporter::import |
13 | 3 | 19µs | 2 | 46µs | # spent 27µs (7+20) within Moose::Meta::Role::Attribute::BEGIN@13 which was called:
# once (7µs+20µs) by Moose::Meta::Role::BEGIN@19 at line 13 # spent 27µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
14 | 3 | 22µs | 2 | 51µs | # spent 28µs (6+22) within Moose::Meta::Role::Attribute::BEGIN@14 which was called:
# once (6µs+22µs) by Moose::Meta::Role::BEGIN@19 at line 14 # spent 28µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@14
# spent 22µs making 1 call to Exporter::import |
15 | |||||
16 | 3 | 432µs | 2 | 253µs | # spent 131µs (8+123) within Moose::Meta::Role::Attribute::BEGIN@16 which was called:
# once (8µs+123µs) by Moose::Meta::Role::BEGIN@19 at line 16 # spent 131µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@16
# spent 123µs making 1 call to base::import |
17 | |||||
18 | 1 | 13µs | 3 | 1.03ms | __PACKAGE__->meta->add_attribute( # spent 569µs making 1 call to Class::MOP::Mixin::meta
# spent 451µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 9µs making 1 call to Class::MOP::_definition_context |
19 | 'metaclass' => ( | ||||
20 | reader => 'metaclass', | ||||
21 | Class::MOP::_definition_context(), | ||||
22 | ) | ||||
23 | ); | ||||
24 | |||||
25 | 1 | 4µs | 3 | 332µs | __PACKAGE__->meta->add_attribute( # spent 296µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 31µs making 1 call to Class::MOP::Mixin::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
26 | 'associated_role' => ( | ||||
27 | reader => 'associated_role', | ||||
28 | Class::MOP::_definition_context(), | ||||
29 | ) | ||||
30 | ); | ||||
31 | |||||
32 | 1 | 4µs | 3 | 279µs | __PACKAGE__->meta->add_attribute( # spent 264µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Class::MOP::Mixin::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
33 | '_original_role' => ( | ||||
34 | reader => '_original_role', | ||||
35 | Class::MOP::_definition_context(), | ||||
36 | ) | ||||
37 | ); | ||||
38 | |||||
39 | 1 | 4µs | 3 | 281µs | __PACKAGE__->meta->add_attribute( # spent 266µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Class::MOP::Mixin::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
40 | 'is' => ( | ||||
41 | reader => 'is', | ||||
42 | Class::MOP::_definition_context(), | ||||
43 | ) | ||||
44 | ); | ||||
45 | |||||
46 | 1 | 4µs | 3 | 280µs | __PACKAGE__->meta->add_attribute( # spent 266µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Class::MOP::Mixin::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
47 | 'original_options' => ( | ||||
48 | reader => 'original_options', | ||||
49 | Class::MOP::_definition_context(), | ||||
50 | ) | ||||
51 | ); | ||||
52 | |||||
53 | # spent 94µs within Moose::Meta::Role::Attribute::new which was called 2 times, avg 47µs/call:
# 2 times (94µs+0s) by Class::MOP::Mixin::HasAttributes::add_attribute at line 20 of Class/MOP/Mixin/HasAttributes.pm, avg 47µs/call | ||||
54 | 2 | 14µs | my ( $class, $name, %options ) = @_; | ||
55 | |||||
56 | 2 | 1µs | (defined $name) | ||
57 | || confess "You must provide a name for the attribute"; | ||||
58 | |||||
59 | 2 | 3µs | my $role = delete $options{_original_role}; | ||
60 | |||||
61 | 2 | 82µs | return bless { | ||
62 | name => $name, | ||||
63 | original_options => \%options, | ||||
64 | _original_role => $role, | ||||
65 | %options, | ||||
66 | }, $class; | ||||
67 | } | ||||
68 | |||||
69 | # spent 49µs (38+11) within Moose::Meta::Role::Attribute::attach_to_role which was called 2 times, avg 24µs/call:
# 2 times (38µs+11µs) by Moose::Meta::Role::_attach_attribute at line 259 of Moose/Meta/Role.pm, avg 24µs/call | ||||
70 | 2 | 2µs | my ( $self, $role ) = @_; | ||
71 | |||||
72 | 2 | 24µs | 4 | 6µs | ( blessed($role) && $role->isa('Moose::Meta::Role') ) # spent 4µs making 2 calls to Scalar::Util::blessed, avg 2µs/call
# spent 3µs making 2 calls to UNIVERSAL::isa, avg 1µs/call |
73 | || confess | ||||
74 | "You must pass a Moose::Meta::Role instance (or a subclass)"; | ||||
75 | |||||
76 | 2 | 27µs | 2 | 5µs | weaken( $self->{'associated_role'} = $role ); # spent 5µs making 2 calls to Scalar::Util::weaken, avg 2µs/call |
77 | } | ||||
78 | |||||
79 | # spent 43µs (26+17) within Moose::Meta::Role::Attribute::original_role which was called 2 times, avg 21µs/call:
# 2 times (26µs+17µs) by Moose::Meta::Role::Attribute::attribute_for_class at line 88, avg 21µs/call | ||||
80 | 2 | 1µs | my $self = shift; | ||
81 | |||||
82 | 2 | 35µs | 4 | 16µs | return $self->_original_role || $self->associated_role; # spent 9µs making 2 calls to Moose::Meta::Role::Attribute::_original_role, avg 4µs/call
# spent 8µs making 2 calls to Moose::Meta::Role::Attribute::associated_role, avg 4µs/call |
83 | } | ||||
84 | |||||
85 | # spent 2.72ms (82µs+2.64) within Moose::Meta::Role::Attribute::attribute_for_class which was called 2 times, avg 1.36ms/call:
# 2 times (82µs+2.64ms) by Moose::Meta::Role::Application::ToClass::apply_attributes at line 152 of Moose/Meta/Role/Application/ToClass.pm, avg 1.36ms/call | ||||
86 | 2 | 1µs | my $self = shift; | ||
87 | |||||
88 | 2 | 14µs | 4 | 52µs | my $metaclass = $self->original_role->applied_attribute_metaclass; # spent 43µs making 2 calls to Moose::Meta::Role::Attribute::original_role, avg 21µs/call
# spent 10µs making 2 calls to Moose::Meta::Role::applied_attribute_metaclass, avg 5µs/call |
89 | |||||
90 | return $metaclass->interpolate_class_and_new( | ||||
91 | 2 | 48µs | 6 | 2.58ms | $self->name => %{ $self->original_options } ); # spent 2.57ms making 2 calls to Moose::Meta::Attribute::interpolate_class_and_new, avg 1.29ms/call
# spent 8µs making 2 calls to Moose::Meta::Role::Attribute::original_options, avg 4µs/call
# spent 3µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 2µs/call |
92 | } | ||||
93 | |||||
94 | sub clone { | ||||
95 | my $self = shift; | ||||
96 | |||||
97 | my $role = $self->original_role; | ||||
98 | |||||
99 | return ( ref $self )->new( | ||||
100 | $self->name, | ||||
101 | %{ $self->original_options }, | ||||
102 | _original_role => $role, | ||||
103 | ); | ||||
104 | } | ||||
105 | |||||
106 | sub is_same_as { | ||||
107 | my $self = shift; | ||||
108 | my $attr = shift; | ||||
109 | |||||
110 | my $self_options = $self->original_options; | ||||
111 | my $other_options = $attr->original_options; | ||||
112 | |||||
113 | return 0 | ||||
114 | unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); | ||||
115 | |||||
116 | for my $key ( keys %{$self_options} ) { | ||||
117 | return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; | ||||
118 | return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; | ||||
119 | |||||
120 | next if all { ! defined } $self_options->{$key}, $other_options->{$key}; | ||||
121 | |||||
122 | return 0 unless $self_options->{$key} eq $other_options->{$key}; | ||||
123 | } | ||||
124 | |||||
125 | return 1; | ||||
126 | } | ||||
127 | |||||
128 | 1 | 13µs | 1; | ||
129 | |||||
130 | # ABSTRACT: The Moose attribute metaclass for Roles | ||||
131 | |||||
- - | |||||
134 | =pod | ||||
135 | |||||
136 | =head1 NAME | ||||
137 | |||||
138 | Moose::Meta::Role::Attribute - The Moose attribute metaclass for Roles | ||||
139 | |||||
140 | =head1 VERSION | ||||
141 | |||||
142 | version 2.0602 | ||||
143 | |||||
144 | =head1 DESCRIPTION | ||||
145 | |||||
146 | This class implements the API for attributes in roles. Attributes in roles are | ||||
147 | more like attribute prototypes than full blown attributes. While they are | ||||
148 | introspectable, they have very little behavior. | ||||
149 | |||||
150 | =head1 METHODS | ||||
151 | |||||
152 | This class provides the following methods: | ||||
153 | |||||
154 | =over 4 | ||||
155 | |||||
156 | =item B<< Moose::Meta::Role::Attribute->new(...) >> | ||||
157 | |||||
158 | This method accepts all the options that would be passed to the constructor | ||||
159 | for L<Moose::Meta::Attribute>. | ||||
160 | |||||
161 | =item B<< $attr->metaclass >> | ||||
162 | |||||
163 | =item B<< $attr->is >> | ||||
164 | |||||
165 | Returns the option as passed to the constructor. | ||||
166 | |||||
167 | =item B<< $attr->associated_role >> | ||||
168 | |||||
169 | Returns the L<Moose::Meta::Role> to which this attribute belongs, if any. | ||||
170 | |||||
171 | =item B<< $attr->original_role >> | ||||
172 | |||||
173 | Returns the L<Moose::Meta::Role> in which this attribute was first | ||||
174 | defined. This may not be the same as the value C<associated_role()> in the | ||||
175 | case of composite role, or the case where one role consumes other roles. | ||||
176 | |||||
177 | =item B<< $attr->original_options >> | ||||
178 | |||||
179 | Returns a hash reference of options passed to the constructor. This is used | ||||
180 | when creating a L<Moose::Meta::Attribute> object from this object. | ||||
181 | |||||
182 | =item B<< $attr->attach_to_role($role) >> | ||||
183 | |||||
184 | Attaches the attribute to the given L<Moose::Meta::Role>. | ||||
185 | |||||
186 | =item B<< $attr->attribute_for_class($metaclass) >> | ||||
187 | |||||
188 | Given an attribute metaclass name, this method calls C<< | ||||
189 | $metaclass->interpolate_class_and_new >> to construct an attribute object | ||||
190 | which can be added to a L<Moose::Meta::Class>. | ||||
191 | |||||
192 | =item B<< $attr->clone >> | ||||
193 | |||||
194 | Creates a new object identical to the object on which the method is called. | ||||
195 | |||||
196 | =item B<< $attr->is_same_as($other_attr) >> | ||||
197 | |||||
198 | Compares two role attributes and returns true if they are identical. | ||||
199 | |||||
200 | =back | ||||
201 | |||||
202 | In addition, this class implements all informational predicates implements by | ||||
203 | L<Moose::Meta::Attribute> (and L<Class::MOP::Attribute>). | ||||
204 | |||||
205 | =head1 BUGS | ||||
206 | |||||
207 | See L<Moose/BUGS> for details on reporting bugs. | ||||
208 | |||||
209 | =head1 AUTHOR | ||||
210 | |||||
211 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
212 | |||||
213 | =head1 COPYRIGHT AND LICENSE | ||||
214 | |||||
215 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
216 | |||||
217 | This is free software; you can redistribute it and/or modify it under | ||||
218 | the same terms as the Perl 5 programming language system itself. | ||||
219 | |||||
220 | =cut | ||||
221 | |||||
222 | |||||
223 | __END__ |