| Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint/Role.pm |
| Statements | Executed 60 statements in 706µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 3 | 1 | 1 | 87µs | 1.95ms | Moose::Meta::TypeConstraint::Role::new |
| 6 | 1 | 1 | 52µs | 81µs | Moose::Meta::TypeConstraint::Role::__ANON__[:27] |
| 1 | 1 | 1 | 13µs | 28µs | Moose::Meta::TypeConstraint::Role::BEGIN@4 |
| 1 | 1 | 1 | 9µs | 30µs | Moose::Meta::TypeConstraint::Role::BEGIN@12 |
| 1 | 1 | 1 | 9µs | 26µs | Moose::Meta::TypeConstraint::Role::BEGIN@8 |
| 1 | 1 | 1 | 8µs | 12µs | Moose::Meta::TypeConstraint::Role::BEGIN@5 |
| 1 | 1 | 1 | 7µs | 459µs | Moose::Meta::TypeConstraint::Role::BEGIN@6 |
| 1 | 1 | 1 | 4µs | 4µs | Moose::Meta::TypeConstraint::Role::BEGIN@9 |
| 1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Role::BEGIN@10 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Role::__ANON__[:35] |
| 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 | 1 | 700ns | our $VERSION = '2.1403'; | ||
| 3 | |||||
| 4 | 2 | 23µs | 2 | 42µs | # spent 28µs (13+15) within Moose::Meta::TypeConstraint::Role::BEGIN@4 which was called:
# once (13µs+15µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 4 # spent 28µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@4
# spent 15µs making 1 call to strict::import |
| 5 | 2 | 20µs | 2 | 16µs | # spent 12µs (8+4) within Moose::Meta::TypeConstraint::Role::BEGIN@5 which was called:
# once (8µs+4µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 5 # spent 12µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@5
# spent 4µs making 1 call to warnings::import |
| 6 | 2 | 25µs | 2 | 911µs | # spent 459µs (7+452) within Moose::Meta::TypeConstraint::Role::BEGIN@6 which was called:
# once (7µs+452µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 6 # spent 459µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@6
# spent 452µs making 1 call to metaclass::import |
| 7 | |||||
| 8 | 2 | 21µs | 2 | 43µs | # spent 26µs (9+17) within Moose::Meta::TypeConstraint::Role::BEGIN@8 which was called:
# once (9µs+17µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 8 # spent 26µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@8
# spent 17µs making 1 call to Exporter::import |
| 9 | 2 | 21µs | 1 | 4µs | # spent 4µs within Moose::Meta::TypeConstraint::Role::BEGIN@9 which was called:
# once (4µs+0s) by Moose::Util::TypeConstraints::BEGIN@29 at line 9 # spent 4µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@9 |
| 10 | 2 | 20µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Role::BEGIN@10 which was called:
# once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@29 at line 10 # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@10 |
| 11 | |||||
| 12 | 2 | 428µs | 2 | 51µs | # spent 30µs (9+21) within Moose::Meta::TypeConstraint::Role::BEGIN@12 which was called:
# once (9µs+21µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 12 # spent 30µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@12
# spent 21µs making 1 call to parent::import |
| 13 | |||||
| 14 | 1 | 6µs | 3 | 424µs | __PACKAGE__->meta->add_attribute('role' => ( # spent 402µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::Role::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
| 15 | reader => 'role', | ||||
| 16 | Class::MOP::_definition_context(), | ||||
| 17 | )); | ||||
| 18 | |||||
| 19 | # spent 81µs (52+29) within Moose::Meta::TypeConstraint::Role::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint/Role.pm:27] which was called 6 times, avg 13µs/call:
# 6 times (52µs+29µs) by Moose::Meta::TypeConstraint::_inline_check at line 195 of Moose/Meta/TypeConstraint.pm, avg 13µs/call | ||||
| 20 | 18 | 60µs | my $self = shift; | ||
| 21 | my $val = shift; | ||||
| 22 | |||||
| 23 | 12 | 29µs | return 'Moose::Util::does_role(' # spent 16µs making 6 calls to B::perlstring, avg 3µs/call
# spent 13µs making 6 calls to Moose::Meta::TypeConstraint::Role::role, avg 2µs/call | ||
| 24 | . $val . ', ' | ||||
| 25 | . B::perlstring($self->role) | ||||
| 26 | . ')'; | ||||
| 27 | 1 | 2µs | }; | ||
| 28 | |||||
| 29 | # spent 1.95ms (87µs+1.86) within Moose::Meta::TypeConstraint::Role::new which was called 3 times, avg 649µs/call:
# 3 times (87µs+1.86ms) by Moose::Util::TypeConstraints::create_role_type_constraint at line 210 of Moose/Util/TypeConstraints.pm, avg 649µs/call | ||||
| 30 | 24 | 73µs | my ( $class, %args ) = @_; | ||
| 31 | |||||
| 32 | 3 | 54µs | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); # spent 54µs making 3 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 18µs/call | ||
| 33 | |||||
| 34 | my $role_name = $args{role}; | ||||
| 35 | $args{constraint} = sub { Moose::Util::does_role( $_[0], $role_name ) }; | ||||
| 36 | |||||
| 37 | $args{inlined} = $inliner; | ||||
| 38 | |||||
| 39 | 3 | 1.25ms | my $self = $class->SUPER::new( \%args ); # spent 1.25ms making 3 calls to Moose::Meta::TypeConstraint::new, avg 417µs/call | ||
| 40 | |||||
| 41 | 3 | 555µs | $self->compile_type_constraint(); # spent 555µs making 3 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 185µs/call | ||
| 42 | |||||
| 43 | return $self; | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | sub parents { | ||||
| 47 | my $self = shift; | ||||
| 48 | return ( | ||||
| 49 | $self->parent, | ||||
| 50 | map { | ||||
| 51 | # FIXME find_type_constraint might find a TC named after the role but that isn't really it | ||||
| 52 | # I did this anyway since it's a convention that preceded TypeConstraint::Role, and it should DWIM | ||||
| 53 | # if anybody thinks this problematic please discuss on IRC. | ||||
| 54 | # a possible fix is to add by attr indexing to the type registry to find types of a certain property | ||||
| 55 | # regardless of their name | ||||
| 56 | Moose::Util::TypeConstraints::find_type_constraint($_) | ||||
| 57 | || | ||||
| 58 | __PACKAGE__->new( role => $_, name => "__ANON__" ) | ||||
| 59 | } @{ Class::MOP::class_of($self->role)->get_roles }, | ||||
| 60 | ); | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | sub equals { | ||||
| 64 | my ( $self, $type_or_name ) = @_; | ||||
| 65 | |||||
| 66 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 67 | |||||
| 68 | return unless defined $other; | ||||
| 69 | return unless $other->isa(__PACKAGE__); | ||||
| 70 | |||||
| 71 | return $self->role eq $other->role; | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | sub is_a_type_of { | ||||
| 75 | my ($self, $type_or_name) = @_; | ||||
| 76 | |||||
| 77 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 78 | |||||
| 79 | ($self->equals($type) || $self->is_subtype_of($type_or_name)); | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | sub is_subtype_of { | ||||
| 83 | my ($self, $type_or_name_or_role ) = @_; | ||||
| 84 | |||||
| 85 | if ( not ref $type_or_name_or_role ) { | ||||
| 86 | # it might be a role | ||||
| 87 | my $class = Class::MOP::class_of($self->role); | ||||
| 88 | return 1 if defined($class) && $class->does_role( $type_or_name_or_role ); | ||||
| 89 | } | ||||
| 90 | |||||
| 91 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_role); | ||||
| 92 | |||||
| 93 | return unless defined $type; | ||||
| 94 | |||||
| 95 | if ( $type->isa(__PACKAGE__) ) { | ||||
| 96 | # if $type_or_name_or_role isn't a role, it might be the TC name of another ::Role type | ||||
| 97 | # or it could also just be a type object in this branch | ||||
| 98 | my $class = Class::MOP::class_of($self->role); | ||||
| 99 | return defined($class) && $class->does_role( $type->role ); | ||||
| 100 | } else { | ||||
| 101 | # the only other thing we are a subtype of is Object | ||||
| 102 | $self->SUPER::is_subtype_of($type); | ||||
| 103 | } | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | sub create_child_type { | ||||
| 107 | my ($self, @args) = @_; | ||||
| 108 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | 1 | 7µs | 1; | ||
| 112 | |||||
| 113 | # ABSTRACT: Role/TypeConstraint parallel hierarchy | ||||
| 114 | |||||
| 115 | __END__ |