line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::TypeConstraint::Parameterizable; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2205'; |
3
|
|
|
|
|
|
|
|
4
|
390
|
|
|
390
|
|
2972
|
use strict; |
|
390
|
|
|
|
|
960
|
|
|
390
|
|
|
|
|
11954
|
|
5
|
390
|
|
|
390
|
|
2251
|
use warnings; |
|
390
|
|
|
|
|
1313
|
|
|
390
|
|
|
|
|
9199
|
|
6
|
390
|
|
|
390
|
|
2037
|
use metaclass; |
|
390
|
|
|
|
|
917
|
|
|
390
|
|
|
|
|
2271
|
|
7
|
|
|
|
|
|
|
|
8
|
390
|
|
|
390
|
|
2996
|
use parent 'Moose::Meta::TypeConstraint'; |
|
390
|
|
|
|
|
1088
|
|
|
390
|
|
|
|
|
2671
|
|
9
|
390
|
|
|
390
|
|
28226
|
use Moose::Meta::TypeConstraint::Parameterized; |
|
390
|
|
|
|
|
1273
|
|
|
390
|
|
|
|
|
11941
|
|
10
|
390
|
|
|
390
|
|
2673
|
use Moose::Util::TypeConstraints (); |
|
390
|
|
|
|
|
1151
|
|
|
390
|
|
|
|
|
10399
|
|
11
|
|
|
|
|
|
|
|
12
|
390
|
|
|
390
|
|
2554
|
use Moose::Util 'throw_exception'; |
|
390
|
|
|
|
|
1133
|
|
|
390
|
|
|
|
|
3113
|
|
13
|
|
|
|
|
|
|
|
14
|
390
|
|
|
390
|
|
103154
|
use Carp 'confess'; |
|
390
|
|
|
|
|
1023
|
|
|
390
|
|
|
|
|
243062
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('constraint_generator' => ( |
17
|
|
|
|
|
|
|
accessor => 'constraint_generator', |
18
|
|
|
|
|
|
|
predicate => 'has_constraint_generator', |
19
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
20
|
|
|
|
|
|
|
)); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('inline_generator' => ( |
23
|
|
|
|
|
|
|
accessor => 'inline_generator', |
24
|
|
|
|
|
|
|
predicate => 'has_inline_generator', |
25
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
26
|
|
|
|
|
|
|
)); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub generate_constraint_for { |
29
|
341
|
|
|
341
|
0
|
891
|
my ($self, $type) = @_; |
30
|
|
|
|
|
|
|
|
31
|
341
|
50
|
|
|
|
14906
|
return unless $self->has_constraint_generator; |
32
|
|
|
|
|
|
|
|
33
|
341
|
100
|
|
|
|
9632
|
return $self->constraint_generator->($type->type_parameter) |
34
|
|
|
|
|
|
|
if $type->is_subtype_of($self->name); |
35
|
|
|
|
|
|
|
|
36
|
201
|
100
|
66
|
|
|
6717
|
return $self->_can_coerce_constraint_from($type) |
37
|
|
|
|
|
|
|
if $self->has_coercion |
38
|
|
|
|
|
|
|
&& $self->coercion->has_coercion_for_type($type->parent->name); |
39
|
|
|
|
|
|
|
|
40
|
199
|
|
|
|
|
977
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _can_coerce_constraint_from { |
44
|
2
|
|
|
2
|
|
16
|
my ($self, $type) = @_; |
45
|
2
|
|
|
|
|
63
|
my $coercion = $self->coercion; |
46
|
2
|
|
|
|
|
67
|
my $constraint = $self->constraint_generator->($type->type_parameter); |
47
|
|
|
|
|
|
|
return sub { |
48
|
4
|
|
|
4
|
|
20
|
local $_ = $coercion->coerce($_); |
49
|
4
|
|
|
|
|
60
|
$constraint->(@_); |
50
|
2
|
|
|
|
|
16
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub generate_inline_for { |
54
|
337
|
|
|
337
|
0
|
1310
|
my ($self, $type, $val) = @_; |
55
|
|
|
|
|
|
|
|
56
|
337
|
100
|
|
|
|
13359
|
throw_exception( CannotGenerateInlineConstraint => parameterizable_type_object_name => $self->name, |
57
|
|
|
|
|
|
|
type_name => $type->name, |
58
|
|
|
|
|
|
|
value => $val, |
59
|
|
|
|
|
|
|
) |
60
|
|
|
|
|
|
|
unless $self->has_inline_generator; |
61
|
|
|
|
|
|
|
|
62
|
336
|
|
|
|
|
12381
|
return '( do { ' . $self->inline_generator->( $self, $type, $val ) . ' } )'; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _parse_type_parameter { |
66
|
133
|
|
|
133
|
|
782
|
my ($self, $type_parameter) = @_; |
67
|
133
|
|
|
|
|
1121
|
return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_parameter); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub parameterize { |
71
|
133
|
|
|
133
|
0
|
522
|
my ($self, $type_parameter) = @_; |
72
|
|
|
|
|
|
|
|
73
|
133
|
|
|
|
|
786
|
my $contained_tc = $self->_parse_type_parameter($type_parameter); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
## The type parameter should be a subtype of the parent's type parameter |
76
|
|
|
|
|
|
|
## if there is one. |
77
|
|
|
|
|
|
|
|
78
|
133
|
50
|
|
|
|
4626
|
if(my $parent = $self->parent) { |
79
|
133
|
100
|
|
|
|
1044
|
if($parent->can('type_parameter')) { |
80
|
3
|
100
|
|
|
|
109
|
unless ( $contained_tc->is_a_type_of($parent->type_parameter) ) { |
81
|
2
|
|
|
|
|
67
|
throw_exception( ParameterIsNotSubtypeOfParent => type_parameter => $type_parameter, |
82
|
|
|
|
|
|
|
type_name => $self->name, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
131
|
50
|
|
|
|
798
|
if ( $contained_tc->isa('Moose::Meta::TypeConstraint') ) { |
89
|
131
|
|
|
|
|
4077
|
my $tc_name = $self->name . '[' . $contained_tc->name . ']'; |
90
|
131
|
|
|
|
|
1793
|
return Moose::Meta::TypeConstraint::Parameterized->new( |
91
|
|
|
|
|
|
|
name => $tc_name, |
92
|
|
|
|
|
|
|
parent => $self, |
93
|
|
|
|
|
|
|
type_parameter => $contained_tc, |
94
|
|
|
|
|
|
|
parameterized_from => $self, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
|
confess("The type parameter must be a Moose meta type"); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# ABSTRACT: Type constraints which can take a parameter (ArrayRef) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=pod |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=encoding UTF-8 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Moose::Meta::TypeConstraint::Parameterizable - Type constraints which can take a parameter (ArrayRef) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
version 2.2205 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 DESCRIPTION |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This class represents a parameterizable type constraint. This is a |
124
|
|
|
|
|
|
|
type constraint like C<ArrayRef> or C<HashRef>, that can be |
125
|
|
|
|
|
|
|
parameterized and made more specific by specifying a contained |
126
|
|
|
|
|
|
|
type. For example, instead of just an C<ArrayRef> of anything, you can |
127
|
|
|
|
|
|
|
specify that is an C<ArrayRef[Int]>. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
A parameterizable constraint should not be used as an attribute type |
130
|
|
|
|
|
|
|
constraint. Instead, when parameterized it creates a |
131
|
|
|
|
|
|
|
L<Moose::Meta::TypeConstraint::Parameterized> which should be used. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 INHERITANCE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
C<Moose::Meta::TypeConstraint::Parameterizable> is a subclass of |
136
|
|
|
|
|
|
|
L<Moose::Meta::TypeConstraint>. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 METHODS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This class is intentionally not documented because the API is |
141
|
|
|
|
|
|
|
confusing and needs some work. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 BUGS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHORS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item * |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
198
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |