Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm |
Statements | Executed 1556 statements in 5.96ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
33 | 8 | 5 | 1.06ms | 11.6ms | new | Moose::Meta::TypeConstraint::
110 | 5 | 2 | 895µs | 1.38ms | can_be_inlined (recurses: max depth 1, inclusive time 19µs) | Moose::Meta::TypeConstraint::
56 | 8 | 3 | 776µs | 2.12ms | _inline_check (recurses: max depth 2, inclusive time 307µs) | Moose::Meta::TypeConstraint::
45 | 1 | 1 | 641µs | 9.66ms | _actually_compile_type_constraint | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 417µs | 1.28ms | BEGIN@12 | Moose::Meta::TypeConstraint::
47 | 3 | 2 | 411µs | 608µs | inline_environment (recurses: max depth 1, inclusive time 8µs) | Moose::Meta::TypeConstraint::
45 | 3 | 3 | 301µs | 10.2ms | compile_type_constraint | Moose::Meta::TypeConstraint::
33 | 1 | 1 | 156µs | 156µs | __ANON__[:77] | Moose::Meta::TypeConstraint::
91 | 4 | 2 | 102µs | 102µs | __ANON__[:16] | Moose::Meta::TypeConstraint::
16 | 1 | 1 | 93µs | 4.32ms | create_child_type | Moose::Meta::TypeConstraint::
33 | 4 | 4 | 66µs | 66µs | __ANON__[:101] | Moose::Meta::TypeConstraint::
3 | 1 | 1 | 35µs | 85µs | check | Moose::Meta::TypeConstraint::
4 | 1 | 1 | 22µs | 27µs | _compile_hand_optimized_type_constraint | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 16µs | 68µs | BEGIN@14 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 10µs | 10µs | BEGIN@3 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 9µs | 14µs | BEGIN@10 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 9µs | 270µs | BEGIN@21 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 9µs | 41µs | BEGIN@19 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 8µs | 83µs | BEGIN@26 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 8µs | 24µs | BEGIN@11 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 8µs | 33µs | BEGIN@22 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 8µs | 27µs | BEGIN@20 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 7µs | 36µs | BEGIN@24 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 7µs | 26µs | BEGIN@23 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 2µs | 2µs | __ANON__[:42] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:14] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:15] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:387] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:38] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:400] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:413] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:68] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:76] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _collect_all_parents | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _compile_subtype | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _compile_type | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | assert_coerce | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | assert_valid | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | coerce | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | equals | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | get_message | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | is_a_type_of | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | is_subtype_of | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | parents | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | validate | Moose::Meta::TypeConstraint::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Moose::Meta::TypeConstraint; | ||||
3 | # spent 10µs within Moose::Meta::TypeConstraint::BEGIN@3 which was called:
# once (10µs+0s) by Moose::BEGIN@29 at line 5 | ||||
4 | 1 | 4µs | $Moose::Meta::TypeConstraint::AUTHORITY = 'cpan:STEVAN'; | ||
5 | 1 | 24µs | 1 | 10µs | } # spent 10µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@3 |
6 | { | ||||
7 | 2 | 2µs | $Moose::Meta::TypeConstraint::VERSION = '2.0602'; | ||
8 | } | ||||
9 | |||||
10 | 3 | 20µs | 2 | 19µs | # spent 14µs (9+5) within Moose::Meta::TypeConstraint::BEGIN@10 which was called:
# once (9µs+5µs) by Moose::BEGIN@29 at line 10 # spent 14µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@10
# spent 5µs making 1 call to strict::import |
11 | 3 | 19µs | 2 | 40µs | # spent 24µs (8+16) within Moose::Meta::TypeConstraint::BEGIN@11 which was called:
# once (8µs+16µs) by Moose::BEGIN@29 at line 11 # spent 24µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11
# spent 16µs making 1 call to warnings::import |
12 | 3 | 156µs | 2 | 1.96ms | # spent 1.28ms (417µs+861µs) within Moose::Meta::TypeConstraint::BEGIN@12 which was called:
# once (417µs+861µs) by Moose::BEGIN@29 at line 12 # spent 1.28ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@12
# spent 681µs making 1 call to metaclass::import |
13 | |||||
14 | # spent 68µs (16+53) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (16µs+53µs) by Moose::BEGIN@29 at line 17 | ||||
15 | '""' => sub { shift->name }, # stringify to tc name | ||||
16 | 91 | 225µs | # spent 102µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:16] which was called 91 times, avg 1µs/call:
# 33 times (42µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 51 of Moose/Meta/TypeConstraint/Registry.pm, avg 1µs/call
# 21 times (30µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274 of Moose/Util/TypeConstraints.pm, avg 1µs/call
# 21 times (19µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 905ns/call
# 16 times (11µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 675ns/call | ||
17 | 3 | 31µs | 2 | 121µs | fallback => 1; # spent 68µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 53µs making 1 call to overload::import |
18 | |||||
19 | 3 | 21µs | 2 | 74µs | # spent 41µs (9+33) within Moose::Meta::TypeConstraint::BEGIN@19 which was called:
# once (9µs+33µs) by Moose::BEGIN@29 at line 19 # spent 41µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@19
# spent 33µs making 1 call to Exporter::import |
20 | 3 | 22µs | 2 | 46µs | # spent 27µs (8+19) within Moose::Meta::TypeConstraint::BEGIN@20 which was called:
# once (8µs+19µs) by Moose::BEGIN@29 at line 20 # spent 27µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20
# spent 19µs making 1 call to Exporter::import |
21 | 3 | 25µs | 2 | 531µs | # spent 270µs (9+261) within Moose::Meta::TypeConstraint::BEGIN@21 which was called:
# once (9µs+261µs) by Moose::BEGIN@29 at line 21 # spent 270µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@21
# spent 261µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
22 | 3 | 20µs | 2 | 59µs | # spent 33µs (8+26) within Moose::Meta::TypeConstraint::BEGIN@22 which was called:
# once (8µs+26µs) by Moose::BEGIN@29 at line 22 # spent 33µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@22
# spent 26µs making 1 call to Exporter::import |
23 | 3 | 18µs | 2 | 45µs | # spent 26µs (7+19) within Moose::Meta::TypeConstraint::BEGIN@23 which was called:
# once (7µs+19µs) by Moose::BEGIN@29 at line 23 # spent 26µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@23
# spent 19µs making 1 call to Exporter::import |
24 | 3 | 18µs | 2 | 66µs | # spent 36µs (7+29) within Moose::Meta::TypeConstraint::BEGIN@24 which was called:
# once (7µs+29µs) by Moose::BEGIN@29 at line 24 # spent 36µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@24
# spent 29µs making 1 call to Exporter::import |
25 | |||||
26 | 3 | 1.59ms | 2 | 158µs | # spent 83µs (8+75) within Moose::Meta::TypeConstraint::BEGIN@26 which was called:
# once (8µs+75µs) by Moose::BEGIN@29 at line 26 # spent 83µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@26
# spent 75µs making 1 call to base::import |
27 | |||||
28 | 1 | 7µs | 3 | 679µs | __PACKAGE__->meta->add_attribute('name' => ( # spent 637µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 32µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 10µs making 1 call to Class::MOP::_definition_context |
29 | reader => 'name', | ||||
30 | Class::MOP::_definition_context(), | ||||
31 | )); | ||||
32 | 1 | 4µs | 3 | 468µs | __PACKAGE__->meta->add_attribute('parent' => ( # spent 450µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
33 | reader => 'parent', | ||||
34 | predicate => 'has_parent', | ||||
35 | Class::MOP::_definition_context(), | ||||
36 | )); | ||||
37 | |||||
38 | 1 | 2µs | my $null_constraint = sub { 1 }; | ||
39 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
40 | reader => 'constraint', | ||||
41 | writer => '_set_constraint', | ||||
42 | 1 | 7µs | # spent 2µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:42] which was called:
# once (2µs+0s) by Moose::Meta::TypeConstraint::_new at line 24 of (eval 87)[Eval/Closure.pm:125] | ||
43 | 1 | 5µs | 3 | 455µs | Class::MOP::_definition_context(), # spent 440µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
44 | )); | ||||
45 | |||||
46 | 1 | 4µs | 3 | 435µs | __PACKAGE__->meta->add_attribute('message' => ( # spent 418µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
47 | accessor => 'message', | ||||
48 | predicate => 'has_message', | ||||
49 | Class::MOP::_definition_context(), | ||||
50 | )); | ||||
51 | |||||
52 | 1 | 4µs | 3 | 288µs | __PACKAGE__->meta->add_attribute('_default_message' => ( # spent 274µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
53 | accessor => '_default_message', | ||||
54 | Class::MOP::_definition_context(), | ||||
55 | )); | ||||
56 | |||||
57 | # can't make this a default because it has to close over the type name, and | ||||
58 | # cmop attributes don't have lazy | ||||
59 | # spent 156µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:77] which was called 33 times, avg 5µs/call:
# 33 times (156µs+0s) by Moose::Meta::TypeConstraint::new at line 146, avg 5µs/call | ||||
60 | 66 | 182µs | my $name = shift; | ||
61 | sub { | ||||
62 | my $value = shift; | ||||
63 | # have to load it late like this, since it uses Moose itself | ||||
64 | my $can_partialdump = try { | ||||
65 | # versions prior to 0.14 had a potential infinite loop bug | ||||
66 | load_class('Devel::PartialDump', { -version => 0.14 }); | ||||
67 | 1; | ||||
68 | }; | ||||
69 | if ($can_partialdump) { | ||||
70 | $value = Devel::PartialDump->new->dump($value); | ||||
71 | } | ||||
72 | else { | ||||
73 | $value = (defined $value ? overload::StrVal($value) : 'undef'); | ||||
74 | } | ||||
75 | return "Validation failed for '" . $name . "' with value $value"; | ||||
76 | } | ||||
77 | 1 | 2µs | }; | ||
78 | 1 | 4µs | 3 | 421µs | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 406µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
79 | accessor => 'coercion', | ||||
80 | predicate => 'has_coercion', | ||||
81 | Class::MOP::_definition_context(), | ||||
82 | )); | ||||
83 | |||||
84 | 1 | 4µs | 3 | 458µs | __PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => ( # spent 444µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
85 | init_arg => 'optimized', | ||||
86 | accessor => 'hand_optimized_type_constraint', | ||||
87 | predicate => 'has_hand_optimized_type_constraint', | ||||
88 | Class::MOP::_definition_context(), | ||||
89 | )); | ||||
90 | |||||
91 | 1 | 4µs | 3 | 434µs | __PACKAGE__->meta->add_attribute('inlined' => ( # spent 419µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
92 | init_arg => 'inlined', | ||||
93 | accessor => 'inlined', | ||||
94 | predicate => '_has_inlined_type_constraint', | ||||
95 | Class::MOP::_definition_context(), | ||||
96 | )); | ||||
97 | |||||
98 | __PACKAGE__->meta->add_attribute('inline_environment' => ( | ||||
99 | init_arg => 'inline_environment', | ||||
100 | accessor => '_inline_environment', | ||||
101 | 33 | 108µs | # spent 66µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:101] which was called 33 times, avg 2µs/call:
# 17 times (27µs+0s) by Moose::Meta::TypeConstraint::_new at line 33 of (eval 87)[Eval/Closure.pm:125], avg 2µs/call
# 8 times (23µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 36 of (eval 101)[Eval/Closure.pm:125], avg 3µs/call
# 4 times (10µs+0s) by Moose::Meta::TypeConstraint::Role::_new at line 33 of (eval 103)[Eval/Closure.pm:125], avg 2µs/call
# 4 times (6µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::_new at line 36 of (eval 99)[Eval/Closure.pm:125], avg 1µs/call | ||
102 | 1 | 7µs | 3 | 461µs | Class::MOP::_definition_context(), # spent 446µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
103 | )); | ||||
104 | |||||
105 | sub parents { | ||||
106 | my $self = shift; | ||||
107 | $self->parent; | ||||
108 | } | ||||
109 | |||||
110 | # private accessors | ||||
111 | |||||
112 | 1 | 8µs | 3 | 539µs | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 507µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 10µs making 1 call to Class::MOP::_definition_context |
113 | accessor => '_compiled_type_constraint', | ||||
114 | predicate => '_has_compiled_type_constraint', | ||||
115 | Class::MOP::_definition_context(), | ||||
116 | )); | ||||
117 | |||||
118 | 1 | 4µs | 3 | 289µs | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 274µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
119 | accessor => '_package_defined_in', | ||||
120 | Class::MOP::_definition_context(), | ||||
121 | )); | ||||
122 | |||||
123 | # spent 11.6ms (1.06+10.6) within Moose::Meta::TypeConstraint::new which was called 33 times, avg 352µs/call:
# 16 times (360µs+3.87ms) by Moose::Meta::TypeConstraint::create_child_type at line 432, avg 264µs/call
# 8 times (374µs+3.85ms) by Moose::Meta::TypeConstraint::Class::new at line 43 of Moose/Meta/TypeConstraint/Class.pm, avg 528µs/call
# 4 times (167µs+1.61ms) by Moose::Meta::TypeConstraint::Role::new at line 44 of Moose/Meta/TypeConstraint/Role.pm, avg 444µs/call
# once (40µs+376µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 185 of Moose/Util/TypeConstraints/Builtins.pm
# once (42µs+330µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 575 of Moose/Util/TypeConstraints.pm
# once (24µs+180µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 255 of Moose/Util/TypeConstraints/Builtins.pm
# once (24µs+180µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 220 of Moose/Util/TypeConstraints/Builtins.pm
# once (24µs+171µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 281 of Moose/Util/TypeConstraints/Builtins.pm | ||||
124 | 330 | 921µs | my $class = shift; | ||
125 | my ($first, @rest) = @_; | ||||
126 | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||||
127 | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; | ||||
128 | |||||
129 | if ( $args{optimized} ) { | ||||
130 | Moose::Deprecated::deprecated( | ||||
131 | feature => 'optimized type constraint sub ref', | ||||
132 | message => | ||||
133 | 'Providing an optimized subroutine ref for type constraints is deprecated.' | ||||
134 | . ' Use the inlining feature (inline_as) instead.' | ||||
135 | ); | ||||
136 | } | ||||
137 | |||||
138 | if ( exists $args{message} | ||||
139 | && (!ref($args{message}) || ref($args{message}) ne 'CODE') ) { | ||||
140 | confess("The 'message' parameter must be a coderef"); | ||||
141 | } | ||||
142 | |||||
143 | 33 | 1.89ms | my $self = $class->_new(%args); # spent 904µs making 8 calls to Moose::Meta::TypeConstraint::Class::_new, avg 113µs/call
# spent 410µs making 4 calls to Moose::Meta::TypeConstraint::Role::_new, avg 102µs/call
# spent 389µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 23µs/call
# spent 190µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 47µs/call | ||
144 | 66 | 8.30ms | $self->compile_type_constraint() # spent 8.22ms making 33 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 249µs/call
# spent 74µs making 33 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call | ||
145 | unless $self->_has_compiled_type_constraint; | ||||
146 | 132 | 375µs | $self->_default_message($_default_message_generator->($self->name)) # spent 156µs making 33 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:77], avg 5µs/call
# spent 89µs making 33 calls to Moose::Meta::TypeConstraint::_default_message, avg 3µs/call
# spent 69µs making 33 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call
# spent 60µs making 33 calls to Moose::Meta::TypeConstraint::has_message, avg 2µs/call | ||
147 | unless $self->has_message; | ||||
148 | return $self; | ||||
149 | } | ||||
150 | |||||
- - | |||||
153 | sub coerce { | ||||
154 | my $self = shift; | ||||
155 | |||||
156 | my $coercion = $self->coercion; | ||||
157 | |||||
158 | unless ($coercion) { | ||||
159 | require Moose; | ||||
160 | Moose->throw_error("Cannot coerce without a type coercion"); | ||||
161 | } | ||||
162 | |||||
163 | return $_[0] if $self->check($_[0]); | ||||
164 | |||||
165 | return $coercion->coerce(@_); | ||||
166 | } | ||||
167 | |||||
168 | sub assert_coerce { | ||||
169 | my $self = shift; | ||||
170 | |||||
171 | my $coercion = $self->coercion; | ||||
172 | |||||
173 | unless ($coercion) { | ||||
174 | require Moose; | ||||
175 | Moose->throw_error("Cannot coerce without a type coercion"); | ||||
176 | } | ||||
177 | |||||
178 | return $_[0] if $self->check($_[0]); | ||||
179 | |||||
180 | my $result = $coercion->coerce(@_); | ||||
181 | |||||
182 | $self->assert_valid($result); | ||||
183 | |||||
184 | return $result; | ||||
185 | } | ||||
186 | |||||
187 | # spent 85µs (35+51) within Moose::Meta::TypeConstraint::check which was called 3 times, avg 28µs/call:
# 3 times (35µs+51µs) by Moose::Meta::Attribute::verify_against_type_constraint at line 1275 of Moose/Meta/Attribute.pm, avg 28µs/call | ||||
188 | 9 | 28µs | my ($self, @args) = @_; | ||
189 | 3 | 8µs | my $constraint_subref = $self->_compiled_type_constraint; # spent 8µs making 3 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 3µs/call | ||
190 | 3 | 43µs | return $constraint_subref->(@args) ? 1 : undef; # spent 29µs making 1 call to Eval::Closure::Sandbox_161::__ANON__[(eval 265)[Eval/Closure.pm:125]:3]
# spent 11µs making 1 call to Eval::Closure::Sandbox_157::__ANON__[(eval 259)[Eval/Closure.pm:125]:3]
# spent 3µs making 1 call to Eval::Closure::Sandbox_65::__ANON__[(eval 133)[Eval/Closure.pm:125]:3] | ||
191 | } | ||||
192 | |||||
193 | sub validate { | ||||
194 | my ($self, $value) = @_; | ||||
195 | if ($self->_compiled_type_constraint->($value)) { | ||||
196 | return undef; | ||||
197 | } | ||||
198 | else { | ||||
199 | $self->get_message($value); | ||||
200 | } | ||||
201 | } | ||||
202 | |||||
203 | # spent 1.38ms (895µs+485µs) within Moose::Meta::TypeConstraint::can_be_inlined which was called 110 times, avg 13µs/call:
# 56 times (361µs+200µs) by Moose::Meta::TypeConstraint::_inline_check at line 216, avg 10µs/call
# 41 times (405µs+226µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 320, avg 15µs/call
# 6 times (78µs+47µs) by Moose::Meta::Attribute::_inline_check_constraint at line 707 of Moose/Meta/Attribute.pm, avg 21µs/call
# 5 times (40µs+22µs) by Moose::Meta::Attribute::_eval_environment at line 785 of Moose/Meta/Attribute.pm, avg 12µs/call
# 2 times (11µs+-11µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 206, avg 0s/call | ||||
204 | 328 | 686µs | my $self = shift; | ||
205 | |||||
206 | 219 | 329µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 164µs making 105 calls to Moose::Meta::TypeConstraint::constraint, avg 2µs/call
# spent 161µs making 110 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 4µs making 2 calls to Moose::Meta::TypeConstraint::parent, avg 2µs/call
# spent 19µs making 2 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 10µs/call, recursion: max depth 1, sum of overlapping time 19µs | ||
207 | return $self->parent->can_be_inlined; | ||||
208 | } | ||||
209 | |||||
210 | 108 | 156µs | return $self->_has_inlined_type_constraint; # spent 156µs making 108 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 1µs/call | ||
211 | } | ||||
212 | |||||
213 | # spent 2.12ms (776µs+1.34) within Moose::Meta::TypeConstraint::_inline_check which was called 56 times, avg 38µs/call:
# 41 times (591µs+1.27ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 320, avg 45µs/call
# 6 times (91µs+167µs) by Moose::Meta::Attribute::_inline_check_constraint at line 707 of Moose/Meta/Attribute.pm, avg 43µs/call
# 4 times (44µs+-44µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:66] at line 64 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# once (10µs+-10µs) by Moose::Meta::TypeConstraint::_inline_check at line 221
# once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:157] at line 152 of Moose/Util/TypeConstraints/Builtins.pm
# once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:101] at line 99 of Moose/Util/TypeConstraints/Builtins.pm
# once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:93] at line 91 of Moose/Util/TypeConstraints/Builtins.pm
# once (11µs+-11µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:83] at line 78 of Moose/Util/TypeConstraints/Builtins.pm | ||||
214 | 223 | 565µs | my $self = shift; | ||
215 | |||||
216 | 56 | 562µs | unless ( $self->can_be_inlined ) { # spent 562µs making 56 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 10µs/call | ||
217 | require Moose; | ||||
218 | Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name ); | ||||
219 | } | ||||
220 | |||||
221 | 112 | 123µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 62µs making 56 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 61µs making 54 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent
# spent 20µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 20µs | ||
222 | return $self->parent->_inline_check(@_); | ||||
223 | } | ||||
224 | |||||
225 | 110 | 942µs | return '( do { ' . $self->inlined->( $self, @_ ) . ' } )'; # spent 366µs making 20 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:30], avg 18µs/call
# spent 133µs making 4 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66], avg 33µs/call
# spent 94µs making 55 calls to Moose::Meta::TypeConstraint::inlined, avg 2µs/call
# spent 73µs making 4 calls to Moose::Meta::TypeConstraint::Role::__ANON__[Moose/Meta/TypeConstraint/Role.pm:32], avg 18µs/call
# spent 68µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:83]
# spent 60µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:93]
# spent 59µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:101]
# spent 36µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157]
# spent 9µs making 5 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:46], avg 2µs/call
# spent 6µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:239], avg 3µs/call
# spent 5µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:204], avg 3µs/call
# spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:58]
# spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:133]
# spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:176]
# spent 4µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:144], avg 2µs/call
# spent 3µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:28], avg 1µs/call
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:113]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:106]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:39]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:138]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:72]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:118]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:272] | ||
226 | } | ||||
227 | |||||
228 | # spent 608µs (411+197) within Moose::Meta::TypeConstraint::inline_environment which was called 47 times, avg 13µs/call:
# 41 times (354µs+180µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 320, avg 13µs/call
# 5 times (52µs+23µs) by Moose::Meta::Attribute::_eval_environment at line 796 of Moose/Meta/Attribute.pm, avg 15µs/call
# once (6µs+-6µs) by Moose::Meta::TypeConstraint::inline_environment at line 231 | ||||
229 | 140 | 304µs | my $self = shift; | ||
230 | |||||
231 | 94 | 111µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 56µs making 45 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 54µs making 47 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent
# spent 8µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 8µs | ||
232 | return $self->parent->inline_environment; | ||||
233 | } | ||||
234 | |||||
235 | 46 | 86µs | return $self->_inline_environment; # spent 86µs making 46 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 2µs/call | ||
236 | } | ||||
237 | |||||
238 | sub assert_valid { | ||||
239 | my ($self, $value) = @_; | ||||
240 | |||||
241 | my $error = $self->validate($value); | ||||
242 | return 1 if ! defined $error; | ||||
243 | |||||
244 | require Moose; | ||||
245 | Moose->throw_error($error); | ||||
246 | } | ||||
247 | |||||
248 | sub get_message { | ||||
249 | my ($self, $value) = @_; | ||||
250 | my $msg = $self->has_message | ||||
251 | ? $self->message | ||||
252 | : $self->_default_message; | ||||
253 | local $_ = $value; | ||||
254 | return $msg->($value); | ||||
255 | } | ||||
256 | |||||
257 | ## type predicates ... | ||||
258 | |||||
259 | sub equals { | ||||
260 | my ( $self, $type_or_name ) = @_; | ||||
261 | |||||
262 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; | ||||
263 | |||||
264 | return 1 if $self == $other; | ||||
265 | |||||
266 | if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) { | ||||
267 | return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint; | ||||
268 | } | ||||
269 | |||||
270 | return unless $self->constraint == $other->constraint; | ||||
271 | |||||
272 | if ( $self->has_parent ) { | ||||
273 | return unless $other->has_parent; | ||||
274 | return unless $self->parent->equals( $other->parent ); | ||||
275 | } else { | ||||
276 | return if $other->has_parent; | ||||
277 | } | ||||
278 | |||||
279 | return; | ||||
280 | } | ||||
281 | |||||
282 | sub is_a_type_of { | ||||
283 | my ($self, $type_or_name) = @_; | ||||
284 | |||||
285 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; | ||||
286 | |||||
287 | ($self->equals($type) || $self->is_subtype_of($type)); | ||||
288 | } | ||||
289 | |||||
290 | sub is_subtype_of { | ||||
291 | my ($self, $type_or_name) = @_; | ||||
292 | |||||
293 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; | ||||
294 | |||||
295 | my $current = $self; | ||||
296 | |||||
297 | while (my $parent = $current->parent) { | ||||
298 | return 1 if $parent->equals($type); | ||||
299 | $current = $parent; | ||||
300 | } | ||||
301 | |||||
302 | return 0; | ||||
303 | } | ||||
304 | |||||
305 | ## compiling the type constraint | ||||
306 | |||||
307 | # spent 10.2ms (301µs+9.86) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 45 times, avg 226µs/call:
# 33 times (234µs+7.99ms) by Moose::Meta::TypeConstraint::new at line 144, avg 249µs/call
# 8 times (49µs+1.79ms) by Moose::Meta::TypeConstraint::Class::new at line 45 of Moose/Meta/TypeConstraint/Class.pm, avg 230µs/call
# 4 times (18µs+83µs) by Moose::Meta::TypeConstraint::Role::new at line 47 of Moose/Meta/TypeConstraint/Role.pm, avg 25µs/call | ||||
308 | 90 | 260µs | my $self = shift; | ||
309 | 90 | 9.86ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 9.66ms making 45 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 215µs/call
# spent 200µs making 45 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 4µs/call | ||
310 | } | ||||
311 | |||||
312 | ## type compilers ... | ||||
313 | |||||
314 | # spent 9.66ms (641µs+9.02) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 45 times, avg 215µs/call:
# 45 times (641µs+9.02ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 309, avg 215µs/call | ||||
315 | 131 | 502µs | my $self = shift; | ||
316 | |||||
317 | 49 | 114µs | return $self->_compile_hand_optimized_type_constraint # spent 88µs making 45 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 2µs/call
# spent 27µs making 4 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 7µs/call | ||
318 | if $self->has_hand_optimized_type_constraint; | ||||
319 | |||||
320 | 164 | 8.91ms | if ( $self->can_be_inlined ) { # spent 5.88ms making 41 calls to Eval::Closure::eval_closure, avg 143µs/call
# spent 1.86ms making 41 calls to Moose::Meta::TypeConstraint::_inline_check, avg 45µs/call
# spent 632µs making 41 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 15µs/call
# spent 534µs making 41 calls to Moose::Meta::TypeConstraint::inline_environment, avg 13µs/call | ||
321 | return eval_closure( | ||||
322 | source => 'sub { ' . $self->_inline_check('$_[0]') . ' }', | ||||
323 | environment => $self->inline_environment, | ||||
324 | ); | ||||
325 | } | ||||
326 | |||||
327 | my $check = $self->constraint; | ||||
328 | unless ( defined $check ) { | ||||
329 | require Moose; | ||||
330 | Moose->throw_error( "Could not compile type constraint '" | ||||
331 | . $self->name | ||||
332 | . "' because no constraint check" ); | ||||
333 | } | ||||
334 | |||||
335 | return $self->_compile_subtype($check) | ||||
336 | if $self->has_parent; | ||||
337 | |||||
338 | return $self->_compile_type($check); | ||||
339 | } | ||||
340 | |||||
341 | # spent 27µs (22+5) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 4 times, avg 7µs/call:
# 4 times (22µs+5µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 317, avg 7µs/call | ||||
342 | 16 | 20µs | my $self = shift; | ||
343 | |||||
344 | 4 | 5µs | my $type_constraint = $self->hand_optimized_type_constraint; # spent 5µs making 4 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 1µs/call | ||
345 | |||||
346 | unless ( ref $type_constraint ) { | ||||
347 | require Moose; | ||||
348 | Moose->throw_error("Hand optimized type constraint is not a code reference"); | ||||
349 | } | ||||
350 | |||||
351 | return $type_constraint; | ||||
352 | } | ||||
353 | |||||
354 | sub _compile_subtype { | ||||
355 | my ($self, $check) = @_; | ||||
356 | |||||
357 | # gather all the parent constraintss in order | ||||
358 | my @parents; | ||||
359 | my $optimized_parent; | ||||
360 | foreach my $parent ($self->_collect_all_parents) { | ||||
361 | # if a parent is optimized, the optimized constraint already includes | ||||
362 | # all of its parents tcs, so we can break the loop | ||||
363 | if ($parent->has_hand_optimized_type_constraint) { | ||||
364 | push @parents => $optimized_parent = $parent->hand_optimized_type_constraint; | ||||
365 | last; | ||||
366 | } | ||||
367 | else { | ||||
368 | push @parents => $parent->constraint; | ||||
369 | } | ||||
370 | } | ||||
371 | |||||
372 | @parents = grep { $_ != $null_constraint } reverse @parents; | ||||
373 | |||||
374 | unless ( @parents ) { | ||||
375 | return $self->_compile_type($check); | ||||
376 | } elsif( $optimized_parent and @parents == 1 ) { | ||||
377 | # the case of just one optimized parent is optimized to prevent | ||||
378 | # looping and the unnecessary localization | ||||
379 | if ( $check == $null_constraint ) { | ||||
380 | return $optimized_parent; | ||||
381 | } else { | ||||
382 | return subname($self->name, sub { | ||||
383 | return undef unless $optimized_parent->($_[0]); | ||||
384 | my (@args) = @_; | ||||
385 | local $_ = $args[0]; | ||||
386 | $check->(@args); | ||||
387 | }); | ||||
388 | } | ||||
389 | } else { | ||||
390 | # general case, check all the constraints, from the first parent to ourselves | ||||
391 | my @checks = @parents; | ||||
392 | push @checks, $check if $check != $null_constraint; | ||||
393 | return subname($self->name => sub { | ||||
394 | my (@args) = @_; | ||||
395 | local $_ = $args[0]; | ||||
396 | foreach my $check (@checks) { | ||||
397 | return undef unless $check->(@args); | ||||
398 | } | ||||
399 | return 1; | ||||
400 | }); | ||||
401 | } | ||||
402 | } | ||||
403 | |||||
404 | sub _compile_type { | ||||
405 | my ($self, $check) = @_; | ||||
406 | |||||
407 | return $check if $check == $null_constraint; # Item, Any | ||||
408 | |||||
409 | return subname($self->name => sub { | ||||
410 | my (@args) = @_; | ||||
411 | local $_ = $args[0]; | ||||
412 | $check->(@args); | ||||
413 | }); | ||||
414 | } | ||||
415 | |||||
416 | ## other utils ... | ||||
417 | |||||
418 | sub _collect_all_parents { | ||||
419 | my $self = shift; | ||||
420 | my @parents; | ||||
421 | my $current = $self->parent; | ||||
422 | while (defined $current) { | ||||
423 | push @parents => $current; | ||||
424 | $current = $current->parent; | ||||
425 | } | ||||
426 | return @parents; | ||||
427 | } | ||||
428 | |||||
429 | # spent 4.32ms (93µs+4.23) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 270µs/call:
# 16 times (93µs+4.23ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 270µs/call | ||||
430 | 48 | 91µs | my ($self, %opts) = @_; | ||
431 | my $class = ref $self; | ||||
432 | 16 | 4.23ms | return $class->new(%opts, parent => $self); # spent 4.23ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 264µs/call | ||
433 | } | ||||
434 | |||||
435 | 1 | 34µs | 1; | ||
436 | |||||
437 | # ABSTRACT: The Moose Type Constraint metaclass | ||||
438 | |||||
- - | |||||
441 | =pod | ||||
442 | |||||
443 | =head1 NAME | ||||
444 | |||||
445 | Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass | ||||
446 | |||||
447 | =head1 VERSION | ||||
448 | |||||
449 | version 2.0602 | ||||
450 | |||||
451 | =head1 DESCRIPTION | ||||
452 | |||||
453 | This class represents a single type constraint. Moose's built-in type | ||||
454 | constraints, as well as constraints you define, are all stored in a | ||||
455 | L<Moose::Meta::TypeConstraint::Registry> object as objects of this | ||||
456 | class. | ||||
457 | |||||
458 | =head1 INHERITANCE | ||||
459 | |||||
460 | C<Moose::Meta::TypeConstraint> is a subclass of L<Class::MOP::Object>. | ||||
461 | |||||
462 | =head1 METHODS | ||||
463 | |||||
464 | =over 4 | ||||
465 | |||||
466 | =item B<< Moose::Meta::TypeConstraint->new(%options) >> | ||||
467 | |||||
468 | This creates a new type constraint based on the provided C<%options>: | ||||
469 | |||||
470 | =over 8 | ||||
471 | |||||
472 | =item * name | ||||
473 | |||||
474 | The constraint name. If a name is not provided, it will be set to | ||||
475 | "__ANON__". | ||||
476 | |||||
477 | =item * parent | ||||
478 | |||||
479 | A C<Moose::Meta::TypeConstraint> object which is the parent type for | ||||
480 | the type being created. This is optional. | ||||
481 | |||||
482 | =item * constraint | ||||
483 | |||||
484 | This is the subroutine reference that implements the actual constraint | ||||
485 | check. This defaults to a subroutine which always returns true. | ||||
486 | |||||
487 | =item * message | ||||
488 | |||||
489 | A subroutine reference which is used to generate an error message when | ||||
490 | the constraint fails. This is optional. | ||||
491 | |||||
492 | =item * coercion | ||||
493 | |||||
494 | A L<Moose::Meta::TypeCoercion> object representing the coercions to | ||||
495 | the type. This is optional. | ||||
496 | |||||
497 | =item * inlined | ||||
498 | |||||
499 | A subroutine which returns a string suitable for inlining this type | ||||
500 | constraint. It will be called as a method on the type constraint object, and | ||||
501 | will receive a single additional parameter, a variable name to be tested | ||||
502 | (usually C<"$_"> or C<"$_[0]">. | ||||
503 | |||||
504 | This is optional. | ||||
505 | |||||
506 | =item * inline_environment | ||||
507 | |||||
508 | A hash reference of variables to close over. The keys are variables names, and | ||||
509 | the values are I<references> to the variables. | ||||
510 | |||||
511 | =item * optimized | ||||
512 | |||||
513 | B<This option is deprecated.> | ||||
514 | |||||
515 | This is a variant of the C<constraint> parameter that is somehow | ||||
516 | optimized. Typically, this means incorporating both the type's | ||||
517 | constraint and all of its parents' constraints into a single | ||||
518 | subroutine reference. | ||||
519 | |||||
520 | =back | ||||
521 | |||||
522 | =item B<< $constraint->equals($type_name_or_object) >> | ||||
523 | |||||
524 | Returns true if the supplied name or type object is the same as the | ||||
525 | current type. | ||||
526 | |||||
527 | =item B<< $constraint->is_subtype_of($type_name_or_object) >> | ||||
528 | |||||
529 | Returns true if the supplied name or type object is a parent of the | ||||
530 | current type. | ||||
531 | |||||
532 | =item B<< $constraint->is_a_type_of($type_name_or_object) >> | ||||
533 | |||||
534 | Returns true if the given type is the same as the current type, or is | ||||
535 | a parent of the current type. This is a shortcut for checking | ||||
536 | C<equals> and C<is_subtype_of>. | ||||
537 | |||||
538 | =item B<< $constraint->coerce($value) >> | ||||
539 | |||||
540 | This will attempt to coerce the value to the type. If the type does not | ||||
541 | have any defined coercions this will throw an error. | ||||
542 | |||||
543 | If no coercion can produce a value matching C<$constraint>, the original | ||||
544 | value is returned. | ||||
545 | |||||
546 | =item B<< $constraint->assert_coerce($value) >> | ||||
547 | |||||
548 | This method behaves just like C<coerce>, but if the result is not valid | ||||
549 | according to C<$constraint>, an error is thrown. | ||||
550 | |||||
551 | =item B<< $constraint->check($value) >> | ||||
552 | |||||
553 | Returns true if the given value passes the constraint for the type. | ||||
554 | |||||
555 | =item B<< $constraint->validate($value) >> | ||||
556 | |||||
557 | This is similar to C<check>. However, if the type I<is valid> then the | ||||
558 | method returns an explicit C<undef>. If the type is not valid, we call | ||||
559 | C<< $self->get_message($value) >> internally to generate an error | ||||
560 | message. | ||||
561 | |||||
562 | =item B<< $constraint->assert_valid($value) >> | ||||
563 | |||||
564 | Like C<check> and C<validate>, this method checks whether C<$value> is | ||||
565 | valid under the constraint. If it is, it will return true. If it is not, | ||||
566 | an exception will be thrown with the results of | ||||
567 | C<< $self->get_message($value) >>. | ||||
568 | |||||
569 | =item B<< $constraint->name >> | ||||
570 | |||||
571 | Returns the type's name, as provided to the constructor. | ||||
572 | |||||
573 | =item B<< $constraint->parent >> | ||||
574 | |||||
575 | Returns the type's parent, as provided to the constructor, if any. | ||||
576 | |||||
577 | =item B<< $constraint->has_parent >> | ||||
578 | |||||
579 | Returns true if the type has a parent type. | ||||
580 | |||||
581 | =item B<< $constraint->parents >> | ||||
582 | |||||
583 | Returns all of the types parents as an list of type constraint objects. | ||||
584 | |||||
585 | =item B<< $constraint->constraint >> | ||||
586 | |||||
587 | Returns the type's constraint, as provided to the constructor. | ||||
588 | |||||
589 | =item B<< $constraint->get_message($value) >> | ||||
590 | |||||
591 | This generates a method for the given value. If the type does not have | ||||
592 | an explicit message, we generate a default message. | ||||
593 | |||||
594 | =item B<< $constraint->has_message >> | ||||
595 | |||||
596 | Returns true if the type has a message. | ||||
597 | |||||
598 | =item B<< $constraint->message >> | ||||
599 | |||||
600 | Returns the type's message as a subroutine reference. | ||||
601 | |||||
602 | =item B<< $constraint->coercion >> | ||||
603 | |||||
604 | Returns the type's L<Moose::Meta::TypeCoercion> object, if one | ||||
605 | exists. | ||||
606 | |||||
607 | =item B<< $constraint->has_coercion >> | ||||
608 | |||||
609 | Returns true if the type has a coercion. | ||||
610 | |||||
611 | =item B<< $constraint->can_be_inlined >> | ||||
612 | |||||
613 | Returns true if this type constraint can be inlined. A type constraint which | ||||
614 | subtypes an inlinable constraint and does not add an additional constraint | ||||
615 | "inherits" its parent type's inlining. | ||||
616 | |||||
617 | =item B<< $constraint->hand_optimized_type_constraint >> | ||||
618 | |||||
619 | B<This method is deprecated.> | ||||
620 | |||||
621 | Returns the type's hand optimized constraint, as provided to the | ||||
622 | constructor via the C<optimized> option. | ||||
623 | |||||
624 | =item B<< $constraint->has_hand_optimized_type_constraint >> | ||||
625 | |||||
626 | B<This method is deprecated.> | ||||
627 | |||||
628 | Returns true if the type has an optimized constraint. | ||||
629 | |||||
630 | =item B<< $constraint->create_child_type(%options) >> | ||||
631 | |||||
632 | This returns a new type constraint of the same class using the | ||||
633 | provided C<%options>. The C<parent> option will be the current type. | ||||
634 | |||||
635 | This method exists so that subclasses of this class can override this | ||||
636 | behavior and change how child types are created. | ||||
637 | |||||
638 | =back | ||||
639 | |||||
640 | =head1 BUGS | ||||
641 | |||||
642 | See L<Moose/BUGS> for details on reporting bugs. | ||||
643 | |||||
644 | =head1 AUTHOR | ||||
645 | |||||
646 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
647 | |||||
648 | =head1 COPYRIGHT AND LICENSE | ||||
649 | |||||
650 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
651 | |||||
652 | This is free software; you can redistribute it and/or modify it under | ||||
653 | the same terms as the Perl 5 programming language system itself. | ||||
654 | |||||
655 | =cut | ||||
656 | |||||
657 | |||||
658 | __END__ |