| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint/Role.pm |
| Statements | Executed 779 statements in 12.6ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 84 | 1 | 1 | 7.07ms | 46.2ms | Moose::Meta::TypeConstraint::Role::new |
| 84 | 1 | 1 | 4.42ms | 6.97ms | Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint |
| 1 | 1 | 1 | 73µs | 91µs | Moose::Meta::TypeConstraint::Role::BEGIN@3 |
| 1 | 1 | 1 | 46µs | 209µs | Moose::Meta::TypeConstraint::Role::BEGIN@7 |
| 1 | 1 | 1 | 38µs | 107µs | Moose::Meta::TypeConstraint::Role::BEGIN@4 |
| 1 | 1 | 1 | 38µs | 286µs | Moose::Meta::TypeConstraint::Role::BEGIN@14 |
| 1 | 1 | 1 | 37µs | 3.00ms | Moose::Meta::TypeConstraint::Role::BEGIN@5 |
| 1 | 1 | 1 | 21µs | 21µ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 | 101µs | 2 | 109µs | # spent 91µs (73+18) within Moose::Meta::TypeConstraint::Role::BEGIN@3 which was called:
# once (73µs+18µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 3 # spent 91µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 95µs | 2 | 176µs | # spent 107µs (38+69) within Moose::Meta::TypeConstraint::Role::BEGIN@4 which was called:
# once (38µs+69µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 4 # spent 107µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@4
# spent 69µs making 1 call to warnings::import |
| 5 | 3 | 150µs | 2 | 5.96ms | # spent 3.00ms (37µs+2.96) within Moose::Meta::TypeConstraint::Role::BEGIN@5 which was called:
# once (37µs+2.96ms) by Moose::Util::TypeConstraints::BEGIN@34 at line 5 # spent 3.00ms making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@5
# spent 2.96ms making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 118µs | 2 | 373µs | # spent 209µs (46+164) within Moose::Meta::TypeConstraint::Role::BEGIN@7 which was called:
# once (46µs+164µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 7 # spent 209µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@7
# spent 164µs making 1 call to Exporter::import |
| 8 | 3 | 220µs | 1 | 21µs | # spent 21µs within Moose::Meta::TypeConstraint::Role::BEGIN@8 which was called:
# once (21µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 8 # spent 21µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@8 |
| 9 | |||||
| 10 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 11 | 1 | 71µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 12 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 1.60ms | 2 | 534µs | # spent 286µs (38+248) within Moose::Meta::TypeConstraint::Role::BEGIN@14 which was called:
# once (38µs+248µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 14 # spent 286µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@14
# spent 248µs making 1 call to base::import |
| 15 | |||||
| 16 | 1 | 27µs | 2 | 2.20ms | __PACKAGE__->meta->add_attribute('role' => ( # spent 2.08ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 116µs making 1 call to Moose::Meta::TypeConstraint::Role::meta |
| 17 | reader => 'role', | ||||
| 18 | )); | ||||
| 19 | |||||
| 20 | # spent 46.2ms (7.07+39.1) within Moose::Meta::TypeConstraint::Role::new which was called 84 times, avg 550µs/call:
# 84 times (7.07ms+39.1ms) by Moose::Util::TypeConstraints::create_role_type_constraint at line 170 of Moose/Util/TypeConstraints.pm, avg 550µs/call | ||||
| 21 | 504 | 6.45ms | my ( $class, %args ) = @_; | ||
| 22 | |||||
| 23 | 84 | 10.9ms | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); # spent 10.9ms making 84 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 130µs/call | ||
| 24 | 84 | 9.18ms | my $self = $class->_new(\%args); # spent 9.18ms making 84 calls to Moose::Meta::TypeConstraint::Role::_new, avg 109µs/call | ||
| 25 | |||||
| 26 | 84 | 6.97ms | $self->_create_hand_optimized_type_constraint; # spent 6.97ms making 84 calls to Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint, avg 83µs/call | ||
| 27 | 84 | 12.0ms | $self->compile_type_constraint(); # spent 12.0ms making 84 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 143µs/call | ||
| 28 | |||||
| 29 | return $self; | ||||
| 30 | } | ||||
| 31 | |||||
| 32 | # spent 6.97ms (4.42+2.55) within Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint which was called 84 times, avg 83µs/call:
# 84 times (4.42ms+2.55ms) by Moose::Meta::TypeConstraint::Role::new at line 26, avg 83µs/call | ||||
| 33 | 252 | 3.76ms | my $self = shift; | ||
| 34 | 84 | 1.12ms | my $role = $self->role; # spent 1.12ms making 84 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 | 84 | 1.43ms | ); # spent 1.43ms making 84 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__ |