Filename | /usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint/Role.pm |
Statements | Executed 565 statements in 1.87ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
35 | 1 | 1 | 617µs | 21.5ms | new | Moose::Meta::TypeConstraint::Role::
89 | 1 | 1 | 588µs | 942µs | __ANON__[:27] | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 9µs | 19µs | BEGIN@4 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 6µs | 351µs | BEGIN@6 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 6µs | 21µs | BEGIN@8 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 6µs | 10µs | BEGIN@5 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 5µs | 24µs | BEGIN@12 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 3µs | 3µs | BEGIN@10 | Moose::Meta::TypeConstraint::Role::
1 | 1 | 1 | 3µs | 3µs | BEGIN@9 | Moose::Meta::TypeConstraint::Role::
0 | 0 | 0 | 0s | 0s | __ANON__[:35] | 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 | 1 | 500ns | our $VERSION = '2.1604'; | ||
3 | |||||
4 | 2 | 20µs | 2 | 29µs | # spent 19µs (9+10) within Moose::Meta::TypeConstraint::Role::BEGIN@4 which was called:
# once (9µs+10µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 4 # spent 19µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@4
# spent 10µs making 1 call to strict::import |
5 | 2 | 18µs | 2 | 14µs | # spent 10µs (6+4) within Moose::Meta::TypeConstraint::Role::BEGIN@5 which was called:
# once (6µs+4µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 5 # spent 10µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | 2 | 24µs | 2 | 696µs | # spent 351µs (6+345) within Moose::Meta::TypeConstraint::Role::BEGIN@6 which was called:
# once (6µs+345µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 6 # spent 351µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@6
# spent 345µs making 1 call to metaclass::import |
7 | |||||
8 | 2 | 20µs | 2 | 36µs | # spent 21µs (6+15) within Moose::Meta::TypeConstraint::Role::BEGIN@8 which was called:
# once (6µs+15µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 8 # spent 21µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@8
# spent 15µs making 1 call to Exporter::import |
9 | 2 | 16µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Role::BEGIN@9 which was called:
# once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@29 at line 9 # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@9 |
10 | 2 | 18µ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 | 454µs | 2 | 42µs | # spent 24µs (5+18) within Moose::Meta::TypeConstraint::Role::BEGIN@12 which was called:
# once (5µs+18µs) by Moose::Util::TypeConstraints::BEGIN@29 at line 12 # spent 24µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@12
# spent 18µs making 1 call to parent::import |
13 | |||||
14 | 1 | 4µs | 3 | 289µs | __PACKAGE__->meta->add_attribute('role' => ( # spent 272µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::Role::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
15 | reader => 'role', | ||||
16 | Class::MOP::_definition_context(), | ||||
17 | )); | ||||
18 | |||||
19 | # spent 942µs (588+354) within Moose::Meta::TypeConstraint::Role::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint/Role.pm:27] which was called 89 times, avg 11µs/call:
# 89 times (588µs+354µs) by Moose::Meta::TypeConstraint::_inline_check at line 195 of Moose/Meta/TypeConstraint.pm, avg 11µs/call | ||||
20 | 89 | 21µs | my $self = shift; | ||
21 | 89 | 20µs | my $val = shift; | ||
22 | |||||
23 | 89 | 723µs | 178 | 354µs | return 'Moose::Util::does_role(' # spent 206µs making 89 calls to B::perlstring, avg 2µs/call
# spent 148µs making 89 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 21.5ms (617µs+20.9) within Moose::Meta::TypeConstraint::Role::new which was called 35 times, avg 615µs/call:
# 35 times (617µs+20.9ms) by Moose::Util::TypeConstraints::create_role_type_constraint at line 210 of Moose/Util/TypeConstraints.pm, avg 615µs/call | ||||
30 | 35 | 37µs | my ( $class, %args ) = @_; | ||
31 | |||||
32 | 35 | 58µs | 35 | 493µs | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); # spent 493µs making 35 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 14µs/call |
33 | |||||
34 | 35 | 21µs | my $role_name = $args{role}; | ||
35 | 35 | 123µs | $args{constraint} = sub { Moose::Util::does_role( $_[0], $role_name ) }; | ||
36 | |||||
37 | 35 | 30µs | $args{inlined} = $inliner; | ||
38 | |||||
39 | 35 | 104µs | 35 | 14.9ms | my $self = $class->SUPER::new( \%args ); # spent 14.9ms making 35 calls to Moose::Meta::TypeConstraint::new, avg 424µs/call |
40 | |||||
41 | 35 | 50µs | 35 | 5.56ms | $self->compile_type_constraint(); # spent 5.56ms making 35 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 159µs/call |
42 | |||||
43 | 35 | 101µs | 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 | 4µs | 1; | ||
112 | |||||
113 | # ABSTRACT: Role/TypeConstraint parallel hierarchy | ||||
114 | |||||
115 | __END__ |