← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:42:38 2010
Reported on Wed Nov 17 22:04:50 2010

Filename/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint/Class.pm
StatementsExecuted 329 statements in 6.92ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
34112.88ms20.2msMoose::Meta::TypeConstraint::Class::::newMoose::Meta::TypeConstraint::Class::new
34111.96ms3.01msMoose::Meta::TypeConstraint::Class::::_create_hand_optimized_type_constraintMoose::Meta::TypeConstraint::Class::_create_hand_optimized_type_constraint
11175µs95µsMoose::Meta::TypeConstraint::Class::::BEGIN@3Moose::Meta::TypeConstraint::Class::BEGIN@3
11160µs238µsMoose::Meta::TypeConstraint::Class::::BEGIN@7Moose::Meta::TypeConstraint::Class::BEGIN@7
11139µs108µsMoose::Meta::TypeConstraint::Class::::BEGIN@4Moose::Meta::TypeConstraint::Class::BEGIN@4
11138µs280µsMoose::Meta::TypeConstraint::Class::::BEGIN@14Moose::Meta::TypeConstraint::Class::BEGIN@14
11137µs2.86msMoose::Meta::TypeConstraint::Class::::BEGIN@5Moose::Meta::TypeConstraint::Class::BEGIN@5
11119µs19µsMoose::Meta::TypeConstraint::Class::::BEGIN@8Moose::Meta::TypeConstraint::Class::BEGIN@8
0000s0sMoose::Meta::TypeConstraint::Class::::__ANON__[:38]Moose::Meta::TypeConstraint::Class::__ANON__[:38]
0000s0sMoose::Meta::TypeConstraint::Class::::create_child_typeMoose::Meta::TypeConstraint::Class::create_child_type
0000s0sMoose::Meta::TypeConstraint::Class::::equalsMoose::Meta::TypeConstraint::Class::equals
0000s0sMoose::Meta::TypeConstraint::Class::::get_messageMoose::Meta::TypeConstraint::Class::get_message
0000s0sMoose::Meta::TypeConstraint::Class::::is_a_type_ofMoose::Meta::TypeConstraint::Class::is_a_type_of
0000s0sMoose::Meta::TypeConstraint::Class::::is_subtype_ofMoose::Meta::TypeConstraint::Class::is_subtype_of
0000s0sMoose::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
1package Moose::Meta::TypeConstraint::Class;
2
33102µs2114µs
# spent 95µs (75+19) within Moose::Meta::TypeConstraint::Class::BEGIN@3 which was called: # once (75µs+19µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 3
use strict;
# spent 95µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@3 # spent 19µs making 1 call to strict::import
4391µs2178µs
# spent 108µs (39+69) within Moose::Meta::TypeConstraint::Class::BEGIN@4 which was called: # once (39µs+69µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 4
use warnings;
# spent 108µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@4 # spent 69µs making 1 call to warnings::import
53143µs25.68ms
# spent 2.86ms (37µs+2.82) within Moose::Meta::TypeConstraint::Class::BEGIN@5 which was called: # once (37µs+2.82ms) by Moose::Util::TypeConstraints::BEGIN@33 at line 5
use metaclass;
# spent 2.86ms making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@5 # spent 2.82ms making 1 call to metaclass::import
6
73106µs2415µs
# spent 238µs (60+178) within Moose::Meta::TypeConstraint::Class::BEGIN@7 which was called: # once (60µs+178µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 7
use Scalar::Util 'blessed';
# spent 238µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@7 # spent 178µs making 1 call to Exporter::import
83197µs119µs
# spent 19µs within Moose::Meta::TypeConstraint::Class::BEGIN@8 which was called: # once (19µs+0s) by Moose::Util::TypeConstraints::BEGIN@33 at line 8
use Moose::Util::TypeConstraints ();
# spent 19µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@8
9
1015µsour $VERSION = '1.19';
11162µs$VERSION = eval $VERSION;
# spent 11µs executing statements in string eval
1214µsour $AUTHORITY = 'cpan:STEVAN';
13
1431.87ms2521µs
# spent 280µs (38+242) within Moose::Meta::TypeConstraint::Class::BEGIN@14 which was called: # once (38µs+242µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 14
use base 'Moose::Meta::TypeConstraint';
# spent 280µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@14 # spent 242µs making 1 call to base::import
15
16127µs22.15ms__PACKAGE__->meta->add_attribute('class' => (
# spent 2.03ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 119µs making 1 call to Moose::Meta::TypeConstraint::Class::meta
17 reader => 'class',
18));
19
20
# spent 20.2ms (2.88+17.3) within Moose::Meta::TypeConstraint::Class::new which was called 34 times, avg 595µs/call: # 34 times (2.88ms+17.3ms) by Moose::Util::TypeConstraints::create_class_type_constraint at line 152 of Moose/Util/TypeConstraints.pm, avg 595µs/call
sub new {
212042.56ms my ( $class, %args ) = @_;
22
23344.27ms $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object');
# spent 4.27ms making 34 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 126µs/call
24345.11ms my $self = $class->_new(\%args);
# spent 5.11ms making 34 calls to Moose::Meta::TypeConstraint::Class::_new, avg 150µs/call
25
26343.01ms $self->_create_hand_optimized_type_constraint;
# spent 3.01ms making 34 calls to Moose::Meta::TypeConstraint::Class::_create_hand_optimized_type_constraint, avg 89µs/call
27344.95ms $self->compile_type_constraint();
# spent 4.95ms making 34 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 145µs/call
28
29 return $self;
30}
31
32
# spent 3.01ms (1.96+1.05) within Moose::Meta::TypeConstraint::Class::_create_hand_optimized_type_constraint which was called 34 times, avg 89µs/call: # 34 times (1.96ms+1.05ms) by Moose::Meta::TypeConstraint::Class::new at line 26, avg 89µs/call
sub _create_hand_optimized_type_constraint {
331021.72ms my $self = shift;
3434512µs my $class = $self->class;
# spent 512µs making 34 calls to Moose::Meta::TypeConstraint::Class::class, avg 15µs/call
35 $self->hand_optimized_type_constraint(
36 sub {
37 blessed( $_[0] ) && blessed( $_[0] ) ne 'Regexp' && $_[0]->isa($class)
38 }
3934540µs );
# spent 540µs making 34 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 16µs/call
40}
41
42sub parents {
43 my $self = shift;
44 return (
45 $self->parent,
46 map {
47 # FIXME find_type_constraint might find a TC named after the class but that isn't really it
48 # I did this anyway since it's a convention that preceded TypeConstraint::Class, and it should DWIM
49 # if anybody thinks this problematic please discuss on IRC.
50 # a possible fix is to add by attr indexing to the type registry to find types of a certain property
51 # regardless of their name
52 Moose::Util::TypeConstraints::find_type_constraint($_)
53 ||
54 __PACKAGE__->new( class => $_, name => "__ANON__" )
55 } Class::MOP::class_of($self->class)->superclasses,
56 );
57}
58
59sub equals {
60 my ( $self, $type_or_name ) = @_;
61
62 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
63
64 return unless defined $other;
65 return unless $other->isa(__PACKAGE__);
66
67 return $self->class eq $other->class;
68}
69
70sub is_a_type_of {
71 my ($self, $type_or_name) = @_;
72
73 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
74
75 ($self->equals($type) || $self->is_subtype_of($type_or_name));
76}
77
78sub is_subtype_of {
79 my ($self, $type_or_name_or_class ) = @_;
80
81 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class);
82
83 if ( not defined $type ) {
84 if ( not ref $type_or_name_or_class ) {
85 # it might be a class
86 return 1 if $self->class->isa( $type_or_name_or_class );
87 }
88 return;
89 }
90
91 if ( $type->isa(__PACKAGE__) && $type->class ne $self->class) {
92 # if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type
93 # or it could also just be a type object in this branch
94 return $self->class->isa( $type->class );
95 } else {
96 # the only other thing we are a subtype of is Object
97 $self->SUPER::is_subtype_of($type);
98 }
99}
100
101# This is a bit counter-intuitive, but a child type of a Class type
102# constraint is not itself a Class type constraint (it has no class
103# attribute). This whole create_child_type thing needs some changing
104# though, probably making MMC->new a factory or something.
105sub create_child_type {
106 my ($self, @args) = @_;
107 return Moose::Meta::TypeConstraint->new(@args, parent => $self);
108}
109
110sub get_message {
111 my $self = shift;
112 my ($value) = @_;
113
114 if ($self->has_message) {
115 return $self->SUPER::get_message(@_);
116 }
117
118 $value = (defined $value ? overload::StrVal($value) : 'undef');
119 return "Validation failed for '" . $self->name . "' with value $value (not isa " . $self->class . ")";
120}
121
122125µs1;
123
124__END__