Profile of Moose/Meta/TypeConstraint/Class.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:35 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint/Class.pm
Statements | Executed 151 statements in 1.24ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
8 | 1 | 1 | 266µs | 6.51ms | Moose::Meta::TypeConstraint::Class::::newMoose::Meta::TypeConstraint::Class::new
20 | 1 | 1 | 240µs | 366µs | Moose::Meta::TypeConstraint::Class::::__ANON__[:30]Moose::Meta::TypeConstraint::Class::__ANON__[:30]
1 | 1 | 1 | 15µs | 39µs | Moose::Meta::TypeConstraint::Class::::BEGIN@13Moose::Meta::TypeConstraint::Class::BEGIN@13
1 | 1 | 1 | 10µs | 10µs | Moose::Meta::TypeConstraint::Class::::BEGIN@2Moose::Meta::TypeConstraint::Class::BEGIN@2
1 | 1 | 1 | 9µs | 14µs | Moose::Meta::TypeConstraint::Class::::BEGIN@9Moose::Meta::TypeConstraint::Class::BEGIN@9
1 | 1 | 1 | 8µs | 25µs | Moose::Meta::TypeConstraint::Class::::BEGIN@10Moose::Meta::TypeConstraint::Class::BEGIN@10
1 | 1 | 1 | 8µs | 600µs | Moose::Meta::TypeConstraint::Class::::BEGIN@11Moose::Meta::TypeConstraint::Class::BEGIN@11
1 | 1 | 1 | 7µs | 34µs | Moose::Meta::TypeConstraint::Class::::BEGIN@14Moose::Meta::TypeConstraint::Class::BEGIN@14
1 | 1 | 1 | 7µs | 103µs | Moose::Meta::TypeConstraint::Class::::BEGIN@17Moose::Meta::TypeConstraint::Class::BEGIN@17
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::TypeConstraint::Class::::BEGIN@15Moose::Meta::TypeConstraint::Class::BEGIN@15
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::__ANON__[:39]Moose::Meta::TypeConstraint::Class::__ANON__[:39]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::create_child_typeMoose::Meta::TypeConstraint::Class::create_child_type
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::equalsMoose::Meta::TypeConstraint::Class::equals
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::get_messageMoose::Meta::TypeConstraint::Class::get_message
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::is_a_type_ofMoose::Meta::TypeConstraint::Class::is_a_type_of
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::is_subtype_ofMoose::Meta::TypeConstraint::Class::is_subtype_of
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::parentsMoose::Meta::TypeConstraint::Class::parents

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Moose::Meta::TypeConstraint::Class;
2 |  |  |  |  | # spent 10µs within Moose::Meta::TypeConstraint::Class::BEGIN@2 which was called: # once (10µs+0s) by Moose::Util::TypeConstraints::BEGIN@36 at line 4 BEGIN {
3 | 1 | 5µs |  |  | $Moose::Meta::TypeConstraint::Class::AUTHORITY = 'cpan:STEVAN';
4 | 1 | 23µs | 1 | 10µs | } # spent 10µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@2
5 |  |  |  |  | {
6 | 2 | 1µs |  |  | $Moose::Meta::TypeConstraint::Class::VERSION = '2.0602';
7 |  |  |  |  | }
8 |  |  |  |  |
9 | 3 | 19µs | 2 | 19µs | # spent 14µs (9+5) within Moose::Meta::TypeConstraint::Class::BEGIN@9 which was called: # once (9µs+5µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 9 use strict; # spent 14µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@9 # spent 5µs making 1 call to strict::import
10 | 3 | 18µs | 2 | 41µs | # spent 25µs (8+16) within Moose::Meta::TypeConstraint::Class::BEGIN@10 which was called: # once (8µs+16µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 10 use warnings; # spent 25µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@10 # spent 16µs making 1 call to warnings::import
11 | 3 | 30µs | 2 | 1.19ms | # spent 600µs (8+592) within Moose::Meta::TypeConstraint::Class::BEGIN@11 which was called: # once (8µs+592µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 11 use metaclass; # spent 600µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@11 # spent 592µs making 1 call to metaclass::import
12 |  |  |  |  |
13 | 3 | 27µs | 2 | 64µs | # spent 39µs (15+24) within Moose::Meta::TypeConstraint::Class::BEGIN@13 which was called: # once (15µs+24µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 13 use B; # spent 39µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@13 # spent 24µs making 1 call to Exporter::import
14 | 3 | 22µs | 2 | 62µs | # spent 34µs (7+27) within Moose::Meta::TypeConstraint::Class::BEGIN@14 which was called: # once (7µs+27µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 14 use Scalar::Util 'blessed'; # spent 34µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@14 # spent 27µs making 1 call to Exporter::import
15 | 3 | 17µs | 1 | 4µs | # spent 4µs within Moose::Meta::TypeConstraint::Class::BEGIN@15 which was called: # once (4µs+0s) by Moose::Util::TypeConstraints::BEGIN@36 at line 15 use Moose::Util::TypeConstraints (); # spent 4µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@15
16 |  |  |  |  |
17 | 3 | 523µs | 2 | 199µs | # spent 103µs (7+96) within Moose::Meta::TypeConstraint::Class::BEGIN@17 which was called: # once (7µs+96µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 17 use base 'Moose::Meta::TypeConstraint'; # spent 103µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@17 # spent 96µs making 1 call to base::import
18 |  |  |  |  |
19 | 1 | 6µs | 3 | 468µs | __PACKAGE__->meta->add_attribute('class' => ( # spent 440µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 19µs making 1 call to Moose::Meta::TypeConstraint::Class::meta # spent 9µs making 1 call to Class::MOP::_definition_context
20 |  |  |  |  | reader => 'class',
21 |  |  |  |  | Class::MOP::_definition_context(),
22 |  |  |  |  | ));
23 |  |  |  |  |
24 |  |  |  |  | # spent 366µs (240+126) within Moose::Meta::TypeConstraint::Class::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint/Class.pm:30] which was called 20 times, avg 18µs/call: # 20 times (240µs+126µs) by Moose::Meta::TypeConstraint::_inline_check at line 225 of Moose/Meta/TypeConstraint.pm, avg 18µs/call my $inliner = sub {
25 | 60 | 301µs |  |  | my $self = shift;
26 |  |  |  |  | my $val = shift;
27 |  |  |  |  |
28 |  |  | 40 | 126µs | return 'Scalar::Util::blessed(' . $val . ')' # spent 72µs making 20 calls to B::perlstring, avg 4µs/call # spent 54µs making 20 calls to Moose::Meta::TypeConstraint::Class::class, avg 3µs/call
29 |  |  |  |  | . ' && ' . $val . '->isa(' . B::perlstring($self->class) . ')';
30 | 1 | 2µs |  |  | };
31 |  |  |  |  |
32 |  |  |  |  | # spent 6.51ms (266µs+6.24) within Moose::Meta::TypeConstraint::Class::new which was called 8 times, avg 814µs/call: # 8 times (266µs+6.24ms) by Moose::Util::TypeConstraints::create_class_type_constraint at line 188 of Moose/Util/TypeConstraints.pm, avg 814µs/call sub new {
33 | 64 | 236µs |  |  | my ( $class, %args ) = @_;
34 |  |  |  |  |
35 |  |  | 8 | 178µs | $args{parent} # spent 178µs making 8 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 22µs/call
36 |  |  |  |  | = Moose::Util::TypeConstraints::find_type_constraint('Object');
37 |  |  |  |  |
38 |  |  |  |  | my $class_name = $args{class};
39 |  |  |  |  | $args{constraint} = sub { $_[0]->isa($class_name) };
40 |  |  |  |  |
41 |  |  |  |  | $args{inlined} = $inliner;
42 |  |  |  |  |
43 |  |  | 8 | 4.23ms | my $self = $class->SUPER::new( \%args ); # spent 4.23ms making 8 calls to Moose::Meta::TypeConstraint::new, avg 528µs/call
44 |  |  |  |  |
45 |  |  | 8 | 1.84ms | $self->compile_type_constraint(); # spent 1.84ms making 8 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 230µs/call
46 |  |  |  |  |
47 |  |  |  |  | return $self;
48 |  |  |  |  | }
49 |  |  |  |  |
50 |  |  |  |  | sub parents {
51 |  |  |  |  | my $self = shift;
52 |  |  |  |  | return (
53 |  |  |  |  | $self->parent,
54 |  |  |  |  | map {
55 |  |  |  |  | # FIXME find_type_constraint might find a TC named after the class but that isn't really it
56 |  |  |  |  | # I did this anyway since it's a convention that preceded TypeConstraint::Class, and it should DWIM
57 |  |  |  |  | # if anybody thinks this problematic please discuss on IRC.
58 |  |  |  |  | # a possible fix is to add by attr indexing to the type registry to find types of a certain property
59 |  |  |  |  | # regardless of their name
60 |  |  |  |  | Moose::Util::TypeConstraints::find_type_constraint($_)
61 |  |  |  |  | ||
62 |  |  |  |  | __PACKAGE__->new( class => $_, name => "__ANON__" )
63 |  |  |  |  | } Class::MOP::class_of($self->class)->superclasses,
64 |  |  |  |  | );
65 |  |  |  |  | }
66 |  |  |  |  |
67 |  |  |  |  | sub equals {
68 |  |  |  |  | my ( $self, $type_or_name ) = @_;
69 |  |  |  |  |
70 |  |  |  |  | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
71 |  |  |  |  |
72 |  |  |  |  | if (!defined($other)) {
73 |  |  |  |  | if (!ref($type_or_name)) {
74 |  |  |  |  | return $self->class eq $type_or_name;
75 |  |  |  |  | }
76 |  |  |  |  | return;
77 |  |  |  |  | }
78 |  |  |  |  |
79 |  |  |  |  | return unless $other->isa(__PACKAGE__);
80 |  |  |  |  |
81 |  |  |  |  | return $self->class eq $other->class;
82 |  |  |  |  | }
83 |  |  |  |  |
84 |  |  |  |  | sub is_a_type_of {
85 |  |  |  |  | my ($self, $type_or_name) = @_;
86 |  |  |  |  |
87 |  |  |  |  | ($self->equals($type_or_name) || $self->is_subtype_of($type_or_name));
88 |  |  |  |  | }
89 |  |  |  |  |
90 |  |  |  |  | sub is_subtype_of {
91 |  |  |  |  | my ($self, $type_or_name_or_class ) = @_;
92 |  |  |  |  |
93 |  |  |  |  | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class);
94 |  |  |  |  |
95 |  |  |  |  | if ( not defined $type ) {
96 |  |  |  |  | if ( not ref $type_or_name_or_class ) {
97 |  |  |  |  | # it might be a class
98 |  |  |  |  | my $class = $self->class;
99 |  |  |  |  | return 1 if $class ne $type_or_name_or_class
100 |  |  |  |  | && $class->isa( $type_or_name_or_class );
101 |  |  |  |  | }
102 |  |  |  |  | return;
103 |  |  |  |  | }
104 |  |  |  |  |
105 |  |  |  |  | if ( $type->isa(__PACKAGE__) && $type->class ne $self->class) {
106 |  |  |  |  | # if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type
107 |  |  |  |  | # or it could also just be a type object in this branch
108 |  |  |  |  | return $self->class->isa( $type->class );
109 |  |  |  |  | } else {
110 |  |  |  |  | # the only other thing we are a subtype of is Object
111 |  |  |  |  | $self->SUPER::is_subtype_of($type);
112 |  |  |  |  | }
113 |  |  |  |  | }
114 |  |  |  |  |
115 |  |  |  |  | # This is a bit counter-intuitive, but a child type of a Class type
116 |  |  |  |  | # constraint is not itself a Class type constraint (it has no class
117 |  |  |  |  | # attribute). This whole create_child_type thing needs some changing
118 |  |  |  |  | # though, probably making MMC->new a factory or something.
119 |  |  |  |  | sub create_child_type {
120 |  |  |  |  | my ($self, @args) = @_;
121 |  |  |  |  | return Moose::Meta::TypeConstraint->new(@args, parent => $self);
122 |  |  |  |  | }
123 |  |  |  |  |
124 |  |  |  |  | sub get_message {
125 |  |  |  |  | my $self = shift;
126 |  |  |  |  | my ($value) = @_;
127 |  |  |  |  |
128 |  |  |  |  | if ($self->has_message) {
129 |  |  |  |  | return $self->SUPER::get_message(@_);
130 |  |  |  |  | }
131 |  |  |  |  |
132 |  |  |  |  | $value = (defined $value ? overload::StrVal($value) : 'undef');
133 |  |  |  |  | return "Validation failed for '" . $self->name . "' with value $value (not isa " . $self->class . ")";
134 |  |  |  |  | }
135 |  |  |  |  |
136 | 1 | 7µs |  |  | 1;
137 |  |  |  |  |
138 |  |  |  |  | # ABSTRACT: Class/TypeConstraint parallel hierarchy
139 |  |  |  |  |
- - |  |  |  |  |
142 |  |  |  |  | =pod
143 |  |  |  |  |
144 |  |  |  |  | =head1 NAME
145 |  |  |  |  |
146 |  |  |  |  | Moose::Meta::TypeConstraint::Class - Class/TypeConstraint parallel hierarchy
147 |  |  |  |  |
148 |  |  |  |  | =head1 VERSION
149 |  |  |  |  |
150 |  |  |  |  | version 2.0602
151 |  |  |  |  |
152 |  |  |  |  | =head1 DESCRIPTION
153 |  |  |  |  |
154 |  |  |  |  | This class represents type constraints for a class.
155 |  |  |  |  |
156 |  |  |  |  | =head1 INHERITANCE
157 |  |  |  |  |
158 |  |  |  |  | C<Moose::Meta::TypeConstraint::Class> is a subclass of
159 |  |  |  |  | L<Moose::Meta::TypeConstraint>.
160 |  |  |  |  |
161 |  |  |  |  | =head1 METHODS
162 |  |  |  |  |
163 |  |  |  |  | =over 4
164 |  |  |  |  |
165 |  |  |  |  | =item B<< Moose::Meta::TypeConstraint::Class->new(%options) >>
166 |  |  |  |  |
167 |  |  |  |  | This creates a new class type constraint based on the given
168 |  |  |  |  | C<%options>.
169 |  |  |  |  |
170 |  |  |  |  | It takes the same options as its parent, with two exceptions. First,
171 |  |  |  |  | it requires an additional option, C<class>, which is name of the
172 |  |  |  |  | constraint's class. Second, it automatically sets the parent to the
173 |  |  |  |  | C<Object> type.
174 |  |  |  |  |
175 |  |  |  |  | The constructor also overrides the hand optimized type constraint with
176 |  |  |  |  | one it creates internally.
177 |  |  |  |  |
178 |  |  |  |  | =item B<< $constraint->class >>
179 |  |  |  |  |
180 |  |  |  |  | Returns the class name associated with the constraint.
181 |  |  |  |  |
182 |  |  |  |  | =item B<< $constraint->parents >>
183 |  |  |  |  |
184 |  |  |  |  | Returns all the type's parent types, corresponding to its parent
185 |  |  |  |  | classes.
186 |  |  |  |  |
187 |  |  |  |  | =item B<< $constraint->is_subtype_of($type_name_or_object) >>
188 |  |  |  |  |
189 |  |  |  |  | If the given type is also a class type, then this checks that the
190 |  |  |  |  | type's class is a subclass of the other type's class.
191 |  |  |  |  |
192 |  |  |  |  | Otherwise it falls back to the implementation in
193 |  |  |  |  | L<Moose::Meta::TypeConstraint>.
194 |  |  |  |  |
195 |  |  |  |  | =item B<< $constraint->create_child_type(%options) >>
196 |  |  |  |  |
197 |  |  |  |  | This returns a new L<Moose::Meta::TypeConstraint> object with the type
198 |  |  |  |  | as its parent.
199 |  |  |  |  |
200 |  |  |  |  | Note that it does I<not> return a
201 |  |  |  |  | C<Moose::Meta::TypeConstraint::Class> object!
202 |  |  |  |  |
203 |  |  |  |  | =item B<< $constraint->get_message($value) >>
204 |  |  |  |  |
205 |  |  |  |  | This is the same as L<Moose::Meta::TypeConstraint/get_message> except
206 |  |  |  |  | that it explicitly says C<isa> was checked. This is to help users deal
207 |  |  |  |  | with accidentally autovivified type constraints.
208 |  |  |  |  |
209 |  |  |  |  | =back
210 |  |  |  |  |
211 |  |  |  |  | =head1 BUGS
212 |  |  |  |  |
213 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
214 |  |  |  |  |
215 |  |  |  |  | =head1 AUTHOR
216 |  |  |  |  |
217 |  |  |  |  | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
218 |  |  |  |  |
219 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
220 |  |  |  |  |
221 |  |  |  |  | This software is copyright (c) 2012 by Infinity Interactive, Inc..
222 |  |  |  |  |
223 |  |  |  |  | This is free software; you can redistribute it and/or modify it under
224 |  |  |  |  | the same terms as the Perl 5 programming language system itself.
225 |  |  |  |  |
226 |  |  |  |  | =cut
227 |  |  |  |  |
228 |  |  |  |  |
229 |  |  |  |  | __END__