line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::TypeConstraint::Parameterizable; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2206'; |
3
|
|
|
|
|
|
|
|
4
|
390
|
|
|
390
|
|
2860
|
use strict; |
|
390
|
|
|
|
|
1017
|
|
|
390
|
|
|
|
|
12115
|
|
5
|
390
|
|
|
390
|
|
2170
|
use warnings; |
|
390
|
|
|
|
|
936
|
|
|
390
|
|
|
|
|
9663
|
|
6
|
390
|
|
|
390
|
|
2038
|
use metaclass; |
|
390
|
|
|
|
|
961
|
|
|
390
|
|
|
|
|
2173
|
|
7
|
|
|
|
|
|
|
|
8
|
390
|
|
|
390
|
|
3117
|
use parent 'Moose::Meta::TypeConstraint'; |
|
390
|
|
|
|
|
1074
|
|
|
390
|
|
|
|
|
2622
|
|
9
|
390
|
|
|
390
|
|
27927
|
use Moose::Meta::TypeConstraint::Parameterized; |
|
390
|
|
|
|
|
1207
|
|
|
390
|
|
|
|
|
12032
|
|
10
|
390
|
|
|
390
|
|
2703
|
use Moose::Util::TypeConstraints (); |
|
390
|
|
|
|
|
1511
|
|
|
390
|
|
|
|
|
10223
|
|
11
|
|
|
|
|
|
|
|
12
|
390
|
|
|
390
|
|
2607
|
use Moose::Util 'throw_exception'; |
|
390
|
|
|
|
|
1139
|
|
|
390
|
|
|
|
|
3019
|
|
13
|
|
|
|
|
|
|
|
14
|
390
|
|
|
390
|
|
103473
|
use Carp 'confess'; |
|
390
|
|
|
|
|
1014
|
|
|
390
|
|
|
|
|
244916
|
|
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
|
845
|
my ($self, $type) = @_; |
30
|
|
|
|
|
|
|
|
31
|
341
|
50
|
|
|
|
14401
|
return unless $self->has_constraint_generator; |
32
|
|
|
|
|
|
|
|
33
|
341
|
100
|
|
|
|
8914
|
return $self->constraint_generator->($type->type_parameter) |
34
|
|
|
|
|
|
|
if $type->is_subtype_of($self->name); |
35
|
|
|
|
|
|
|
|
36
|
201
|
100
|
66
|
|
|
6502
|
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
|
|
|
|
|
1003
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _can_coerce_constraint_from { |
44
|
2
|
|
|
2
|
|
8
|
my ($self, $type) = @_; |
45
|
2
|
|
|
|
|
79
|
my $coercion = $self->coercion; |
46
|
2
|
|
|
|
|
100
|
my $constraint = $self->constraint_generator->($type->type_parameter); |
47
|
|
|
|
|
|
|
return sub { |
48
|
4
|
|
|
4
|
|
30
|
local $_ = $coercion->coerce($_); |
49
|
4
|
|
|
|
|
74
|
$constraint->(@_); |
50
|
2
|
|
|
|
|
32
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub generate_inline_for { |
54
|
337
|
|
|
337
|
0
|
1120
|
my ($self, $type, $val) = @_; |
55
|
|
|
|
|
|
|
|
56
|
337
|
100
|
|
|
|
13108
|
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
|
|
|
|
|
11674
|
return '( do { ' . $self->inline_generator->( $self, $type, $val ) . ' } )'; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _parse_type_parameter { |
66
|
133
|
|
|
133
|
|
720
|
my ($self, $type_parameter) = @_; |
67
|
133
|
|
|
|
|
1026
|
return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_parameter); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub parameterize { |
71
|
133
|
|
|
133
|
0
|
567
|
my ($self, $type_parameter) = @_; |
72
|
|
|
|
|
|
|
|
73
|
133
|
|
|
|
|
729
|
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
|
|
|
|
4315
|
if(my $parent = $self->parent) { |
79
|
133
|
100
|
|
|
|
1047
|
if($parent->can('type_parameter')) { |
80
|
3
|
100
|
|
|
|
110
|
unless ( $contained_tc->is_a_type_of($parent->type_parameter) ) { |
81
|
2
|
|
|
|
|
58
|
throw_exception( ParameterIsNotSubtypeOfParent => type_parameter => $type_parameter, |
82
|
|
|
|
|
|
|
type_name => $self->name, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
131
|
50
|
|
|
|
770
|
if ( $contained_tc->isa('Moose::Meta::TypeConstraint') ) { |
89
|
131
|
|
|
|
|
3919
|
my $tc_name = $self->name . '[' . $contained_tc->name . ']'; |
90
|
131
|
|
|
|
|
1593
|
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.2206 |
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 |