← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 05.Domain_and_Item.t
  Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:23:02 2010

File /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/Role.pm
Statements Executed 221
Statement Execution Time 857µs
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2211314µs1.93msMoose::Meta::TypeConstraint::Role::::newMoose::Meta::TypeConstraint::Role::new
2211176µs271µsMoose::Meta::TypeConstraint::Role::::_create_hand_optimized_type_constraintMoose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint
11113µs16µsMoose::Meta::TypeConstraint::Role::::BEGIN@3Moose::Meta::TypeConstraint::Role::BEGIN@3
1117µs16µsMoose::Meta::TypeConstraint::Role::::BEGIN@4Moose::Meta::TypeConstraint::Role::BEGIN@4
1117µs30µsMoose::Meta::TypeConstraint::Role::::BEGIN@7Moose::Meta::TypeConstraint::Role::BEGIN@7
1116µs104µsMoose::Meta::TypeConstraint::Role::::BEGIN@5Moose::Meta::TypeConstraint::Role::BEGIN@5
1116µs48µsMoose::Meta::TypeConstraint::Role::::BEGIN@14Moose::Meta::TypeConstraint::Role::BEGIN@14
1113µs3µsMoose::Meta::TypeConstraint::Role::::BEGIN@8Moose::Meta::TypeConstraint::Role::BEGIN@8
0000s0sMoose::Meta::TypeConstraint::Role::::__ANON__[:36]Moose::Meta::TypeConstraint::Role::__ANON__[:36]
0000s0sMoose::Meta::TypeConstraint::Role::::create_child_typeMoose::Meta::TypeConstraint::Role::create_child_type
0000s0sMoose::Meta::TypeConstraint::Role::::equalsMoose::Meta::TypeConstraint::Role::equals
0000s0sMoose::Meta::TypeConstraint::Role::::is_a_type_ofMoose::Meta::TypeConstraint::Role::is_a_type_of
0000s0sMoose::Meta::TypeConstraint::Role::::is_subtype_ofMoose::Meta::TypeConstraint::Role::is_subtype_of
0000s0sMoose::Meta::TypeConstraint::Role::::parentsMoose::Meta::TypeConstraint::Role::parents
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moose::Meta::TypeConstraint::Role;
2
3320µs219µs
# spent 16µs (13+3) within Moose::Meta::TypeConstraint::Role::BEGIN@3 which was called # once (13µs+3µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 3
use strict;
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@3 # spent 3µs making 1 call to strict::import
4318µs225µs
# spent 16µs (7+9) within Moose::Meta::TypeConstraint::Role::BEGIN@4 which was called # once (7µs+9µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 4
use warnings;
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@4 # spent 9µs making 1 call to warnings::import
5325µs2202µs
# spent 104µs (6+98) within Moose::Meta::TypeConstraint::Role::BEGIN@5 which was called # once (6µs+98µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 5
use metaclass;
# spent 104µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@5 # spent 98µs making 1 call to metaclass::import
6
7320µs254µs
# spent 30µs (7+24) within Moose::Meta::TypeConstraint::Role::BEGIN@7 which was called # once (7µs+24µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 7
use Scalar::Util 'blessed';
# spent 30µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@7 # spent 24µs making 1 call to Exporter::import
8338µs13µs
# spent 3µs within Moose::Meta::TypeConstraint::Role::BEGIN@8 which was called # once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@33 at line 8
use Moose::Util::TypeConstraints ();
# spent 3µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@8
9
101700nsour $VERSION = '0.98';
11114µs$VERSION = eval $VERSION;
121300nsour $AUTHORITY = 'cpan:STEVAN';
13
143342µs291µs
# spent 48µs (6+43) within Moose::Meta::TypeConstraint::Role::BEGIN@14 which was called # once (6µs+43µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 14
use base 'Moose::Meta::TypeConstraint';
# spent 48µs making 1 call to Moose::Meta::TypeConstraint::Role::BEGIN@14 # spent 42µs making 1 call to base::import
15
1613µs2290µs__PACKAGE__->meta->add_attribute('role' => (
# spent 273µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Role::meta
17 reader => 'role',
18));
19
20
# spent 1.93ms (314µs+1.62) within Moose::Meta::TypeConstraint::Role::new which was called 22 times, avg 88µs/call: # 22 times (314µs+1.62ms) by Moose::Util::TypeConstraints::create_role_type_constraint at line 169 of Moose/Util/TypeConstraints.pm, avg 88µs/call
sub new {
212228µs my ( $class, %args ) = @_;
22
232234µs22393µs $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object');
# spent 393µs making 22 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 18µs/call
242246µs22497µs my $self = $class->_new(\%args);
# spent 497µs making 22 calls to Moose::Meta::TypeConstraint::Role::_new, avg 23µs/call
25
262231µs22271µs $self->_create_hand_optimized_type_constraint;
# spent 271µs making 22 calls to Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint, avg 12µs/call
272234µs22460µs $self->compile_type_constraint();
# spent 460µs making 22 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 21µs/call
28
292256µs return $self;
30}
31
32
# spent 271µs (176+95) within Moose::Meta::TypeConstraint::Role::_create_hand_optimized_type_constraint which was called 22 times, avg 12µs/call: # 22 times (176µs+95µs) by Moose::Meta::TypeConstraint::Role::new at line 26, avg 12µs/call
sub _create_hand_optimized_type_constraint {
33226µs my $self = shift;
342230µs2240µs my $role = $self->role;
# spent 40µs making 22 calls to Moose::Meta::TypeConstraint::Role::role, avg 2µs/call
35 $self->hand_optimized_type_constraint(
36 sub { Moose::Util::does_role($_[0], $role) }
3722106µs2255µs );
# spent 55µs making 22 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 3µs/call
38}
39
40sub 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
57sub 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
68sub 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
76sub 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
98sub create_child_type {
99 my ($self, @args) = @_;
100 return Moose::Meta::TypeConstraint->new(@args, parent => $self);
101}
102
10317µs1;
104
105__END__
106
107=pod
108
109=head1 NAME
110
111Moose::Meta::TypeConstraint::Role - Role/TypeConstraint parallel hierarchy
112
113=head1 DESCRIPTION
114
115This class represents type constraints for a role.
116
117=head1 INHERITANCE
118
119C<Moose::Meta::TypeConstraint::Role> is a subclass of
120L<Moose::Meta::TypeConstraint>.
121
122=head1 METHODS
123
124=over 4
125
126=item B<< Moose::Meta::TypeConstraint::Role->new(%options) >>
127
128This creates a new role type constraint based on the given
129C<%options>.
130
131It takes the same options as its parent, with two exceptions. First,
132it requires an additional option, C<role>, which is name of the
133constraint's role. Second, it automatically sets the parent to the
134C<Object> type.
135
136The constructor also overrides the hand optimized type constraint with
137one it creates internally.
138
139=item B<< $constraint->role >>
140
141Returns the role name associated with the constraint.
142
143=item B<< $constraint->parents >>
144
145Returns all the type's parent types, corresponding to the roles that
146its role does.
147
148=item B<< $constraint->is_subtype_of($type_name_or_object) >>
149
150If the given type is also a role type, then this checks that the
151type's role does the other type's role.
152
153Otherwise it falls back to the implementation in
154L<Moose::Meta::TypeConstraint>.
155
156=item B<< $constraint->create_child_type(%options) >>
157
158This returns a new L<Moose::Meta::TypeConstraint> object with the type
159as its parent.
160
161Note that it does I<not> return a C<Moose::Meta::TypeConstraint::Role>
162object!
163
164=back
165
166=head1 BUGS
167
168See L<Moose/BUGS> for details on reporting bugs.
169
170=head1 AUTHOR
171
172Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
173
174=head1 COPYRIGHT AND LICENSE
175
176Copyright 2006-2010 by Infinity Interactive, Inc.
177
178L<http://www.iinteractive.com>
179
180This library is free software; you can redistribute it and/or modify
181it under the same terms as Perl itself.
182
183=cut