Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Role.pm |
Statements | Executed 126 statements in 1.25ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 1 | 1 | 207µs | 5.88ms | init_meta | Moose::Role::
4 | 3 | 3 | 104µs | 1.42ms | has | Moose::Role::
4 | 3 | 3 | 35µs | 549µs | requires | Moose::Role::
1 | 1 | 1 | 22µs | 22µs | BEGIN@21 | Moose::Role::
1 | 1 | 1 | 12µs | 49µs | BEGIN@11 | Moose::Role::
1 | 1 | 1 | 11µs | 180µs | BEGIN@15 | Moose::Role::
1 | 1 | 1 | 10µs | 1.42ms | BEGIN@22 | Moose::Role::
1 | 1 | 1 | 10µs | 18µs | BEGIN@9 | Moose::Role::
1 | 1 | 1 | 10µs | 29µs | BEGIN@13 | Moose::Role::
1 | 1 | 1 | 9µs | 31µs | BEGIN@20 | Moose::Role::
1 | 1 | 1 | 9µs | 9µs | BEGIN@2 | Moose::Role::
1 | 1 | 1 | 8µs | 28µs | BEGIN@12 | Moose::Role::
1 | 1 | 1 | 6µs | 8µs | BEGIN@8 | Moose::Role::
1 | 1 | 1 | 3µs | 3µs | BEGIN@17 | Moose::Role::
1 | 1 | 1 | 3µs | 3µs | BEGIN@18 | Moose::Role::
0 | 0 | 0 | 0s | 0s | _add_method_modifier | Moose::Role::
0 | 0 | 0 | 0s | 0s | after | Moose::Role::
0 | 0 | 0 | 0s | 0s | around | Moose::Role::
0 | 0 | 0 | 0s | 0s | augment | Moose::Role::
0 | 0 | 0 | 0s | 0s | before | Moose::Role::
0 | 0 | 0 | 0s | 0s | excludes | Moose::Role::
0 | 0 | 0 | 0s | 0s | extends | Moose::Role::
0 | 0 | 0 | 0s | 0s | inner | Moose::Role::
0 | 0 | 0 | 0s | 0s | override | Moose::Role::
0 | 0 | 0 | 0s | 0s | super | Moose::Role::
0 | 0 | 0 | 0s | 0s | with | Moose::Role::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Role; | ||||
2 | # spent 9µs within Moose::Role::BEGIN@2 which was called:
# once (9µs+0s) by Any::Moose::_install_module at line 4 | ||||
3 | 1 | 4µs | $Moose::Role::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 21µs | 1 | 9µs | } # spent 9µs making 1 call to Moose::Role::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Role::VERSION = '2.0602'; | ||
7 | } | ||||
8 | 3 | 20µs | 2 | 10µs | # spent 8µs (6+2) within Moose::Role::BEGIN@8 which was called:
# once (6µs+2µs) by Any::Moose::_install_module at line 8 # spent 8µs making 1 call to Moose::Role::BEGIN@8
# spent 2µs making 1 call to strict::import |
9 | 3 | 18µs | 2 | 26µs | # spent 18µs (10+8) within Moose::Role::BEGIN@9 which was called:
# once (10µs+8µs) by Any::Moose::_install_module at line 9 # spent 18µs making 1 call to Moose::Role::BEGIN@9
# spent 8µs making 1 call to warnings::import |
10 | |||||
11 | 3 | 24µs | 2 | 87µs | # spent 49µs (12+38) within Moose::Role::BEGIN@11 which was called:
# once (12µs+38µs) by Any::Moose::_install_module at line 11 # spent 49µs making 1 call to Moose::Role::BEGIN@11
# spent 38µs making 1 call to Exporter::import |
12 | 3 | 19µs | 2 | 48µs | # spent 28µs (8+20) within Moose::Role::BEGIN@12 which was called:
# once (8µs+20µs) by Any::Moose::_install_module at line 12 # spent 28µs making 1 call to Moose::Role::BEGIN@12
# spent 20µs making 1 call to Exporter::import |
13 | 3 | 20µs | 2 | 49µs | # spent 29µs (10+20) within Moose::Role::BEGIN@13 which was called:
# once (10µs+20µs) by Any::Moose::_install_module at line 13 # spent 29µs making 1 call to Moose::Role::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
14 | |||||
15 | 3 | 23µs | 2 | 349µs | # spent 180µs (11+169) within Moose::Role::BEGIN@15 which was called:
# once (11µs+169µs) by Any::Moose::_install_module at line 15 # spent 180µs making 1 call to Moose::Role::BEGIN@15
# spent 169µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
16 | |||||
17 | 3 | 14µs | 1 | 3µs | # spent 3µs within Moose::Role::BEGIN@17 which was called:
# once (3µs+0s) by Any::Moose::_install_module at line 17 # spent 3µs making 1 call to Moose::Role::BEGIN@17 |
18 | 3 | 15µs | 1 | 3µs | # spent 3µs within Moose::Role::BEGIN@18 which was called:
# once (3µs+0s) by Any::Moose::_install_module at line 18 # spent 3µs making 1 call to Moose::Role::BEGIN@18 |
19 | |||||
20 | 3 | 21µs | 2 | 52µs | # spent 31µs (9+21) within Moose::Role::BEGIN@20 which was called:
# once (9µs+21µs) by Any::Moose::_install_module at line 20 # spent 31µs making 1 call to Moose::Role::BEGIN@20
# spent 21µs making 1 call to Moose::Exporter::import |
21 | 3 | 34µs | 1 | 22µs | # spent 22µs within Moose::Role::BEGIN@21 which was called:
# once (22µs+0s) by Any::Moose::_install_module at line 21 # spent 22µs making 1 call to Moose::Role::BEGIN@21 |
22 | 3 | 692µs | 2 | 2.84ms | # spent 1.42ms (10µs+1.41) within Moose::Role::BEGIN@22 which was called:
# once (10µs+1.41ms) by Any::Moose::_install_module at line 22 # spent 1.42ms making 1 call to Moose::Role::BEGIN@22
# spent 1.41ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:492] |
23 | |||||
24 | sub extends { | ||||
25 | croak "Roles do not support 'extends' (you can use 'with' to specialize a role)"; | ||||
26 | } | ||||
27 | |||||
28 | sub with { | ||||
29 | Moose::Util::apply_all_roles( shift, @_ ); | ||||
30 | } | ||||
31 | |||||
32 | # spent 549µs (35+514) within Moose::Role::requires which was called 4 times, avg 137µs/call:
# 2 times (14µs+238µs) by Moose::Role::requires at line 382 of Moose/Exporter.pm, avg 126µs/call
# once (12µs+206µs) by Module::Runtime::require_module at line 9 of lib/Tapper/MCP/Net/TAP.pm
# once (9µs+69µs) by main::BEGIN@1.15 at line 7 of lib/Tapper/MCP/Scheduler/Algorithm/WFQ.pm | ||||
33 | 6 | 16µs | my $meta = shift; | ||
34 | croak "Must specify at least one method" unless @_; | ||||
35 | 2 | 238µs | $meta->add_required_methods(@_); # spent 238µs making 2 calls to Moose::Meta::Role::add_required_methods, avg 119µs/call | ||
36 | } | ||||
37 | |||||
38 | sub excludes { | ||||
39 | my $meta = shift; | ||||
40 | croak "Must specify at least one role" unless @_; | ||||
41 | $meta->add_excluded_roles(@_); | ||||
42 | } | ||||
43 | |||||
44 | # spent 1.42ms (104µs+1.32) within Moose::Role::has which was called 4 times, avg 356µs/call:
# 2 times (72µs+597µs) by Moose::Role::has at line 382 of Moose/Exporter.pm, avg 334µs/call
# once (21µs+471µs) by Module::Runtime::require_module at line 14 of MooseX/Traits.pm
# once (12µs+251µs) by Module::Runtime::require_module at line 14 of MooseX/Log/Log4perl.pm | ||||
45 | 14 | 70µs | my $meta = shift; | ||
46 | my $name = shift; | ||||
47 | croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1; | ||||
48 | 2 | 39µs | my %options = ( definition_context => Moose::Util::_caller_info(), @_ ); # spent 39µs making 2 calls to Moose::Util::_caller_info, avg 19µs/call | ||
49 | my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; | ||||
50 | 2 | 558µs | $meta->add_attribute( $_, %options ) for @$attrs; # spent 558µs making 2 calls to Moose::Meta::Role::add_attribute, avg 279µs/call | ||
51 | } | ||||
52 | |||||
53 | sub _add_method_modifier { | ||||
54 | my $type = shift; | ||||
55 | my $meta = shift; | ||||
56 | |||||
57 | if ( ref($_[0]) eq 'Regexp' ) { | ||||
58 | croak "Roles do not currently support regex " | ||||
59 | . " references for $type method modifiers"; | ||||
60 | } | ||||
61 | |||||
62 | Moose::Util::add_method_modifier($meta, $type, \@_); | ||||
63 | } | ||||
64 | |||||
65 | sub before { _add_method_modifier('before', @_) } | ||||
66 | |||||
67 | sub after { _add_method_modifier('after', @_) } | ||||
68 | |||||
69 | sub around { _add_method_modifier('around', @_) } | ||||
70 | |||||
71 | # see Moose.pm for discussion | ||||
72 | sub super { | ||||
73 | return unless $Moose::SUPER_BODY; | ||||
74 | $Moose::SUPER_BODY->(@Moose::SUPER_ARGS); | ||||
75 | } | ||||
76 | |||||
77 | sub override { | ||||
78 | my $meta = shift; | ||||
79 | my ( $name, $code ) = @_; | ||||
80 | $meta->add_override_method_modifier( $name, $code ); | ||||
81 | } | ||||
82 | |||||
83 | sub inner { | ||||
84 | croak "Roles cannot support 'inner'"; | ||||
85 | } | ||||
86 | |||||
87 | sub augment { | ||||
88 | croak "Roles cannot support 'augment'"; | ||||
89 | } | ||||
90 | |||||
91 | 1 | 7µs | 1 | 922µs | Moose::Exporter->setup_import_methods( # spent 922µs making 1 call to Moose::Exporter::setup_import_methods |
92 | with_meta => [ | ||||
93 | qw( with requires excludes has before after around override ) | ||||
94 | ], | ||||
95 | as_is => [ | ||||
96 | qw( extends super inner augment ), | ||||
97 | \&Carp::confess, | ||||
98 | \&Scalar::Util::blessed, | ||||
99 | ], | ||||
100 | ); | ||||
101 | |||||
102 | # spent 5.88ms (207µs+5.67) within Moose::Role::init_meta which was called 4 times, avg 1.47ms/call:
# 4 times (207µs+5.67ms) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:492] at line 447 of Moose/Exporter.pm, avg 1.47ms/call | ||||
103 | 52 | 166µs | shift; | ||
104 | my %args = @_; | ||||
105 | |||||
106 | my $role = $args{for_class}; | ||||
107 | |||||
108 | unless ($role) { | ||||
109 | require Moose; | ||||
110 | Moose->throw_error("Cannot call init_meta without specifying a for_class"); | ||||
111 | } | ||||
112 | |||||
113 | my $metaclass = $args{metaclass} || "Moose::Meta::Role"; | ||||
114 | my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta'; | ||||
115 | |||||
116 | 4 | 18µs | Moose->throw_error("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)") # spent 18µs making 4 calls to Class::Load::XS::is_class_loaded, avg 4µs/call | ||
117 | unless is_class_loaded($metaclass); | ||||
118 | |||||
119 | 4 | 7µs | Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Role.") # spent 7µs making 4 calls to UNIVERSAL::isa, avg 2µs/call | ||
120 | unless $metaclass->isa('Moose::Meta::Role'); | ||||
121 | |||||
122 | # make a subtype for each Moose role | ||||
123 | 8 | 2.49ms | role_type $role unless find_type_constraint($role); # spent 2.39ms making 4 calls to Moose::Util::TypeConstraints::role_type, avg 597µs/call
# spent 100µs making 4 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 25µs/call | ||
124 | |||||
125 | my $meta; | ||||
126 | 4 | 15µs | 4 | 13µs | if ( $meta = Class::MOP::get_metaclass_by_name($role) ) { # spent 13µs making 4 calls to Class::MOP::get_metaclass_by_name, avg 3µs/call |
127 | unless ( $meta->isa("Moose::Meta::Role") ) { | ||||
128 | my $error_message = "$role already has a metaclass, but it does not inherit $metaclass ($meta)."; | ||||
129 | if ( $meta->isa('Moose::Meta::Class') ) { | ||||
130 | Moose->throw_error($error_message . ' You cannot make the same thing a role and a class. Remove either Moose or Moose::Role.'); | ||||
131 | } else { | ||||
132 | Moose->throw_error($error_message); | ||||
133 | } | ||||
134 | } | ||||
135 | } | ||||
136 | else { | ||||
137 | 4 | 718µs | $meta = $metaclass->initialize($role); # spent 718µs making 4 calls to Moose::Meta::Role::initialize, avg 180µs/call | ||
138 | } | ||||
139 | |||||
140 | 12 | 43µs | if (defined $meta_name) { | ||
141 | # also check for inherited non moose 'meta' method? | ||||
142 | 4 | 352µs | my $existing = $meta->get_method($meta_name); # spent 352µs making 4 calls to Class::MOP::Mixin::HasMethods::get_method, avg 88µs/call | ||
143 | if ($existing && !$existing->isa('Class::MOP::Method::Meta')) { | ||||
144 | Carp::cluck "Moose::Role is overwriting an existing method named " | ||||
145 | . "$meta_name in role $role with a method " | ||||
146 | . "which returns the class's metaclass. If this is " | ||||
147 | . "actually what you want, you should remove the " | ||||
148 | . "existing method, otherwise, you should rename or " | ||||
149 | . "disable this generated method using the " | ||||
150 | . "'-meta_name' option to 'use Moose::Role'."; | ||||
151 | } | ||||
152 | 4 | 2.07ms | $meta->_add_meta_method($meta_name); # spent 2.07ms making 4 calls to Class::MOP::Mixin::HasMethods::_add_meta_method, avg 518µs/call | ||
153 | } | ||||
154 | |||||
155 | return $meta; | ||||
156 | } | ||||
157 | |||||
158 | 1 | 8µs | 1; | ||
159 | |||||
160 | # ABSTRACT: The Moose Role | ||||
161 | |||||
- - | |||||
164 | =pod | ||||
165 | |||||
166 | =head1 NAME | ||||
167 | |||||
168 | Moose::Role - The Moose Role | ||||
169 | |||||
170 | =head1 VERSION | ||||
171 | |||||
172 | version 2.0602 | ||||
173 | |||||
174 | =head1 SYNOPSIS | ||||
175 | |||||
176 | package Eq; | ||||
177 | use Moose::Role; # automatically turns on strict and warnings | ||||
178 | |||||
179 | requires 'equal'; | ||||
180 | |||||
181 | sub no_equal { | ||||
182 | my ($self, $other) = @_; | ||||
183 | !$self->equal($other); | ||||
184 | } | ||||
185 | |||||
186 | # ... then in your classes | ||||
187 | |||||
188 | package Currency; | ||||
189 | use Moose; # automatically turns on strict and warnings | ||||
190 | |||||
191 | with 'Eq'; | ||||
192 | |||||
193 | sub equal { | ||||
194 | my ($self, $other) = @_; | ||||
195 | $self->as_float == $other->as_float; | ||||
196 | } | ||||
197 | |||||
198 | # ... and also | ||||
199 | |||||
200 | package Comparator; | ||||
201 | use Moose; | ||||
202 | |||||
203 | has compare_to => ( | ||||
204 | is => 'ro', | ||||
205 | does => 'Eq', | ||||
206 | handles => 'Eq', | ||||
207 | ); | ||||
208 | |||||
209 | # ... which allows | ||||
210 | |||||
211 | my $currency1 = Currency->new(...); | ||||
212 | my $currency2 = Currency->new(...); | ||||
213 | Comparator->new(compare_to => $currency1)->equal($currency2); | ||||
214 | |||||
215 | =head1 DESCRIPTION | ||||
216 | |||||
217 | The concept of roles is documented in L<Moose::Manual::Roles>. This document | ||||
218 | serves as API documentation. | ||||
219 | |||||
220 | =head1 EXPORTED FUNCTIONS | ||||
221 | |||||
222 | Moose::Role currently supports all of the functions that L<Moose> exports, but | ||||
223 | differs slightly in how some items are handled (see L</CAVEATS> below for | ||||
224 | details). | ||||
225 | |||||
226 | Moose::Role also offers two role-specific keyword exports: | ||||
227 | |||||
228 | =over 4 | ||||
229 | |||||
230 | =item B<requires (@method_names)> | ||||
231 | |||||
232 | Roles can require that certain methods are implemented by any class which | ||||
233 | C<does> the role. | ||||
234 | |||||
235 | Note that attribute accessors also count as methods for the purposes | ||||
236 | of satisfying the requirements of a role. | ||||
237 | |||||
238 | =item B<excludes (@role_names)> | ||||
239 | |||||
240 | Roles can C<exclude> other roles, in effect saying "I can never be combined | ||||
241 | with these C<@role_names>". This is a feature which should not be used | ||||
242 | lightly. | ||||
243 | |||||
244 | =back | ||||
245 | |||||
246 | =head2 B<unimport> | ||||
247 | |||||
248 | Moose::Role offers a way to remove the keywords it exports, through the | ||||
249 | C<unimport> method. You simply have to say C<no Moose::Role> at the bottom of | ||||
250 | your code for this to work. | ||||
251 | |||||
252 | =head1 METACLASS | ||||
253 | |||||
254 | When you use Moose::Role, you can specify traits which will be applied to your | ||||
255 | role metaclass: | ||||
256 | |||||
257 | use Moose::Role -traits => 'My::Trait'; | ||||
258 | |||||
259 | This is very similar to the attribute traits feature. When you do | ||||
260 | this, your class's C<meta> object will have the specified traits | ||||
261 | applied to it. See L<Moose/Metaclass and Trait Name Resolution> for more | ||||
262 | details. | ||||
263 | |||||
264 | =head1 APPLYING ROLES | ||||
265 | |||||
266 | In addition to being applied to a class using the 'with' syntax (see | ||||
267 | L<Moose::Manual::Roles>) and using the L<Moose::Util> 'apply_all_roles' | ||||
268 | method, roles may also be applied to an instance of a class using | ||||
269 | L<Moose::Util> 'apply_all_roles' or the role's metaclass: | ||||
270 | |||||
271 | MyApp::Test::SomeRole->meta->apply( $instance ); | ||||
272 | |||||
273 | Doing this creates a new, mutable, anonymous subclass, applies the role to that, | ||||
274 | and reblesses. In a debugger, for example, you will see class names of the | ||||
275 | form C< Moose::Meta::Class::__ANON__::SERIAL::6 >, which means that doing a | ||||
276 | 'ref' on your instance may not return what you expect. See L<Moose::Object> for | ||||
277 | 'DOES'. | ||||
278 | |||||
279 | Additional params may be added to the new instance by providing | ||||
280 | 'rebless_params'. See L<Moose::Meta::Role::Application::ToInstance>. | ||||
281 | |||||
282 | =head1 CAVEATS | ||||
283 | |||||
284 | Role support has only a few caveats: | ||||
285 | |||||
286 | =over 4 | ||||
287 | |||||
288 | =item * | ||||
289 | |||||
290 | Roles cannot use the C<extends> keyword; it will throw an exception for now. | ||||
291 | The same is true of the C<augment> and C<inner> keywords (not sure those | ||||
292 | really make sense for roles). All other Moose keywords will be I<deferred> | ||||
293 | so that they can be applied to the consuming class. | ||||
294 | |||||
295 | =item * | ||||
296 | |||||
297 | Role composition does its best to B<not> be order-sensitive when it comes to | ||||
298 | conflict resolution and requirements detection. However, it is order-sensitive | ||||
299 | when it comes to method modifiers. All before/around/after modifiers are | ||||
300 | included whenever a role is composed into a class, and then applied in the order | ||||
301 | in which the roles are used. This also means that there is no conflict for | ||||
302 | before/around/after modifiers. | ||||
303 | |||||
304 | In most cases, this will be a non-issue; however, it is something to keep in | ||||
305 | mind when using method modifiers in a role. You should never assume any | ||||
306 | ordering. | ||||
307 | |||||
308 | =back | ||||
309 | |||||
310 | =head1 BUGS | ||||
311 | |||||
312 | See L<Moose/BUGS> for details on reporting bugs. | ||||
313 | |||||
314 | =head1 AUTHOR | ||||
315 | |||||
316 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
317 | |||||
318 | =head1 COPYRIGHT AND LICENSE | ||||
319 | |||||
320 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
321 | |||||
322 | This is free software; you can redistribute it and/or modify it under | ||||
323 | the same terms as the Perl 5 programming language system itself. | ||||
324 | |||||
325 | =cut | ||||
326 | |||||
327 | |||||
328 | __END__ |