← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 05.Domain_and_Item.t
  Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:22:56 2010

File /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Role.pm
Statements Executed 548
Statement Execution Time 1.86ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2211553µs6.86msMoose::Role::::init_metaMoose::Role::init_meta
281512312µs3.05msMoose::Role::::hasMoose::Role::has
261414134µs88.0msMoose::Role::::withMoose::Role::with
1931117µs389µsMoose::Role::::_add_method_modifierMoose::Role::_add_method_modifier
2011271µs524µsMoose::Role::::aroundMoose::Role::around
106648µs353µsMoose::Role::::beforeMoose::Role::before
85438µs234µsMoose::Role::::afterMoose::Role::after
43334µs471µsMoose::Role::::requiresMoose::Role::requires
11114µs17µsMoose::Role::::BEGIN@2Moose::Role::BEGIN@2
1118µs57µsMoose::Role::::BEGIN@5Moose::Role::BEGIN@5
1118µs106µsMoose::Role::::BEGIN@8Moose::Role::BEGIN@8
1118µs1.18msMoose::Role::::BEGIN@19Moose::Role::BEGIN@19
1118µs32µsMoose::Role::::BEGIN@6Moose::Role::BEGIN@6
1117µs18µsMoose::Role::::BEGIN@3Moose::Role::BEGIN@3
1116µs26µsMoose::Role::::BEGIN@17Moose::Role::BEGIN@17
1115µs5µsMoose::Role::::BEGIN@18Moose::Role::BEGIN@18
1114µs4µsMoose::Role::::BEGIN@14Moose::Role::BEGIN@14
1113µs3µsMoose::Role::::BEGIN@15Moose::Role::BEGIN@15
0000s0sMoose::Role::::__ANON__[:135]Moose::Role::__ANON__[:135]
0000s0sMoose::Role::::augmentMoose::Role::augment
0000s0sMoose::Role::::excludesMoose::Role::excludes
0000s0sMoose::Role::::extendsMoose::Role::extends
0000s0sMoose::Role::::innerMoose::Role::inner
0000s0sMoose::Role::::overrideMoose::Role::override
0000s0sMoose::Role::::superMoose::Role::super
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moose::Role;
2326µs220µs
# spent 17µs (14+3) within Moose::Role::BEGIN@2 which was called # once (14µs+3µs) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 2
use strict;
# spent 17µs making 1 call to Moose::Role::BEGIN@2 # spent 3µs making 1 call to strict::import
3321µs229µs
# spent 18µs (7+11) within Moose::Role::BEGIN@3 which was called # once (7µs+11µs) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 3
use warnings;
# spent 18µs making 1 call to Moose::Role::BEGIN@3 # spent 11µs making 1 call to warnings::import
4
5325µs2105µs
# spent 57µs (8+48) within Moose::Role::BEGIN@5 which was called # once (8µs+48µs) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 5
use Scalar::Util 'blessed';
# spent 57µs making 1 call to Moose::Role::BEGIN@5 # spent 48µs making 1 call to Exporter::import
6321µs256µs
# spent 32µs (8+24) within Moose::Role::BEGIN@6 which was called # once (8µs+24µs) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 6
use Carp 'croak';
# spent 32µs making 1 call to Moose::Role::BEGIN@6 # spent 24µs making 1 call to Exporter::import
7
8345µs2204µs
# spent 106µs (8+98) within Moose::Role::BEGIN@8 which was called # once (8µs+98µs) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 8
use Sub::Exporter;
# spent 106µs making 1 call to Moose::Role::BEGIN@8 # spent 98µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
9
101700nsour $VERSION = '0.98';
11114µs$VERSION = eval $VERSION;
121300nsour $AUTHORITY = 'cpan:STEVAN';
13
14316µs14µs
# spent 4µs within Moose::Role::BEGIN@14 which was called # once (4µs+0s) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 14
use Moose ();
# spent 4µs making 1 call to Moose::Role::BEGIN@14
15322µs13µs
# spent 3µs within Moose::Role::BEGIN@15 which was called # once (3µs+0s) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 15
use Moose::Util ();
# spent 3µs making 1 call to Moose::Role::BEGIN@15
16
17320µs245µs
# spent 26µs (6+20) within Moose::Role::BEGIN@17 which was called # once (6µs+20µs) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 17
use Moose::Exporter;
# spent 26µs making 1 call to Moose::Role::BEGIN@17 # spent 20µs making 1 call to Moose::Exporter::import
18319µs15µs
# spent 5µs within Moose::Role::BEGIN@18 which was called # once (5µs+0s) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 18
use Moose::Meta::Role;
# spent 5µs making 1 call to Moose::Role::BEGIN@18
193665µs22.36ms
# spent 1.18ms (8µs+1.18) within Moose::Role::BEGIN@19 which was called # once (8µs+1.18ms) by MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 at line 19
use Moose::Util::TypeConstraints;
# spent 1.18ms making 1 call to Moose::Role::BEGIN@19 # spent 1.18ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389]
20
21sub extends {
22 croak "Roles do not support 'extends' (you can use 'with' to specialize a role)";
23}
24
25
# spent 88.0ms (134µs+87.8) within Moose::Role::with which was called 26 times, avg 3.38ms/call: # 13 times (42µs+42.7ms) by Moose::Role::with at line 293 of Moose/Exporter.pm, avg 3.29ms/call # once (13µs+7.42ms) by MooseX::AttributeHelpers::BEGIN@13 at line 9 of MooseX/AttributeHelpers/Trait/Bool.pm # once (6µs+6.02ms) by MooseX::AttributeHelpers::Trait::Collection::Hash::BEGIN@9 at line 8 of MooseX/AttributeHelpers/MethodProvider/Hash.pm # once (6µs+5.96ms) by MooseX::AttributeHelpers::BEGIN@17 at line 11 of MooseX/AttributeHelpers/Trait/Collection/List.pm # once (7µs+4.87ms) by MooseX::AttributeHelpers::Trait::Collection::Array::BEGIN@9 at line 8 of MooseX/AttributeHelpers/MethodProvider/Array.pm # once (6µs+3.58ms) by MooseX::AttributeHelpers::Trait::Collection::Bag::BEGIN@10 at line 8 of MooseX/AttributeHelpers/MethodProvider/Bag.pm # once (8µs+2.45ms) by MooseX::AttributeHelpers::BEGIN@14 at line 11 of MooseX/AttributeHelpers/Trait/Counter.pm # once (7µs+2.39ms) by MooseX::AttributeHelpers::BEGIN@15 at line 8 of MooseX/AttributeHelpers/Trait/Number.pm # once (7µs+2.18ms) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 9 of MooseX/AttributeHelpers/Trait/Collection.pm # once (7µs+2.11ms) by MooseX::AttributeHelpers::BEGIN@20 at line 11 of MooseX/AttributeHelpers/Trait/Collection/ImmutableHash.pm # once (6µs+2.11ms) by MooseX::AttributeHelpers::BEGIN@16 at line 11 of MooseX/AttributeHelpers/Trait/String.pm # once (6µs+2.04ms) by MooseX::AttributeHelpers::BEGIN@21 at line 12 of MooseX/AttributeHelpers/Trait/Collection/Bag.pm # once (6µs+1.97ms) by MooseX::AttributeHelpers::BEGIN@18 at line 11 of MooseX/AttributeHelpers/Trait/Collection/Array.pm # once (6µs+1.96ms) by MooseX::AttributeHelpers::BEGIN@19 at line 11 of MooseX/AttributeHelpers/Trait/Collection/Hash.pm
sub with {
261344µs1342.7ms Moose::Util::apply_all_roles( shift, @_ );
# spent 44.9ms making 13 calls to Moose::Util::apply_all_roles, avg 3.45ms/call, recursion: max depth 1, time 2.16ms
27}
28
29
# spent 471µs (34+437) within Moose::Role::requires which was called 4 times, avg 118µs/call: # 2 times (14µs+199µs) by Moose::Role::requires at line 293 of Moose/Exporter.pm, avg 106µs/call # once (13µs+131µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 6 of ../lib/SimpleDB/Class/Role/Itemized.pm # once (8µs+107µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 10 of MooseX/AttributeHelpers/Trait/Base.pm
sub requires {
302900ns my $meta = shift;
312800ns croak "Must specify at least one method" unless @_;
32211µs2199µs $meta->add_required_methods(@_);
# spent 199µs making 2 calls to Moose::Meta::Role::add_required_methods, avg 100µs/call
33}
34
35sub excludes {
36 my $meta = shift;
37 croak "Must specify at least one role" unless @_;
38 $meta->add_excluded_roles(@_);
39}
40
41
# spent 3.05ms (312µs+2.74) within Moose::Role::has which was called 28 times, avg 109µs/call: # 14 times (219µs+1.21ms) by Moose::Role::has at line 293 of Moose/Exporter.pm, avg 102µs/call # once (9µs+184µs) by MooseX::ClassAttribute::BEGIN@11 at line 24 of MooseX/ClassAttribute/Role/Meta/Class.pm # once (7µs+186µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 17 of MooseX/AttributeHelpers/Trait/Base.pm # once (6µs+121µs) by MooseX::AttributeHelpers::BEGIN@15 at line 54 of MooseX/AttributeHelpers/Trait/Number.pm # once (8µs+113µs) by MooseX::AttributeHelpers::BEGIN@14 at line 13 of MooseX/AttributeHelpers/Trait/Counter.pm # once (7µs+105µs) by MooseX::AttributeHelpers::BEGIN@20 at line 13 of MooseX/AttributeHelpers/Trait/Collection/ImmutableHash.pm # once (6µs+102µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 52 of MooseX/AttributeHelpers/Trait/Base.pm # once (6µs+97µs) by MooseX::ClassAttribute::BEGIN@11 at line 38 of MooseX/ClassAttribute/Role/Meta/Class.pm # once (7µs+95µs) by MooseX::AttributeHelpers::BEGIN@13 at line 19 of MooseX/AttributeHelpers/Trait/Bool.pm # once (7µs+91µs) by MooseX::AttributeHelpers::BEGIN@18 at line 13 of MooseX/AttributeHelpers/Trait/Collection/Array.pm # once (6µs+90µs) by MooseX::AttributeHelpers::BEGIN@17 at line 13 of MooseX/AttributeHelpers/Trait/Collection/List.pm # once (6µs+88µs) by MooseX::AttributeHelpers::BEGIN@19 at line 13 of MooseX/AttributeHelpers/Trait/Collection/Hash.pm # once (6µs+87µs) by MooseX::AttributeHelpers::BEGIN@16 at line 13 of MooseX/AttributeHelpers/Trait/String.pm # once (5µs+88µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 23 of MooseX/AttributeHelpers/Trait/Base.pm # once (6µs+86µs) by MooseX::AttributeHelpers::BEGIN@21 at line 14 of MooseX/AttributeHelpers/Trait/Collection/Bag.pm
sub has {
42144µs my $meta = shift;
43146µs my $name = shift;
44146µs croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1;
451454µs14118µs my %options = ( definition_context => Moose::Util::_caller_info(), @_ );
# spent 118µs making 14 calls to Moose::Util::_caller_info, avg 8µs/call
461413µs my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
4728102µs141.09ms $meta->add_attribute( $_, %options ) for @$attrs;
# spent 1.09ms making 14 calls to Moose::Meta::Role::add_attribute, avg 78µs/call
48}
49
50
# spent 389µs (117+272) within Moose::Role::_add_method_modifier which was called 19 times, avg 20µs/call: # 10 times (53µs+131µs) by Moose::Role::around at line 69, avg 18µs/call # 5 times (42µs+85µs) by Moose::Role::before at line 65, avg 25µs/call # 4 times (22µs+57µs) by Moose::Role::after at line 67, avg 20µs/call
sub _add_method_modifier {
51196µs my $type = shift;
52193µs my $meta = shift;
53193µs my $code = pop @_;
54
551937µs for (@_) {
56192µs croak "Roles do not currently support "
57 . ref($_)
58 . " references for $type method modifiers"
59 if ref $_;
60199µs my $add_method = "add_${type}_method_modifier";
611934µs19272µs $meta->$add_method( $_, $code );
# spent 131µs making 10 calls to Moose::Meta::Role::add_around_method_modifier, avg 13µs/call # spent 85µs making 5 calls to Moose::Meta::Role::add_before_method_modifier, avg 17µs/call # spent 57µs making 4 calls to Moose::Meta::Role::add_after_method_modifier, avg 14µs/call
62 }
63}
64
65515µs5126µs
# spent 353µs (48+305) within Moose::Role::before which was called 10 times, avg 35µs/call: # 5 times (17µs+126µs) by Moose::Role::before at line 293 of Moose/Exporter.pm, avg 29µs/call # once (7µs+46µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 77 of MooseX/AttributeHelpers/Trait/Base.pm # once (6µs+42µs) by MooseX::AttributeHelpers::BEGIN@21 at line 34 of MooseX/AttributeHelpers/Trait/Collection/Bag.pm # once (7µs+34µs) by MooseX::AttributeHelpers::BEGIN@14 at line 32 of MooseX/AttributeHelpers/Trait/Counter.pm # once (5µs+29µs) by MooseX::AttributeHelpers::BEGIN@16 at line 32 of MooseX/AttributeHelpers/Trait/String.pm # once (5µs+28µs) by MooseX::AttributeHelpers::BEGIN@13 at line 33 of MooseX/AttributeHelpers/Trait/Bool.pm
sub before { _add_method_modifier('before', @_) }
# spent 126µs making 5 calls to Moose::Role::_add_method_modifier, avg 25µs/call
66
67411µs479µs
# spent 234µs (38+196) within Moose::Role::after which was called 8 times, avg 29µs/call: # 4 times (12µs+79µs) by Moose::Role::after at line 293 of Moose/Exporter.pm, avg 23µs/call # once (10µs+35µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 194 of MooseX/AttributeHelpers/Trait/Base.pm # once (7µs+30µs) by MooseX::AttributeHelpers::BEGIN@14 at line 46 of MooseX/AttributeHelpers/Trait/Counter.pm # once (5µs+26µs) by MooseX::AttributeHelpers::BEGIN@16 at line 46 of MooseX/AttributeHelpers/Trait/String.pm # once (4µs+26µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 217 of MooseX/AttributeHelpers/Trait/Base.pm
sub after { _add_method_modifier('after', @_) }
# spent 79µs making 4 calls to Moose::Role::_add_method_modifier, avg 20µs/call
68
691021µs10184µs
# spent 524µs (71+454) within Moose::Role::around which was called 20 times, avg 26µs/call: # 10 times (25µs+184µs) by Moose::Role::around at line 293 of Moose/Exporter.pm, avg 21µs/call # once (8µs+48µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 18 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+25µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 31 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+25µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 120 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+25µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 54 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+25µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 43 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+25µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 102 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+24µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 136 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+24µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 128 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+24µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 84 of MooseX/ClassAttribute/Role/Meta/Attribute.pm # once (4µs+24µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@7 at line 112 of MooseX/ClassAttribute/Role/Meta/Attribute.pm
sub around { _add_method_modifier('around', @_) }
# spent 184µs making 10 calls to Moose::Role::_add_method_modifier, avg 18µs/call
70
71# see Moose.pm for discussion
72sub super {
73 return unless $Moose::SUPER_BODY;
74 $Moose::SUPER_BODY->(@Moose::SUPER_ARGS);
75}
76
77sub override {
78 my $meta = shift;
79 my ( $name, $code ) = @_;
80 $meta->add_override_method_modifier( $name, $code );
81}
82
83sub inner {
84 croak "Roles cannot support 'inner'";
85}
86
87sub augment {
88 croak "Roles cannot support 'augment'";
89}
90
9117µs1740µsMoose::Exporter->setup_import_methods(
# spent 740µ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 6.86ms (553µs+6.30) within Moose::Role::init_meta which was called 22 times, avg 312µs/call: # 22 times (553µs+6.30ms) by Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:389] at line 354 of Moose/Exporter.pm, avg 312µs/call
sub init_meta {
103225µs shift;
1042233µs my %args = @_;
105
106229µs my $role = $args{for_class};
107
108223µs unless ($role) {
109 require Moose;
110 Moose->throw_error("Cannot call init_meta without specifying a for_class");
111 }
112
1132212µs my $metaclass = $args{metaclass} || "Moose::Meta::Role";
114
115 # make a subtype for each Moose class
1162262µs443.25ms role_type $role unless find_type_constraint($role);
# spent 2.94ms making 22 calls to Moose::Util::TypeConstraints::role_type, avg 133µs/call # spent 310µs making 22 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 14µs/call
117
118 # FIXME copy from Moose.pm
119223µs my $meta;
12022229µs2250µs if ($role->can('meta')) {
# spent 50µs making 22 calls to UNIVERSAL::can, avg 2µs/call
121 $meta = $role->meta();
122
123 unless ( blessed($meta) && $meta->isa('Moose::Meta::Role') ) {
124 require Moose;
125 Moose->throw_error("You already have a &meta function, but it does not return a Moose::Meta::Role");
126 }
127 }
128 else {
1292249µs222.24ms $meta = $metaclass->initialize($role);
# spent 2.24ms making 22 calls to Moose::Meta::Role::initialize, avg 102µs/call
130
131 $meta->add_method(
132 'meta' => sub {
133 # re-initialize so it inherits properly
134211µs213µs $metaclass->initialize( ref($_[0]) || $_[0] );
# spent 13µs making 2 calls to Moose::Meta::Role::initialize, avg 6µs/call
135 }
1362277µs22766µs );
# spent 766µs making 22 calls to Class::MOP::Mixin::HasMethods::add_method, avg 35µs/call
137 }
138
1392259µs return $meta;
140}
141
142121µs1;
143
144__END__
145
146=pod
147
148=head1 NAME
149
150Moose::Role - The Moose Role
151
152=head1 SYNOPSIS
153
154 package Eq;
155 use Moose::Role; # automatically turns on strict and warnings
156
157 requires 'equal';
158
159 sub no_equal {
160 my ($self, $other) = @_;
161 !$self->equal($other);
162 }
163
164 # ... then in your classes
165
166 package Currency;
167 use Moose; # automatically turns on strict and warnings
168
169 with 'Eq';
170
171 sub equal {
172 my ($self, $other) = @_;
173 $self->as_float == $other->as_float;
174 }
175
176=head1 DESCRIPTION
177
178The concept of roles is documented in L<Moose::Manual::Roles>. This document
179serves as API documentation.
180
181=head1 EXPORTED FUNCTIONS
182
183Moose::Role currently supports all of the functions that L<Moose> exports, but
184differs slightly in how some items are handled (see L<CAVEATS> below for
185details).
186
187Moose::Role also offers two role-specific keyword exports:
188
189=over 4
190
191=item B<requires (@method_names)>
192
193Roles can require that certain methods are implemented by any class which
194C<does> the role.
195
196Note that attribute accessors also count as methods for the purposes
197of satisfying the requirements of a role.
198
199=item B<excludes (@role_names)>
200
201Roles can C<exclude> other roles, in effect saying "I can never be combined
202with these C<@role_names>". This is a feature which should not be used
203lightly.
204
205=back
206
207=head2 B<unimport>
208
209Moose::Role offers a way to remove the keywords it exports, through the
210C<unimport> method. You simply have to say C<no Moose::Role> at the bottom of
211your code for this to work.
212
213=head2 B<< Moose::Role->init_meta(for_class => $role, metaclass => $metaclass) >>
214
215The C<init_meta> method sets up the metaclass object for the role
216specified by C<for_class>. It also injects a a C<meta> accessor into
217the role so you can get at this object.
218
219The default metaclass is L<Moose::Meta::Role>. You can specify an
220alternate metaclass with the C<metaclass> parameter.
221
222=head1 METACLASS
223
224When you use Moose::Role, you can specify which metaclass to use:
225
226 use Moose::Role -metaclass => 'My::Meta::Role';
227
228You can also specify traits which will be applied to your role metaclass:
229
230 use Moose::Role -traits => 'My::Trait';
231
232This is very similar to the attribute traits feature. When you do
233this, your class's C<meta> object will have the specified traits
234applied to it. See L<Moose/Metaclass and Trait Name Resolution> for more
235details.
236
237=head1 APPLYING ROLES
238
239In addition to being applied to a class using the 'with' syntax (see
240L<Moose::Manual::Roles>) and using the L<Moose::Util> 'apply_all_roles'
241method, roles may also be applied to an instance of a class using
242L<Moose::Util> 'apply_all_roles' or the role's metaclass:
243
244 MyApp::Test::SomeRole->meta->apply( $instance );
245
246Doing this creates a new, mutable, anonymous subclass, applies the role to that,
247and reblesses. In a debugger, for example, you will see class names of the
248form C< Class::MOP::Class::__ANON__::SERIAL::6 >, which means that doing a 'ref'
249on your instance may not return what you expect. See L<Moose::Object> for 'DOES'.
250
251Additional params may be added to the new instance by providing 'rebless_params'.
252See L<Moose::Meta::Role::Application::ToInstance>.
253
254=head1 CAVEATS
255
256Role support has only a few caveats:
257
258=over 4
259
260=item *
261
262Roles cannot use the C<extends> keyword; it will throw an exception for now.
263The same is true of the C<augment> and C<inner> keywords (not sure those
264really make sense for roles). All other Moose keywords will be I<deferred>
265so that they can be applied to the consuming class.
266
267=item *
268
269Role composition does its best to B<not> be order-sensitive when it comes to
270conflict resolution and requirements detection. However, it is order-sensitive
271when it comes to method modifiers. All before/around/after modifiers are
272included whenever a role is composed into a class, and then applied in the order
273in which the roles are used. This also means that there is no conflict for
274before/around/after modifiers.
275
276In most cases, this will be a non-issue; however, it is something to keep in
277mind when using method modifiers in a role. You should never assume any
278ordering.
279
280=back
281
282=head1 BUGS
283
284See L<Moose/BUGS> for details on reporting bugs.
285
286=head1 AUTHOR
287
288Stevan Little E<lt>stevan@iinteractive.comE<gt>
289
290Christian Hansen E<lt>chansen@cpan.orgE<gt>
291
292=head1 COPYRIGHT AND LICENSE
293
294Copyright 2006-2010 by Infinity Interactive, Inc.
295
296L<http://www.iinteractive.com>
297
298This library is free software; you can redistribute it and/or modify
299it under the same terms as Perl itself.
300
301=cut