Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Role.pm |
Statements | Executed 305 statements in 1.09ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
19 | 1 | 1 | 279µs | 9.26ms | new | Moose::Meta::TypeConstraint::Role::
19 | 1 | 1 | 124µs | 175µs | _create_hand_optimized_type_constraint | Moose::Meta::TypeConstraint::Role::
19 | 1 | 1 | 112µs | 175µs | __ANON__[:32] | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 8µs | 335µs | BEGIN@11 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 8µs | 11µs | BEGIN@10 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 8µs | 8µs | BEGIN@2 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 6µs | 18µs | BEGIN@13 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 6µs | 16µs | BEGIN@9 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 6µs | 24µs | BEGIN@14 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 5µs | 53µs | BEGIN@17 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 3µs | 3µs | BEGIN@15 | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | __ANON__[:40] | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | __ANON__[:56] | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | create_child_type | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | equals | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | is_a_type_of | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | is_subtype_of | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | parents | Moose::Meta::TypeConstraint::Role::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::TypeConstraint::Role; | ||||
2 | # spent 8µs within Moose::Meta::TypeConstraint::Role::BEGIN@2 which was called:
# once (8µs+0s) by Moose::Util::TypeConstraints::BEGIN@37 at line 4 | ||||
3 | 1 | 4µs | $Moose::Meta::TypeConstraint::Role::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 29µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@2 |
5 | { | ||||
6 | 2 | 800ns | $Moose::Meta::TypeConstraint::Role::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 20µs | 2 | 26µs | # spent 16µs (6+10) within Moose::Meta::TypeConstraint::Role::BEGIN@9 which was called:
# once (6µs+10µs) by Moose::Util::TypeConstraints::BEGIN@37 at line 9 # spent 16µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@9
# spent 10µs making 1 call to strict::import |
10 | 2 | 19µs | 2 | 14µs | # spent 11µs (8+3) within Moose::Meta::TypeConstraint::Role::BEGIN@10 which was called:
# once (8µs+3µs) by Moose::Util::TypeConstraints::BEGIN@37 at line 10 # spent 11µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@10
# spent 3µs making 1 call to warnings::import |
11 | 2 | 23µs | 2 | 661µs | # spent 335µs (8+326) within Moose::Meta::TypeConstraint::Role::BEGIN@11 which was called:
# once (8µs+326µs) by Moose::Util::TypeConstraints::BEGIN@37 at line 11 # spent 335µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@11
# spent 326µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 21µs | 2 | 31µs | # spent 18µs (6+12) within Moose::Meta::TypeConstraint::Role::BEGIN@13 which was called:
# once (6µs+12µs) by Moose::Util::TypeConstraints::BEGIN@37 at line 13 # spent 18µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@13
# spent 12µs making 1 call to Exporter::import |
14 | 2 | 22µs | 2 | 43µs | # spent 24µs (6+19) within Moose::Meta::TypeConstraint::Role::BEGIN@14 which was called:
# once (6µs+19µs) by Moose::Util::TypeConstraints::BEGIN@37 at line 14 # spent 24µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@14
# spent 19µs making 1 call to Exporter::import |
15 | 2 | 19µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Role::BEGIN@15 which was called:
# once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@37 at line 15 # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@15 |
16 | |||||
17 | 2 | 487µs | 2 | 100µs | # spent 53µs (5+47) within Moose::Meta::TypeConstraint::Role::BEGIN@17 which was called:
# once (5µs+47µs) by Moose::Util::TypeConstraints::BEGIN@37 at line 17 # spent 53µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@17
# spent 47µs making 1 call to base::import |
18 | |||||
19 | 1 | 3µs | 3 | 283µs | __PACKAGE__->meta->add_attribute('role' => ( # spent 264µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::Role::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
20 | reader => 'role', | ||||
21 | Class::MOP::_definition_context(), | ||||
22 | )); | ||||
23 | |||||
24 | # spent 175µs (112+63) within Moose::Meta::TypeConstraint::Role::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Role.pm:32] which was called 19 times, avg 9µs/call:
# 19 times (112µs+63µs) by Moose::Meta::TypeConstraint::_inline_check at line 216 of Moose/Meta/TypeConstraint.pm, avg 9µs/call | ||||
25 | 19 | 3µs | my $self = shift; | ||
26 | 19 | 3µs | my $val = shift; | ||
27 | |||||
28 | 19 | 130µs | 38 | 63µs | return 'Moose::Util::does_role(' # spent 40µs making 19 calls to B::perlstring, avg 2µs/call
# spent 23µs making 19 calls to Moose::Meta::TypeConstraint::Role::role, avg 1µs/call |
29 | . $val . ', ' | ||||
30 | . B::perlstring($self->role) | ||||
31 | . ')'; | ||||
32 | 1 | 2µs | }; | ||
33 | |||||
34 | # spent 9.26ms (279µs+8.98) within Moose::Meta::TypeConstraint::Role::new which was called 19 times, avg 487µs/call:
# 19 times (279µs+8.98ms) by Moose::Util::TypeConstraints::create_role_type_constraint at line 224 of Moose/Util/TypeConstraints.pm, avg 487µs/call | ||||
35 | 19 | 17µs | my ( $class, %args ) = @_; | ||
36 | |||||
37 | 19 | 22µs | 19 | 248µs | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); # spent 248µs making 19 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 13µs/call |
38 | |||||
39 | 19 | 4µs | my $role_name = $args{role}; | ||
40 | 19 | 48µs | $args{constraint} = sub { Moose::Util::does_role( $_[0], $role_name ) }; | ||
41 | |||||
42 | 19 | 5µs | $args{inlined} = $inliner; | ||
43 | |||||
44 | 19 | 32µs | 19 | 4.19ms | my $self = $class->SUPER::new( \%args ); # spent 4.19ms making 19 calls to Moose::Meta::TypeConstraint::new, avg 221µs/call |
45 | |||||
46 | 19 | 20µs | 19 | 175µs | $self->_create_hand_optimized_type_constraint; # spent 175µs making 19 calls to Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint, avg 9µs/call |
47 | 19 | 16µs | 19 | 4.36ms | $self->compile_type_constraint(); # spent 4.36ms making 19 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 230µs/call |
48 | |||||
49 | 19 | 40µs | return $self; | ||
50 | } | ||||
51 | |||||
52 | # spent 175µs (124+51) within Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint which was called 19 times, avg 9µs/call:
# 19 times (124µs+51µs) by Moose::Meta::TypeConstraint::Role::new at line 46, avg 9µs/call | ||||
53 | 19 | 2µs | my $self = shift; | ||
54 | 19 | 14µs | 19 | 19µs | my $role = $self->role; # spent 19µs making 19 calls to Moose::Meta::TypeConstraint::Role::role, avg 1µs/call |
55 | $self->hand_optimized_type_constraint( | ||||
56 | sub { Moose::Util::does_role($_[0], $role) } | ||||
57 | 19 | 76µs | 19 | 31µs | ); # spent 31µs making 19 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 2µs/call |
58 | } | ||||
59 | |||||
60 | sub parents { | ||||
61 | my $self = shift; | ||||
62 | return ( | ||||
63 | $self->parent, | ||||
64 | map { | ||||
65 | # FIXME find_type_constraint might find a TC named after the role but that isn't really it | ||||
66 | # I did this anyway since it's a convention that preceded TypeConstraint::Role, and it should DWIM | ||||
67 | # if anybody thinks this problematic please discuss on IRC. | ||||
68 | # a possible fix is to add by attr indexing to the type registry to find types of a certain property | ||||
69 | # regardless of their name | ||||
70 | Moose::Util::TypeConstraints::find_type_constraint($_) | ||||
71 | || | ||||
72 | __PACKAGE__->new( role => $_, name => "__ANON__" ) | ||||
73 | } @{ Class::MOP::class_of($self->role)->get_roles }, | ||||
74 | ); | ||||
75 | } | ||||
76 | |||||
77 | sub equals { | ||||
78 | my ( $self, $type_or_name ) = @_; | ||||
79 | |||||
80 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
81 | |||||
82 | return unless defined $other; | ||||
83 | return unless $other->isa(__PACKAGE__); | ||||
84 | |||||
85 | return $self->role eq $other->role; | ||||
86 | } | ||||
87 | |||||
88 | sub is_a_type_of { | ||||
89 | my ($self, $type_or_name) = @_; | ||||
90 | |||||
91 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
92 | |||||
93 | ($self->equals($type) || $self->is_subtype_of($type_or_name)); | ||||
94 | } | ||||
95 | |||||
96 | sub is_subtype_of { | ||||
97 | my ($self, $type_or_name_or_role ) = @_; | ||||
98 | |||||
99 | if ( not ref $type_or_name_or_role ) { | ||||
100 | # it might be a role | ||||
101 | my $class = Class::MOP::class_of($self->role); | ||||
102 | return 1 if defined($class) && $class->does_role( $type_or_name_or_role ); | ||||
103 | } | ||||
104 | |||||
105 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_role); | ||||
106 | |||||
107 | return unless defined $type; | ||||
108 | |||||
109 | if ( $type->isa(__PACKAGE__) ) { | ||||
110 | # if $type_or_name_or_role isn't a role, it might be the TC name of another ::Role type | ||||
111 | # or it could also just be a type object in this branch | ||||
112 | my $class = Class::MOP::class_of($self->role); | ||||
113 | return defined($class) && $class->does_role( $type->role ); | ||||
114 | } else { | ||||
115 | # the only other thing we are a subtype of is Object | ||||
116 | $self->SUPER::is_subtype_of($type); | ||||
117 | } | ||||
118 | } | ||||
119 | |||||
120 | sub create_child_type { | ||||
121 | my ($self, @args) = @_; | ||||
122 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
123 | } | ||||
124 | |||||
125 | 1 | 4µs | 1; | ||
126 | |||||
127 | # ABSTRACT: Role/TypeConstraint parallel hierarchy | ||||
128 | |||||
129 | __END__ |