| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint/Role.pm |
| Statements | Executed 392 statements in 7.08ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 41 | 1 | 1 | 3.35ms | 22.6ms | Moose::Meta::TypeConstraint::Role::new |
| 41 | 1 | 1 | 2.07ms | 3.31ms | Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint |
| 1 | 1 | 1 | 111µs | 361µs | Moose::Meta::TypeConstraint::Role::BEGIN@14 |
| 1 | 1 | 1 | 71µs | 89µs | Moose::Meta::TypeConstraint::Role::BEGIN@3 |
| 1 | 1 | 1 | 69µs | 136µs | Moose::Meta::TypeConstraint::Role::BEGIN@4 |
| 1 | 1 | 1 | 42µs | 221µs | Moose::Meta::TypeConstraint::Role::BEGIN@7 |
| 1 | 1 | 1 | 41µs | 2.65ms | Moose::Meta::TypeConstraint::Role::BEGIN@5 |
| 1 | 1 | 1 | 23µs | 23µs | Moose::Meta::TypeConstraint::Role::BEGIN@8 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Role::__ANON__[:36] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Role::create_child_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Role::equals |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Role::is_a_type_of |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Role::is_subtype_of |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Role::parents |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::TypeConstraint::Role; | ||||
| 2 | |||||
| 3 | 3 | 103µs | 2 | 107µs | # spent 89µs (71+18) within Moose::Meta::TypeConstraint::Role::BEGIN@3 which was called:
# once (71µs+18µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 3 # spent 89µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 99µs | 2 | 204µs | # spent 136µs (69+67) within Moose::Meta::TypeConstraint::Role::BEGIN@4 which was called:
# once (69µs+67µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 4 # spent 136µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@4
# spent 67µs making 1 call to warnings::import |
| 5 | 3 | 141µs | 2 | 5.25ms | # spent 2.65ms (41µs+2.61) within Moose::Meta::TypeConstraint::Role::BEGIN@5 which was called:
# once (41µs+2.61ms) by Moose::Util::TypeConstraints::BEGIN@34 at line 5 # spent 2.65ms making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@5
# spent 2.61ms making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 110µs | 2 | 399µs | # spent 221µs (42+178) within Moose::Meta::TypeConstraint::Role::BEGIN@7 which was called:
# once (42µs+178µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 7 # spent 221µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@7
# spent 178µs making 1 call to Exporter::import |
| 8 | 3 | 219µs | 1 | 23µs | # spent 23µs within Moose::Meta::TypeConstraint::Role::BEGIN@8 which was called:
# once (23µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 8 # spent 23µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@8 |
| 9 | |||||
| 10 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 11 | 1 | 60µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 12 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 1.53ms | 2 | 612µs | # spent 361µs (111+251) within Moose::Meta::TypeConstraint::Role::BEGIN@14 which was called:
# once (111µs+251µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 14 # spent 361µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@14
# spent 251µs making 1 call to base::import |
| 15 | |||||
| 16 | 1 | 26µs | 2 | 2.16ms | __PACKAGE__->meta->add_attribute('role' => ( # spent 2.04ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 118µs making 1 call to Moose::Meta::TypeConstraint::Role::meta |
| 17 | reader => 'role', | ||||
| 18 | )); | ||||
| 19 | |||||
| 20 | # spent 22.6ms (3.35+19.2) within Moose::Meta::TypeConstraint::Role::new which was called 41 times, avg 551µs/call:
# 41 times (3.35ms+19.2ms) by Moose::Util::TypeConstraints::create_role_type_constraint at line 170 of Moose/Util/TypeConstraints.pm, avg 551µs/call | ||||
| 21 | 246 | 2.99ms | my ( $class, %args ) = @_; | ||
| 22 | |||||
| 23 | 41 | 5.10ms | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); # spent 5.10ms making 41 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 124µs/call | ||
| 24 | 41 | 4.95ms | my $self = $class->_new(\%args); # spent 4.95ms making 41 calls to Moose::Meta::TypeConstraint::Role::_new, avg 121µs/call | ||
| 25 | |||||
| 26 | 41 | 3.31ms | $self->_create_hand_optimized_type_constraint; # spent 3.31ms making 41 calls to Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint, avg 81µs/call | ||
| 27 | 41 | 5.87ms | $self->compile_type_constraint(); # spent 5.87ms making 41 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 143µs/call | ||
| 28 | |||||
| 29 | return $self; | ||||
| 30 | } | ||||
| 31 | |||||
| 32 | # spent 3.31ms (2.07+1.23) within Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint which was called 41 times, avg 81µs/call:
# 41 times (2.07ms+1.23ms) by Moose::Meta::TypeConstraint::Role::new at line 26, avg 81µs/call | ||||
| 33 | 123 | 1.77ms | my $self = shift; | ||
| 34 | 41 | 549µs | my $role = $self->role; # spent 549µs making 41 calls to Moose::Meta::TypeConstraint::Role::role, avg 13µs/call | ||
| 35 | $self->hand_optimized_type_constraint( | ||||
| 36 | sub { Moose::Util::does_role($_[0], $role) } | ||||
| 37 | 41 | 685µs | ); # spent 685µs making 41 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 17µs/call | ||
| 38 | } | ||||
| 39 | |||||
| 40 | sub parents { | ||||
| 41 | my $self = shift; | ||||
| 42 | return ( | ||||
| 43 | $self->parent, | ||||
| 44 | map { | ||||
| 45 | # FIXME find_type_constraint might find a TC named after the role but that isn't really it | ||||
| 46 | # I did this anyway since it's a convention that preceded TypeConstraint::Role, and it should DWIM | ||||
| 47 | # if anybody thinks this problematic please discuss on IRC. | ||||
| 48 | # a possible fix is to add by attr indexing to the type registry to find types of a certain property | ||||
| 49 | # regardless of their name | ||||
| 50 | Moose::Util::TypeConstraints::find_type_constraint($_) | ||||
| 51 | || | ||||
| 52 | __PACKAGE__->new( role => $_, name => "__ANON__" ) | ||||
| 53 | } @{ Class::MOP::class_of($self->role)->get_roles }, | ||||
| 54 | ); | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | sub equals { | ||||
| 58 | my ( $self, $type_or_name ) = @_; | ||||
| 59 | |||||
| 60 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 61 | |||||
| 62 | return unless defined $other; | ||||
| 63 | return unless $other->isa(__PACKAGE__); | ||||
| 64 | |||||
| 65 | return $self->role eq $other->role; | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | sub is_a_type_of { | ||||
| 69 | my ($self, $type_or_name) = @_; | ||||
| 70 | |||||
| 71 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 72 | |||||
| 73 | ($self->equals($type) || $self->is_subtype_of($type_or_name)); | ||||
| 74 | } | ||||
| 75 | |||||
| 76 | sub is_subtype_of { | ||||
| 77 | my ($self, $type_or_name_or_role ) = @_; | ||||
| 78 | |||||
| 79 | if ( not ref $type_or_name_or_role ) { | ||||
| 80 | # it might be a role | ||||
| 81 | return 1 if Class::MOP::class_of($self->role)->does_role( $type_or_name_or_role ); | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_role); | ||||
| 85 | |||||
| 86 | return unless defined $type; | ||||
| 87 | |||||
| 88 | if ( $type->isa(__PACKAGE__) ) { | ||||
| 89 | # if $type_or_name_or_role isn't a role, it might be the TC name of another ::Role type | ||||
| 90 | # or it could also just be a type object in this branch | ||||
| 91 | return Class::MOP::class_of($self->role)->does_role( $type->role ); | ||||
| 92 | } else { | ||||
| 93 | # the only other thing we are a subtype of is Object | ||||
| 94 | $self->SUPER::is_subtype_of($type); | ||||
| 95 | } | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | sub create_child_type { | ||||
| 99 | my ($self, @args) = @_; | ||||
| 100 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | 1 | 24µs | 1; | ||
| 104 | |||||
| 105 | __END__ |