| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Role.pm |
| Statements Executed | 548 |
| Statement Execution Time | 1.86ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 22 | 1 | 1 | 553µs | 6.86ms | Moose::Role::init_meta |
| 28 | 15 | 12 | 312µs | 3.05ms | Moose::Role::has |
| 26 | 14 | 14 | 134µs | 88.0ms | Moose::Role::with |
| 19 | 3 | 1 | 117µs | 389µs | Moose::Role::_add_method_modifier |
| 20 | 11 | 2 | 71µs | 524µs | Moose::Role::around |
| 10 | 6 | 6 | 48µs | 353µs | Moose::Role::before |
| 8 | 5 | 4 | 38µs | 234µs | Moose::Role::after |
| 4 | 3 | 3 | 34µs | 471µs | Moose::Role::requires |
| 1 | 1 | 1 | 14µs | 17µs | Moose::Role::BEGIN@2 |
| 1 | 1 | 1 | 8µs | 57µs | Moose::Role::BEGIN@5 |
| 1 | 1 | 1 | 8µs | 106µs | Moose::Role::BEGIN@8 |
| 1 | 1 | 1 | 8µs | 1.18ms | Moose::Role::BEGIN@19 |
| 1 | 1 | 1 | 8µs | 32µs | Moose::Role::BEGIN@6 |
| 1 | 1 | 1 | 7µs | 18µs | Moose::Role::BEGIN@3 |
| 1 | 1 | 1 | 6µs | 26µs | Moose::Role::BEGIN@17 |
| 1 | 1 | 1 | 5µs | 5µs | Moose::Role::BEGIN@18 |
| 1 | 1 | 1 | 4µs | 4µs | Moose::Role::BEGIN@14 |
| 1 | 1 | 1 | 3µs | 3µs | Moose::Role::BEGIN@15 |
| 0 | 0 | 0 | 0s | 0s | Moose::Role::__ANON__[:135] |
| 0 | 0 | 0 | 0s | 0s | Moose::Role::augment |
| 0 | 0 | 0 | 0s | 0s | Moose::Role::excludes |
| 0 | 0 | 0 | 0s | 0s | Moose::Role::extends |
| 0 | 0 | 0 | 0s | 0s | Moose::Role::inner |
| 0 | 0 | 0 | 0s | 0s | Moose::Role::override |
| 0 | 0 | 0 | 0s | 0s | Moose::Role::super |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Role; | ||||
| 2 | 3 | 26µs | 2 | 20µ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 # spent 17µs making 1 call to Moose::Role::BEGIN@2
# spent 3µs making 1 call to strict::import |
| 3 | 3 | 21µs | 2 | 29µ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 # spent 18µs making 1 call to Moose::Role::BEGIN@3
# spent 11µs making 1 call to warnings::import |
| 4 | |||||
| 5 | 3 | 25µs | 2 | 105µ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 # spent 57µs making 1 call to Moose::Role::BEGIN@5
# spent 48µs making 1 call to Exporter::import |
| 6 | 3 | 21µs | 2 | 56µ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 # spent 32µs making 1 call to Moose::Role::BEGIN@6
# spent 24µs making 1 call to Exporter::import |
| 7 | |||||
| 8 | 3 | 45µs | 2 | 204µ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 # 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 | |||||
| 10 | 1 | 700ns | our $VERSION = '0.98'; | ||
| 11 | 1 | 14µs | $VERSION = eval $VERSION; | ||
| 12 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 16µs | 1 | 4µ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 # spent 4µs making 1 call to Moose::Role::BEGIN@14 |
| 15 | 3 | 22µs | 1 | 3µ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 # spent 3µs making 1 call to Moose::Role::BEGIN@15 |
| 16 | |||||
| 17 | 3 | 20µs | 2 | 45µ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 # spent 26µs making 1 call to Moose::Role::BEGIN@17
# spent 20µs making 1 call to Moose::Exporter::import |
| 18 | 3 | 19µs | 1 | 5µ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 # spent 5µs making 1 call to Moose::Role::BEGIN@18 |
| 19 | 3 | 665µs | 2 | 2.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 # 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 | |||||
| 21 | sub 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 | ||||
| 26 | 13 | 44µs | 13 | 42.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 | ||||
| 30 | 2 | 900ns | my $meta = shift; | ||
| 31 | 2 | 800ns | croak "Must specify at least one method" unless @_; | ||
| 32 | 2 | 11µs | 2 | 199µs | $meta->add_required_methods(@_); # spent 199µs making 2 calls to Moose::Meta::Role::add_required_methods, avg 100µs/call |
| 33 | } | ||||
| 34 | |||||
| 35 | sub 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 | ||||
| 42 | 14 | 4µs | my $meta = shift; | ||
| 43 | 14 | 6µs | my $name = shift; | ||
| 44 | 14 | 6µs | croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1; | ||
| 45 | 14 | 54µs | 14 | 118µs | my %options = ( definition_context => Moose::Util::_caller_info(), @_ ); # spent 118µs making 14 calls to Moose::Util::_caller_info, avg 8µs/call |
| 46 | 14 | 13µs | my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; | ||
| 47 | 28 | 102µs | 14 | 1.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 | ||||
| 51 | 19 | 6µs | my $type = shift; | ||
| 52 | 19 | 3µs | my $meta = shift; | ||
| 53 | 19 | 3µs | my $code = pop @_; | ||
| 54 | |||||
| 55 | 19 | 37µs | for (@_) { | ||
| 56 | 19 | 2µs | croak "Roles do not currently support " | ||
| 57 | . ref($_) | ||||
| 58 | . " references for $type method modifiers" | ||||
| 59 | if ref $_; | ||||
| 60 | 19 | 9µs | my $add_method = "add_${type}_method_modifier"; | ||
| 61 | 19 | 34µs | 19 | 272µ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 | |||||
| 65 | 5 | 15µs | 5 | 126µ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 # spent 126µs making 5 calls to Moose::Role::_add_method_modifier, avg 25µs/call |
| 66 | |||||
| 67 | 4 | 11µs | 4 | 79µ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 # spent 79µs making 4 calls to Moose::Role::_add_method_modifier, avg 20µs/call |
| 68 | |||||
| 69 | 10 | 21µs | 10 | 184µ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 # spent 184µs making 10 calls to Moose::Role::_add_method_modifier, avg 18µs/call |
| 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 | 740µs | Moose::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 | ||||
| 103 | 22 | 5µs | shift; | ||
| 104 | 22 | 33µs | my %args = @_; | ||
| 105 | |||||
| 106 | 22 | 9µs | my $role = $args{for_class}; | ||
| 107 | |||||
| 108 | 22 | 3µs | unless ($role) { | ||
| 109 | require Moose; | ||||
| 110 | Moose->throw_error("Cannot call init_meta without specifying a for_class"); | ||||
| 111 | } | ||||
| 112 | |||||
| 113 | 22 | 12µs | my $metaclass = $args{metaclass} || "Moose::Meta::Role"; | ||
| 114 | |||||
| 115 | # make a subtype for each Moose class | ||||
| 116 | 22 | 62µs | 44 | 3.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 | ||||
| 119 | 22 | 3µs | my $meta; | ||
| 120 | 22 | 229µs | 22 | 50µ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 { | ||||
| 129 | 22 | 49µs | 22 | 2.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 | ||||
| 134 | 2 | 11µs | 2 | 13µs | $metaclass->initialize( ref($_[0]) || $_[0] ); # spent 13µs making 2 calls to Moose::Meta::Role::initialize, avg 6µs/call |
| 135 | } | ||||
| 136 | 22 | 77µs | 22 | 766µs | ); # spent 766µs making 22 calls to Class::MOP::Mixin::HasMethods::add_method, avg 35µs/call |
| 137 | } | ||||
| 138 | |||||
| 139 | 22 | 59µs | return $meta; | ||
| 140 | } | ||||
| 141 | |||||
| 142 | 1 | 21µs | 1; | ||
| 143 | |||||
| 144 | __END__ | ||||
| 145 | |||||
| 146 | =pod | ||||
| 147 | |||||
| 148 | =head1 NAME | ||||
| 149 | |||||
| 150 | Moose::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 | |||||
| 178 | The concept of roles is documented in L<Moose::Manual::Roles>. This document | ||||
| 179 | serves as API documentation. | ||||
| 180 | |||||
| 181 | =head1 EXPORTED FUNCTIONS | ||||
| 182 | |||||
| 183 | Moose::Role currently supports all of the functions that L<Moose> exports, but | ||||
| 184 | differs slightly in how some items are handled (see L<CAVEATS> below for | ||||
| 185 | details). | ||||
| 186 | |||||
| 187 | Moose::Role also offers two role-specific keyword exports: | ||||
| 188 | |||||
| 189 | =over 4 | ||||
| 190 | |||||
| 191 | =item B<requires (@method_names)> | ||||
| 192 | |||||
| 193 | Roles can require that certain methods are implemented by any class which | ||||
| 194 | C<does> the role. | ||||
| 195 | |||||
| 196 | Note that attribute accessors also count as methods for the purposes | ||||
| 197 | of satisfying the requirements of a role. | ||||
| 198 | |||||
| 199 | =item B<excludes (@role_names)> | ||||
| 200 | |||||
| 201 | Roles can C<exclude> other roles, in effect saying "I can never be combined | ||||
| 202 | with these C<@role_names>". This is a feature which should not be used | ||||
| 203 | lightly. | ||||
| 204 | |||||
| 205 | =back | ||||
| 206 | |||||
| 207 | =head2 B<unimport> | ||||
| 208 | |||||
| 209 | Moose::Role offers a way to remove the keywords it exports, through the | ||||
| 210 | C<unimport> method. You simply have to say C<no Moose::Role> at the bottom of | ||||
| 211 | your code for this to work. | ||||
| 212 | |||||
| 213 | =head2 B<< Moose::Role->init_meta(for_class => $role, metaclass => $metaclass) >> | ||||
| 214 | |||||
| 215 | The C<init_meta> method sets up the metaclass object for the role | ||||
| 216 | specified by C<for_class>. It also injects a a C<meta> accessor into | ||||
| 217 | the role so you can get at this object. | ||||
| 218 | |||||
| 219 | The default metaclass is L<Moose::Meta::Role>. You can specify an | ||||
| 220 | alternate metaclass with the C<metaclass> parameter. | ||||
| 221 | |||||
| 222 | =head1 METACLASS | ||||
| 223 | |||||
| 224 | When you use Moose::Role, you can specify which metaclass to use: | ||||
| 225 | |||||
| 226 | use Moose::Role -metaclass => 'My::Meta::Role'; | ||||
| 227 | |||||
| 228 | You can also specify traits which will be applied to your role metaclass: | ||||
| 229 | |||||
| 230 | use Moose::Role -traits => 'My::Trait'; | ||||
| 231 | |||||
| 232 | This is very similar to the attribute traits feature. When you do | ||||
| 233 | this, your class's C<meta> object will have the specified traits | ||||
| 234 | applied to it. See L<Moose/Metaclass and Trait Name Resolution> for more | ||||
| 235 | details. | ||||
| 236 | |||||
| 237 | =head1 APPLYING ROLES | ||||
| 238 | |||||
| 239 | In addition to being applied to a class using the 'with' syntax (see | ||||
| 240 | L<Moose::Manual::Roles>) and using the L<Moose::Util> 'apply_all_roles' | ||||
| 241 | method, roles may also be applied to an instance of a class using | ||||
| 242 | L<Moose::Util> 'apply_all_roles' or the role's metaclass: | ||||
| 243 | |||||
| 244 | MyApp::Test::SomeRole->meta->apply( $instance ); | ||||
| 245 | |||||
| 246 | Doing this creates a new, mutable, anonymous subclass, applies the role to that, | ||||
| 247 | and reblesses. In a debugger, for example, you will see class names of the | ||||
| 248 | form C< Class::MOP::Class::__ANON__::SERIAL::6 >, which means that doing a 'ref' | ||||
| 249 | on your instance may not return what you expect. See L<Moose::Object> for 'DOES'. | ||||
| 250 | |||||
| 251 | Additional params may be added to the new instance by providing 'rebless_params'. | ||||
| 252 | See L<Moose::Meta::Role::Application::ToInstance>. | ||||
| 253 | |||||
| 254 | =head1 CAVEATS | ||||
| 255 | |||||
| 256 | Role support has only a few caveats: | ||||
| 257 | |||||
| 258 | =over 4 | ||||
| 259 | |||||
| 260 | =item * | ||||
| 261 | |||||
| 262 | Roles cannot use the C<extends> keyword; it will throw an exception for now. | ||||
| 263 | The same is true of the C<augment> and C<inner> keywords (not sure those | ||||
| 264 | really make sense for roles). All other Moose keywords will be I<deferred> | ||||
| 265 | so that they can be applied to the consuming class. | ||||
| 266 | |||||
| 267 | =item * | ||||
| 268 | |||||
| 269 | Role composition does its best to B<not> be order-sensitive when it comes to | ||||
| 270 | conflict resolution and requirements detection. However, it is order-sensitive | ||||
| 271 | when it comes to method modifiers. All before/around/after modifiers are | ||||
| 272 | included whenever a role is composed into a class, and then applied in the order | ||||
| 273 | in which the roles are used. This also means that there is no conflict for | ||||
| 274 | before/around/after modifiers. | ||||
| 275 | |||||
| 276 | In most cases, this will be a non-issue; however, it is something to keep in | ||||
| 277 | mind when using method modifiers in a role. You should never assume any | ||||
| 278 | ordering. | ||||
| 279 | |||||
| 280 | =back | ||||
| 281 | |||||
| 282 | =head1 BUGS | ||||
| 283 | |||||
| 284 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 285 | |||||
| 286 | =head1 AUTHOR | ||||
| 287 | |||||
| 288 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
| 289 | |||||
| 290 | Christian Hansen E<lt>chansen@cpan.orgE<gt> | ||||
| 291 | |||||
| 292 | =head1 COPYRIGHT AND LICENSE | ||||
| 293 | |||||
| 294 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
| 295 | |||||
| 296 | L<http://www.iinteractive.com> | ||||
| 297 | |||||
| 298 | This library is free software; you can redistribute it and/or modify | ||||
| 299 | it under the same terms as Perl itself. | ||||
| 300 | |||||
| 301 | =cut |