← 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:22:54 2010

File /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint.pm
Statements Executed 11643
Statement Execution Time 20.5ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
831665.56ms20.4msMoose::Meta::TypeConstraint::::checkMoose::Meta::TypeConstraint::check
93319113.16ms4.65msMoose::Meta::TypeConstraint::::__ANON__[:8]Moose::Meta::TypeConstraint::__ANON__[:8]
431543.10ms60.2msMoose::Meta::TypeConstraint::::coerceMoose::Meta::TypeConstraint::coerce
5421782µs1.54msMoose::Meta::TypeConstraint::::equalsMoose::Meta::TypeConstraint::equals
41106728µs7.78msMoose::Meta::TypeConstraint::::newMoose::Meta::TypeConstraint::new
9011681µs2.61msMoose::Meta::TypeConstraint::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::_actually_compile_type_constraint
9144570µs3.40msMoose::Meta::TypeConstraint::::compile_type_constraintMoose::Meta::TypeConstraint::compile_type_constraint
2311555µs1.27msMoose::Meta::TypeConstraint::::_compile_subtypeMoose::Meta::TypeConstraint::_compile_subtype
1722469µs2.60msMoose::Meta::TypeConstraint::::is_subtype_ofMoose::Meta::TypeConstraint::is_subtype_of
2311386µs530µsMoose::Meta::TypeConstraint::::_collect_all_parentsMoose::Meta::TypeConstraint::_collect_all_parents
111377µs587µsMoose::Meta::TypeConstraint::::BEGIN@6Moose::Meta::TypeConstraint::BEGIN@6
6611311µs389µsMoose::Meta::TypeConstraint::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint
2222130µs1.78msMoose::Meta::TypeConstraint::::create_child_typeMoose::Meta::TypeConstraint::create_child_type
6666125µs125µsMoose::Meta::TypeConstraint::::__ANON__[:30]Moose::Meta::TypeConstraint::__ANON__[:30]
21134µs164µsMoose::Meta::TypeConstraint::::is_a_type_ofMoose::Meta::TypeConstraint::is_a_type_of
11114µs17µsMoose::Meta::TypeConstraint::::BEGIN@4Moose::Meta::TypeConstraint::BEGIN@4
11114µs28µsMoose::Meta::TypeConstraint::::_compile_typeMoose::Meta::TypeConstraint::_compile_type
1119µs56µsMoose::Meta::TypeConstraint::::BEGIN@8Moose::Meta::TypeConstraint::BEGIN@8
1117µs35µsMoose::Meta::TypeConstraint::::BEGIN@11Moose::Meta::TypeConstraint::BEGIN@11
1117µs16µsMoose::Meta::TypeConstraint::::BEGIN@5Moose::Meta::TypeConstraint::BEGIN@5
1117µs29µsMoose::Meta::TypeConstraint::::BEGIN@12Moose::Meta::TypeConstraint::BEGIN@12
1116µs45µsMoose::Meta::TypeConstraint::::BEGIN@14Moose::Meta::TypeConstraint::BEGIN@14
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:253]Moose::Meta::TypeConstraint::__ANON__[:253]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:266]Moose::Meta::TypeConstraint::__ANON__[:266]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:26]Moose::Meta::TypeConstraint::__ANON__[:26]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:279]Moose::Meta::TypeConstraint::__ANON__[:279]
0000s0sMoose::Meta::TypeConstraint::::assert_validMoose::Meta::TypeConstraint::assert_valid
0000s0sMoose::Meta::TypeConstraint::::get_messageMoose::Meta::TypeConstraint::get_message
0000s0sMoose::Meta::TypeConstraint::::parentsMoose::Meta::TypeConstraint::parents
0000s0sMoose::Meta::TypeConstraint::::validateMoose::Meta::TypeConstraint::validate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::TypeConstraint;
3
4320µs220µs
# spent 17µs (14+3) within Moose::Meta::TypeConstraint::BEGIN@4 which was called # once (14µs+3µs) by Moose::BEGIN@19 at line 4
use strict;
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4 # spent 3µs making 1 call to strict::import
5325µs226µs
# spent 16µs (7+10) within Moose::Meta::TypeConstraint::BEGIN@5 which was called # once (7µs+10µs) by Moose::BEGIN@19 at line 5
use warnings;
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5 # spent 10µs making 1 call to warnings::import
63120µs2686µs
# spent 587µs (377+210) within Moose::Meta::TypeConstraint::BEGIN@6 which was called # once (377µs+210µs) by Moose::BEGIN@19 at line 6
use metaclass;
# spent 587µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@6 # spent 99µs making 1 call to metaclass::import
7
89332.71ms9331.49ms
# spent 56µs (9+48) within Moose::Meta::TypeConstraint::BEGIN@8 which was called # once (9µs+48µs) by Moose::BEGIN@19 at line 9 # spent 4.65ms (3.16+1.49) within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint.pm:8] which was called 933 times, avg 5µs/call: # 229 times (790µs+379µs) by SimpleDB::Class::Item::CORE:match or SimpleDB::Class::Item::stringify_values at line 623 of ../lib/SimpleDB/Class/Item.pm, avg 5µs/call # 112 times (406µs+200µs) by MooseX::Types::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types.pm:486] at line 479 of MooseX/Types.pm, avg 5µs/call # 86 times (325µs+159µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 217 of Moose/Util/TypeConstraints.pm, avg 6µs/call # 86 times (300µs+117µs) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 5µs/call # 82 times (222µs+100µs) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 203 of Moose/Util/TypeConstraints.pm, avg 4µs/call # 61 times (222µs+97µs) by Moose::Meta::Method::Accessor::_eval_code at line 26 of Moose/Meta/Method/Accessor.pm, avg 5µs/call # 54 times (164µs+77µs) by MooseX::Types::TypeDecorator::new at line 69 of MooseX/Types/TypeDecorator.pm, avg 4µs/call # 54 times (143µs+65µs) by Moose::Meta::TypeConstraint::equals at line 134, avg 4µs/call # 53 times (139µs+63µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 169, avg 4µs/call # 42 times (155µs+80µs) by MooseX::Types::Base::import at line 82 of MooseX/Types/Base.pm, avg 6µs/call # 19 times (48µs+21µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 523 of Moose/Util/TypeConstraints.pm, avg 4µs/call # 18 times (131µs+77µs) by SimpleDB::Class::Item::CORE:match at line 584 of ../lib/SimpleDB/Class/Item.pm, avg 12µs/call # 17 times (54µs+22µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 165, avg 4µs/call # 7 times (22µs+11µs) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 58 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 5µs/call # 6 times (16µs+7µs) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 175 of Moose/Util/TypeConstraints.pm, avg 4µs/call # 2 times (7µs+5µs) by Moose::Util::TypeConstraints::create_type_constraint_union at line 88 of Moose/Util/TypeConstraints.pm, avg 6µs/call # 2 times (6µs+3µs) by MooseX::Types::CheckedUtilExports::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/CheckedUtilExports.pm:63] at line 56 of MooseX/Types/CheckedUtilExports.pm, avg 5µs/call # 2 times (6µs+3µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 157, avg 4µs/call # once (4µs+2µs) by Moose::init_meta at line 155 of Moose.pm
use overload '""' => sub { shift->name }, # stringify to tc name
# spent 1.49ms making 933 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call
9326µs2104µs fallback => 1;
# spent 56µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8 # spent 48µs making 1 call to overload::import
10
11324µs262µs
# spent 35µs (7+28) within Moose::Meta::TypeConstraint::BEGIN@11 which was called # once (7µs+28µs) by Moose::BEGIN@19 at line 11
use Scalar::Util qw(blessed refaddr);
# spent 35µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11 # spent 28µs making 1 call to Exporter::import
12323µs250µs
# spent 29µs (7+22) within Moose::Meta::TypeConstraint::BEGIN@12 which was called # once (7µs+22µs) by Moose::BEGIN@19 at line 12
use Sub::Name qw(subname);
# spent 29µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@12 # spent 22µs making 1 call to Exporter::import
13
1431.03ms284µs
# spent 45µs (6+39) within Moose::Meta::TypeConstraint::BEGIN@14 which was called # once (6µs+39µs) by Moose::BEGIN@19 at line 14
use base qw(Class::MOP::Object);
# spent 45µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14 # spent 39µs making 1 call to base::import
15
161700nsour $VERSION = '0.98';
17114µs$VERSION = eval $VERSION;
181300nsour $AUTHORITY = 'cpan:STEVAN';
19
2013µs2380µs__PACKAGE__->meta->add_attribute('name' => (reader => 'name'));
# spent 363µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 17µs making 1 call to Moose::Meta::TypeConstraint::meta
2112µs2411µs__PACKAGE__->meta->add_attribute('parent' => (
# spent 401µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
22 reader => 'parent',
23 predicate => 'has_parent',
24));
25
2611µsmy $null_constraint = sub { 1 };
27__PACKAGE__->meta->add_attribute('constraint' => (
28 reader => 'constraint',
29 writer => '_set_constraint',
3066209µs
# spent 125µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint.pm:30] which was called 66 times, avg 2µs/call: # 28 times (66µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 35 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 2µs/call # 22 times (31µs+0s) by Moose::Meta::TypeConstraint::Role::_new at line 32 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 1µs/call # 7 times (11µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new at line 29 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 2µs/call # 6 times (12µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::_new at line 35 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 2µs/call # 2 times (3µs+0s) by Moose::Meta::TypeConstraint::_new at line 26 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 2µs/call # once (1µs+0s) by Moose::Meta::TypeConstraint::Union::_new at line 31 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm
default => sub { $null_constraint }
3114µs2424µs));
# spent 414µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
3212µs2398µs__PACKAGE__->meta->add_attribute('message' => (
# spent 388µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
33 accessor => 'message',
34 predicate => 'has_message'
35));
3612µs2389µs__PACKAGE__->meta->add_attribute('coercion' => (
# spent 378µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
37 accessor => 'coercion',
38 predicate => 'has_coercion'
39));
40
4112µs2406µs__PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => (
# spent 396µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
42 init_arg => 'optimized',
43 accessor => 'hand_optimized_type_constraint',
44 predicate => 'has_hand_optimized_type_constraint',
45));
46
47sub parents {
48 my $self;
49 $self->parent;
50}
51
52# private accessors
53
5412µs2394µs__PACKAGE__->meta->add_attribute('compiled_type_constraint' => (
# spent 383µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
55 accessor => '_compiled_type_constraint',
56 predicate => '_has_compiled_type_constraint'
57));
5812µs2265µs__PACKAGE__->meta->add_attribute('package_defined_in' => (
# spent 254µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
59 accessor => '_package_defined_in'
60));
61
62
# spent 7.78ms (728µs+7.05) within Moose::Meta::TypeConstraint::new which was called 41 times, avg 190µs/call: # 22 times (348µs+1.30ms) by Moose::Meta::TypeConstraint::create_child_type at line 298, avg 75µs/call # 7 times (148µs+4.37ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 69 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 645µs/call # 5 times (90µs+743µs) by Moose::Meta::TypeConstraint::Parameterized::create_child_type at line 67 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 167µs/call # once (20µs+142µs) by Moose::Meta::TypeConstraint::Union::new at line 27 of Moose/Meta/TypeConstraint/Union.pm # once (27µs+122µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 533 of Moose/Util/TypeConstraints.pm # once (20µs+122µs) by Moose::Meta::TypeConstraint::Class::create_child_type at line 106 of Moose/Meta/TypeConstraint/Class.pm # once (27µs+106µs) by Moose::Meta::Attribute::BEGIN@18 at line 731 of Moose/Util/TypeConstraints.pm # once (19µs+88µs) by Moose::Meta::Attribute::BEGIN@18 at line 790 of Moose/Util/TypeConstraints.pm # once (15µs+28µs) by Moose::Meta::Attribute::BEGIN@18 at line 752 of Moose/Util/TypeConstraints.pm # once (14µs+27µs) by Moose::Meta::Attribute::BEGIN@18 at line 773 of Moose/Util/TypeConstraints.pm
sub new {
63287573µs my $class = shift;
64 my ($first, @rest) = @_;
65 my %args = ref $first ? %$first : $first ? ($first, @rest) : ();
66122µs20240µs $args{name} = $args{name} ? "$args{name}" : "__ANON__";
# spent 240µs making 20 calls to MooseX::Types::TypeDecorator::__ANON__[MooseX/Types/TypeDecorator.pm:20], avg 12µs/call
67
68 my $self = $class->_new(%args);
# spent 347µs making 10 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 35µs/call # spent 345µs making 23 calls to Moose::Meta::TypeConstraint::_new, avg 15µs/call # spent 289µs making 7 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 41µs/call # spent 109µs making 1 call to Moose::Meta::TypeConstraint::Union::_new
69 $self->compile_type_constraint()
# spent 4.07ms making 7 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 581µs/call # spent 1.58ms making 34 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 47µs/call # spent 70µs making 41 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call
70 unless $self->_has_compiled_type_constraint;
71 return $self;
72}
73
74
75
76
# spent 60.2ms (3.10+57.1) within Moose::Meta::TypeConstraint::coerce which was called 431 times, avg 140µs/call: # 250 times (1.74ms+39.2ms) by Moose::Meta::Attribute::_coerce_and_verify at line 740 of Moose/Meta/Attribute.pm, avg 164µs/call # 112 times (889µs+5.93ms) by MooseX::Types::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types.pm:486] at line 480 of MooseX/Types.pm, avg 61µs/call # 40 times (236µs+771µs) by Foo::Domain::color or Foo::Domain::components or Foo::Domain::notes or Foo::Domain::parentId or Foo::Domain::properties or Foo::Domain::quantity or Foo::Domain::size or Foo::Domain::size_formatted or Foo::Domain::start_date at line 5 of generated method (unknown origin), avg 25µs/call # 25 times (158µs+586µs) by Foo::Domain::components or Foo::Domain::notes or Foo::Domain::properties or Foo::Domain::start_date at line 13 of generated method (unknown origin), avg 30µs/call # 4 times (74µs+10.7ms) by SimpleDB::Class::Item::parse_value at line 550 of ../lib/SimpleDB/Class/Item.pm, avg 2.69ms/call
sub coerce {
7718182.28ms my $self = shift;
78
79 my $coercion = $self->coercion;
# spent 730µs making 431 calls to Moose::Meta::TypeConstraint::coercion, avg 2µs/call
80
81 unless ($coercion) {
82 require Moose;
83 Moose->throw_error("Cannot coerce without a type coercion");
84 }
85
86 return $_[0] if $self->check($_[0]);
# spent 12.5ms making 431 calls to Moose::Meta::TypeConstraint::check, avg 29µs/call
87
88 return $coercion->coerce(@_);
# spent 73.2ms making 94 calls to Moose::Meta::TypeCoercion::coerce, avg 778µs/call, recursion: max depth 1, time 28.9ms
89}
90
91
# spent 20.4ms (5.56+14.8) within Moose::Meta::TypeConstraint::check which was called 831 times, avg 25µs/call: # 431 times (3.01ms+9.50ms) by Moose::Meta::TypeConstraint::coerce at line 86, avg 29µs/call # 258 times (1.58ms+3.05ms) by Moose::Meta::Attribute::verify_against_type_constraint at line 757 of Moose/Meta/Attribute.pm, avg 18µs/call # 112 times (693µs+1.66ms) by MooseX::Types::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types.pm:486] at line 483 of MooseX/Types.pm, avg 21µs/call # 27 times (237µs+577µs) by MooseX::Types::TypeDecorator::AUTOLOAD at line 199 of MooseX/Types/TypeDecorator.pm, avg 30µs/call # 2 times (18µs+10µs) by Moose::Meta::TypeConstraint::Union::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/Union.pm:50] at line 47 of Moose/Meta/TypeConstraint/Union.pm, avg 14µs/call # once (23µs+20µs) by Class::MOP::Class::__ANON__::SERIAL::1::_add_class_attribute at line 21 of MooseX/AttributeHelpers/MethodProvider/Hash.pm
sub check {
9224934.38ms my ($self, @args) = @_;
93 my $constraint_subref = $self->_compiled_type_constraint;
# spent 1.33ms making 831 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 2µs/call
94 return $constraint_subref->(@args) ? 1 : undef;
# spent 4.71ms making 440 calls to SimpleDB::Class::Types::SdbStr, avg 11µs/call # spent 4.67ms making 73 calls to SimpleDB::Class::Types::SdbInt, avg 64µs/call # spent 2.18ms making 99 calls to SimpleDB::Class::Types::SdbArrayRefOfStr, avg 22µs/call # spent 702µs making 61 calls to SimpleDB::Class::Types::SdbMediumStr, avg 12µs/call # spent 582µs making 65 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:38], avg 9µs/call # spent 483µs making 28 calls to SimpleDB::Class::Types::SdbIntAsStr, avg 17µs/call # spent 92µs making 59 calls to Moose::Util::TypeConstraints::OptimizedConstraints::HashRef, avg 2µs/call # spent 38µs making 2 calls to HashRef[Moose::Meta::Attribute], avg 19µs/call # spent 19µs making 2 calls to Moose::Util::TypeConstraints::OptimizedConstraints::ClassName, avg 10µs/call # spent 5µs making 2 calls to Moose::Util::TypeConstraints::OptimizedConstraints::Str, avg 2µs/call
95}
96
97sub validate {
98 my ($self, $value) = @_;
99 if ($self->_compiled_type_constraint->($value)) {
100 return undef;
101 }
102 else {
103 $self->get_message($value);
104 }
105}
106
107sub assert_valid {
108 my ($self, $value) = @_;
109
110 my $error = $self->validate($value);
111 return 1 if ! defined $error;
112
113 require Moose;
114 Moose->throw_error($error);
115}
116
117sub get_message {
118 my ($self, $value) = @_;
119 if (my $msg = $self->message) {
120 local $_ = $value;
121 return $msg->($value);
122 }
123 else {
124 $value = (defined $value ? overload::StrVal($value) : 'undef');
125 return "Validation failed for '" . $self->name . "' failed with value $value";
126 }
127}
128
129## type predicates ...
130
131
# spent 1.54ms (782µs+759µs) within Moose::Meta::TypeConstraint::equals which was called 54 times, avg 29µs/call: # 53 times (770µs+746µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 170, avg 29µs/call # once (13µs+13µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 159
sub equals {
132252555µs my ( $self, $type_or_name ) = @_;
133
134117µs108490µs my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
# spent 281µs making 54 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 5µs/call # spent 208µs making 54 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 4µs/call
135
136 return 1 if refaddr($self) == refaddr($other);
# spent 44µs making 108 calls to Scalar::Util::refaddr, avg 407ns/call
137
138 if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) {
# spent 77µs making 63 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call # spent 43µs making 36 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 1µs/call
139 return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint;
140 }
141
142 return unless $self->constraint == $other->constraint;
# spent 105µs making 90 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
143
144 if ( $self->has_parent ) {
145 return unless $other->has_parent;
146 return unless $self->parent->equals( $other->parent );
147 } else {
148 return if $other->has_parent;
149 }
150
151 return 1;
152}
153
154
# spent 164µs (34+130) within Moose::Meta::TypeConstraint::is_a_type_of which was called 2 times, avg 82µs/call: # 2 times (34µs+130µs) by MooseX::AttributeHelpers::Trait::Base::process_options_for_provides at line 69 of MooseX/AttributeHelpers/Trait/Base.pm, avg 82µs/call
sub is_a_type_of {
155619µs my ($self, $type_or_name) = @_;
156
15711µs443µs my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
# spent 34µs making 2 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 17µs/call # spent 9µs making 2 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 4µs/call
158
159 ($self->equals($type) || $self->is_subtype_of($type));
# spent 44µs making 1 call to Moose::Meta::TypeConstraint::is_subtype_of # spent 25µs making 1 call to Moose::Meta::TypeConstraint::equals # spent 18µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::equals
160}
161
162
# spent 2.60ms (469µs+2.13) within Moose::Meta::TypeConstraint::is_subtype_of which was called 17 times, avg 153µs/call: # 16 times (458µs+2.10ms) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 25 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 160µs/call # once (12µs+33µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 159
sub is_subtype_of {
1637788µs my ($self, $type_or_name) = @_;
164
16516µs34346µs my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
# spent 270µs making 17 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 16µs/call # spent 76µs making 17 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 4µs/call
166
167 my $current = $self;
168
1699895µs115273µs while (my $parent = $current->parent) {
# spent 202µs making 53 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 4µs/call # spent 71µs making 62 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call
170197µs531.52ms return 1 if $parent->equals($type);
# spent 1.52ms making 53 calls to Moose::Meta::TypeConstraint::equals, avg 29µs/call
171 $current = $parent;
172 }
173
174 return 0;
175}
176
177## compiling the type constraint
178
179
# spent 3.40ms (570µs+2.83) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 91 times, avg 37µs/call: # 34 times (183µs+1.40ms) by Moose::Meta::TypeConstraint::new at line 69, avg 47µs/call # 28 times (211µs+526µs) by Moose::Meta::TypeConstraint::Class::new at line 27 of Moose/Meta/TypeConstraint/Class.pm, avg 26µs/call # 22 times (127µs+332µs) by Moose::Meta::TypeConstraint::Role::new at line 27 of Moose/Meta/TypeConstraint/Role.pm, avg 21µs/call # 7 times (49µs+574µs) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 89µs/call
sub compile_type_constraint {
180182458µs my $self = shift;
181 $self->_compiled_type_constraint($self->_actually_compile_type_constraint);
# spent 2.61ms making 90 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 29µs/call # spent 204µs making 91 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 2µs/call # spent 20µs making 1 call to Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint
182}
183
184## type compilers ...
185
186
# spent 2.61ms (681µs+1.93) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 90 times, avg 29µs/call: # 90 times (681µs+1.93ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 181, avg 29µs/call
sub _actually_compile_type_constraint {
187253520µs my $self = shift;
188
189 return $self->_compile_hand_optimized_type_constraint
# spent 389µs making 66 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 6µs/call # spent 165µs making 90 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 2µs/call
190 if $self->has_hand_optimized_type_constraint;
191
192 my $check = $self->constraint;
# spent 36µs making 24 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
193 unless ( defined $check ) {
194 require Moose;
195 Moose->throw_error( "Could not compile type constraint '"
196 . $self->name
197 . "' because no constraint check" );
198 }
199
200 return $self->_compile_subtype($check)
# spent 1.27ms making 23 calls to Moose::Meta::TypeConstraint::_compile_subtype, avg 55µs/call # spent 37µs making 24 calls to Moose::Meta::TypeConstraint::has_parent, avg 2µs/call
201 if $self->has_parent;
202
203 return $self->_compile_type($check);
# spent 28µs making 1 call to Moose::Meta::TypeConstraint::_compile_type
204}
205
206
# spent 389µs (311+78) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 66 times, avg 6µs/call: # 66 times (311µs+78µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 189, avg 6µs/call
sub _compile_hand_optimized_type_constraint {
207264254µs my $self = shift;
208
209 my $type_constraint = $self->hand_optimized_type_constraint;
# spent 78µs making 66 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 1µs/call
210
211 unless ( ref $type_constraint ) {
212 require Moose;
213 Carp::confess ("Hand optimized type constraint for " . $self->name . " is not a code reference");
214 Moose->throw_error("Hand optimized type constraint is not a code reference");
215 }
216
217 return $type_constraint;
218}
219
220
# spent 1.27ms (555µs+720µs) within Moose::Meta::TypeConstraint::_compile_subtype which was called 23 times, avg 55µs/call: # 23 times (555µs+720µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 200, avg 55µs/call
sub _compile_subtype {
221138119µs my ($self, $check) = @_;
222
223 # gather all the parent constraintss in order
224 my @parents;
225 my $optimized_parent;
226 foreach my $parent ($self->_collect_all_parents) {
# spent 530µs making 23 calls to Moose::Meta::TypeConstraint::_collect_all_parents, avg 23µs/call
227 # if a parent is optimized, the optimized constraint already includes
228 # all of its parents tcs, so we can break the loop
22982102µs3243µs if ($parent->has_hand_optimized_type_constraint) {
# spent 43µs making 32 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call
230 push @parents => $optimized_parent = $parent->hand_optimized_type_constraint;
# spent 28µs making 18 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 2µs/call
231 last;
232 }
233 else {
234 push @parents => $parent->constraint;
# spent 15µs making 14 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
235 }
236 }
237
238 @parents = grep { $_ != $null_constraint } reverse @parents;
239
24043126µs unless ( @parents ) {
241 return $self->_compile_type($check);
242 } elsif( $optimized_parent and @parents == 1 ) {
243 # the case of just one optimized parent is optimized to prevent
244 # looping and the unnecessary localization
24511147µs if ( $check == $null_constraint ) {
246 return $optimized_parent;
247 } else {
248 return subname($self->name, sub {
24930864.66ms8485.48ms return undef unless $optimized_parent->($_[0]);
# spent 3.95ms making 88 calls to Moose::Util::TypeConstraints::OptimizedConstraints::Int, avg 45µs/call # spent 1.52ms making 758 calls to Moose::Util::TypeConstraints::OptimizedConstraints::Str, avg 2µs/call # spent 4µs making 2 calls to Moose::Util::TypeConstraints::OptimizedConstraints::HashRef, avg 2µs/call
250 my (@args) = @_;
251 local $_ = $args[0];
252 $check->(@args);
# spent 973µs making 571 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:89], avg 2µs/call # spent 391µs making 74 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:108], avg 5µs/call # spent 155µs making 28 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:112], avg 6µs/call # spent 142µs making 71 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:93], avg 2µs/call # spent 10µs making 2 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:770], avg 5µs/call
253 });
# spent 43µs making 11 calls to Sub::Name::subname, avg 4µs/call # spent 19µs making 11 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call
254 }
255 } else {
256 # general case, check all the constraints, from the first parent to ourselves
257 my @checks = @parents;
258 push @checks, $check if $check != $null_constraint;
259 return subname($self->name => sub {
260747649µs my (@args) = @_;
261 local $_ = $args[0];
262 foreach my $check (@checks) {
263370737µs3702.31ms return undef unless $check->(@args);
# spent 1.95ms making 154 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:749], avg 13µs/call # spent 259µs making 186 calls to Moose::Util::TypeConstraints::OptimizedConstraints::ArrayRef, avg 1µs/call # spent 44µs making 10 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:657], avg 4µs/call # spent 41µs making 15 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:650], avg 3µs/call # spent 20µs making 5 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:653], avg 4µs/call
264 }
265 return 1;
266 });
# spent 26µs making 10 calls to Sub::Name::subname, avg 3µs/call # spent 15µs making 10 calls to Moose::Meta::TypeConstraint::name, avg 1µs/call
267 }
268}
269
270
# spent 28µs (14+14) within Moose::Meta::TypeConstraint::_compile_type which was called # once (14µs+14µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 203
sub _compile_type {
271324µs my ($self, $check) = @_;
272
273 return $check if $check == $null_constraint; # Item, Any
274
275 return subname($self->name => sub {
276 my (@args) = @_;
277 local $_ = $args[0];
278 $check->(@args);
279 });
# spent 12µs making 1 call to Sub::Name::subname # spent 2µs making 1 call to Moose::Meta::TypeConstraint::name
280}
281
282## other utils ...
283
284
# spent 530µs (386+144) within Moose::Meta::TypeConstraint::_collect_all_parents which was called 23 times, avg 23µs/call: # 23 times (386µs+144µs) by Moose::Meta::TypeConstraint::_compile_subtype at line 226, avg 23µs/call
sub _collect_all_parents {
285115102µs my $self = shift;
286 my @parents;
287 my $current = $self->parent;
# spent 31µs making 23 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call
288 while (defined $current) {
289214133µs push @parents => $current;
290 $current = $current->parent;
# spent 113µs making 107 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call
291 }
292 return @parents;
293}
294
295
# spent 1.78ms (130µs+1.65) within Moose::Meta::TypeConstraint::create_child_type which was called 22 times, avg 81µs/call: # 17 times (95µs+950µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 523 of Moose/Util/TypeConstraints.pm, avg 62µs/call # 5 times (34µs+702µs) by MooseX::Types::TypeDecorator::AUTOLOAD at line 199 of MooseX/Types/TypeDecorator.pm, avg 147µs/call
sub create_child_type {
29666119µs my ($self, %opts) = @_;
297 my $class = ref $self;
298 return $class->new(%opts, parent => $self);
# spent 1.65ms making 22 calls to Moose::Meta::TypeConstraint::new, avg 75µs/call
299}
300
301125µs1;
302
303__END__
304
305=pod
306
307=head1 NAME
308
309Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
310
311=head1 DESCRIPTION
312
313This class represents a single type constraint. Moose's built-in type
314constraints, as well as constraints you define, are all stored in a
315L<Moose::Meta::TypeConstraint::Registry> object as objects of this
316class.
317
318=head1 INHERITANCE
319
320C<Moose::Meta::TypeConstraint> is a subclass of L<Class::MOP::Object>.
321
322=head1 METHODS
323
324=over 4
325
326=item B<< Moose::Meta::TypeConstraint->new(%options) >>
327
328This creates a new type constraint based on the provided C<%options>:
329
330=over 8
331
332=item * name
333
334The constraint name. If a name is not provided, it will be set to
335"__ANON__".
336
337=item * parent
338
339A C<Moose::Meta::TypeConstraint> object which is the parent type for
340the type being created. This is optional.
341
342=item * constraint
343
344This is the subroutine reference that implements the actual constraint
345check. This defaults to a subroutine which always returns true.
346
347=item * message
348
349A subroutine reference which is used to generate an error message when
350the constraint fails. This is optional.
351
352=item * coercion
353
354A L<Moose::Meta::TypeCoercion> object representing the coercions to
355the type. This is optional.
356
357=item * optimized
358
359This is a variant of the C<constraint> parameter that is somehow
360optimized. Typically, this means incorporating both the type's
361constraint and all of its parents' constraints into a single
362subroutine reference.
363
364=back
365
366=item B<< $constraint->equals($type_name_or_object) >>
367
368Returns true if the supplied name or type object is the same as the
369current type.
370
371=item B<< $constraint->is_subtype_of($type_name_or_object) >>
372
373Returns true if the supplied name or type object is a parent of the
374current type.
375
376=item B<< $constraint->is_a_type_of($type_name_or_object) >>
377
378Returns true if the given type is the same as the current type, or is
379a parent of the current type. This is a shortcut for checking
380C<equals> and C<is_subtype_of>.
381
382=item B<< $constraint->coerce($value) >>
383
384This will attempt to coerce the value to the type. If the type does
385have any defined coercions this will throw an error.
386
387=item B<< $constraint->check($value) >>
388
389Returns true if the given value passes the constraint for the type.
390
391=item B<< $constraint->validate($value) >>
392
393This is similar to C<check>. However, if the type I<is valid> then the
394method returns an explicit C<undef>. If the type is not valid, we call
395C<< $self->get_message($value) >> internally to generate an error
396message.
397
398=item B<< $constraint->assert_valid($value) >>
399
400Like C<check> and C<validate>, this method checks whether C<$value> is
401valid under the constraint. If it is, it will return true. If it is not,
402an exception will be thrown with the results of
403C<< $self->get_message($value) >>.
404
405=item B<< $constraint->name >>
406
407Returns the type's name, as provided to the constructor.
408
409=item B<< $constraint->parent >>
410
411Returns the type's parent, as provided to the constructor, if any.
412
413=item B<< $constraint->has_parent >>
414
415Returns true if the type has a parent type.
416
417=item B<< $constraint->parents >>
418
419A synonym for C<parent>. This is useful for polymorphism with types
420that can have more than one parent.
421
422=item B<< $constraint->constraint >>
423
424Returns the type's constraint, as provided to the constructor.
425
426=item B<< $constraint->get_message($value) >>
427
428This generates a method for the given value. If the type does not have
429an explicit message, we generate a default message.
430
431=item B<< $constraint->has_message >>
432
433Returns true if the type has a message.
434
435=item B<< $constraint->message >>
436
437Returns the type's message as a subroutine reference.
438
439=item B<< $constraint->coercion >>
440
441Returns the type's L<Moose::Meta::TypeCoercion> object, if one
442exists.
443
444=item B<< $constraint->has_coercion >>
445
446Returns true if the type has a coercion.
447
448=item B<< $constraint->hand_optimized_type_constraint >>
449
450Returns the type's hand optimized constraint, as provided to the
451constructor via the C<optimized> option.
452
453=item B<< $constraint->has_hand_optimized_type_constraint >>
454
455Returns true if the type has an optimized constraint.
456
457=item B<< $constraint->create_child_type(%options) >>
458
459This returns a new type constraint of the same class using the
460provided C<%options>. The C<parent> option will be the current type.
461
462This method exists so that subclasses of this class can override this
463behavior and change how child types are created.
464
465=back
466
467=head1 BUGS
468
469See L<Moose/BUGS> for details on reporting bugs.
470
471=head1 AUTHOR
472
473Stevan Little E<lt>stevan@iinteractive.comE<gt>
474
475=head1 COPYRIGHT AND LICENSE
476
477Copyright 2006-2010 by Infinity Interactive, Inc.
478
479L<http://www.iinteractive.com>
480
481This library is free software; you can redistribute it and/or modify
482it under the same terms as Perl itself.
483
484=cut