| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint/Role.pm |
| Statements | Executed 347 statements in 6.64ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 36 | 1 | 1 | 3.07ms | 21.3ms | Moose::Meta::TypeConstraint::Role::new |
| 36 | 1 | 1 | 1.79ms | 2.85ms | Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint |
| 1 | 1 | 1 | 70µs | 88µs | Moose::Meta::TypeConstraint::Role::BEGIN@3 |
| 1 | 1 | 1 | 42µs | 201µs | Moose::Meta::TypeConstraint::Role::BEGIN@7 |
| 1 | 1 | 1 | 40µs | 2.71ms | Moose::Meta::TypeConstraint::Role::BEGIN@5 |
| 1 | 1 | 1 | 39µs | 107µs | Moose::Meta::TypeConstraint::Role::BEGIN@4 |
| 1 | 1 | 1 | 38µs | 282µs | Moose::Meta::TypeConstraint::Role::BEGIN@14 |
| 1 | 1 | 1 | 20µs | 20µ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 | 98µs | 2 | 105µs | # spent 88µs (70+18) within Moose::Meta::TypeConstraint::Role::BEGIN@3 which was called:
# once (70µs+18µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 3 # spent 88µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 91µs | 2 | 176µs | # spent 107µs (39+68) within Moose::Meta::TypeConstraint::Role::BEGIN@4 which was called:
# once (39µs+68µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 4 # spent 107µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@4
# spent 68µs making 1 call to warnings::import |
| 5 | 3 | 140µs | 2 | 5.38ms | # spent 2.71ms (40µs+2.67) within Moose::Meta::TypeConstraint::Role::BEGIN@5 which was called:
# once (40µs+2.67ms) by Moose::Util::TypeConstraints::BEGIN@34 at line 5 # spent 2.71ms making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@5
# spent 2.67ms making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 99µs | 2 | 360µs | # spent 201µs (42+159) within Moose::Meta::TypeConstraint::Role::BEGIN@7 which was called:
# once (42µs+159µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 7 # spent 201µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@7
# spent 159µs making 1 call to Exporter::import |
| 8 | 3 | 229µs | 1 | 20µs | # spent 20µs within Moose::Meta::TypeConstraint::Role::BEGIN@8 which was called:
# once (20µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 8 # spent 20µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@8 |
| 9 | |||||
| 10 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 11 | 1 | 66µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 12 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 1.59ms | 2 | 526µs | # spent 282µs (38+244) within Moose::Meta::TypeConstraint::Role::BEGIN@14 which was called:
# once (38µs+244µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 14 # spent 282µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@14
# spent 244µs making 1 call to base::import |
| 15 | |||||
| 16 | 1 | 26µs | 2 | 2.10ms | __PACKAGE__->meta->add_attribute('role' => ( # spent 1.98ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 117µs making 1 call to Moose::Meta::TypeConstraint::Role::meta |
| 17 | reader => 'role', | ||||
| 18 | )); | ||||
| 19 | |||||
| 20 | # spent 21.3ms (3.07+18.2) within Moose::Meta::TypeConstraint::Role::new which was called 36 times, avg 592µs/call:
# 36 times (3.07ms+18.2ms) by Moose::Util::TypeConstraints::create_role_type_constraint at line 170 of Moose/Util/TypeConstraints.pm, avg 592µs/call | ||||
| 21 | 216 | 2.71ms | my ( $class, %args ) = @_; | ||
| 22 | |||||
| 23 | 36 | 4.65ms | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); # spent 4.65ms making 36 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 129µs/call | ||
| 24 | 36 | 5.57ms | my $self = $class->_new(\%args); # spent 5.57ms making 36 calls to Moose::Meta::TypeConstraint::Role::_new, avg 155µs/call | ||
| 25 | |||||
| 26 | 36 | 2.85ms | $self->_create_hand_optimized_type_constraint; # spent 2.85ms making 36 calls to Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint, avg 79µs/call | ||
| 27 | 36 | 5.16ms | $self->compile_type_constraint(); # spent 5.16ms making 36 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 143µs/call | ||
| 28 | |||||
| 29 | return $self; | ||||
| 30 | } | ||||
| 31 | |||||
| 32 | # spent 2.85ms (1.79+1.06) within Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint which was called 36 times, avg 79µs/call:
# 36 times (1.79ms+1.06ms) by Moose::Meta::TypeConstraint::Role::new at line 26, avg 79µs/call | ||||
| 33 | 108 | 1.56ms | my $self = shift; | ||
| 34 | 36 | 496µs | my $role = $self->role; # spent 496µs making 36 calls to Moose::Meta::TypeConstraint::Role::role, avg 14µs/call | ||
| 35 | $self->hand_optimized_type_constraint( | ||||
| 36 | sub { Moose::Util::does_role($_[0], $role) } | ||||
| 37 | 36 | 564µs | ); # spent 564µs making 36 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 16µ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__ |