| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Specio::Constraint::Parameterizable; |
|
2
|
|
|
|
|
|
|
|
|
3
|
29
|
|
|
29
|
|
202
|
use strict; |
|
|
29
|
|
|
|
|
60
|
|
|
|
29
|
|
|
|
|
873
|
|
|
4
|
29
|
|
|
29
|
|
218
|
use warnings; |
|
|
29
|
|
|
|
|
62
|
|
|
|
29
|
|
|
|
|
1554
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
29
|
|
|
29
|
|
156
|
use Carp qw( confess ); |
|
|
29
|
|
|
|
|
60
|
|
|
|
29
|
|
|
|
|
1348
|
|
|
9
|
29
|
|
|
29
|
|
7765
|
use Role::Tiny::With; |
|
|
29
|
|
|
|
|
84649
|
|
|
|
29
|
|
|
|
|
1433
|
|
|
10
|
29
|
|
|
29
|
|
12852
|
use Specio::Constraint::Parameterized; |
|
|
29
|
|
|
|
|
100
|
|
|
|
29
|
|
|
|
|
1141
|
|
|
11
|
29
|
|
|
29
|
|
7272
|
use Specio::DeclaredAt; |
|
|
29
|
|
|
|
|
72
|
|
|
|
29
|
|
|
|
|
890
|
|
|
12
|
29
|
|
|
29
|
|
187
|
use Specio::OO; |
|
|
29
|
|
|
|
|
54
|
|
|
|
29
|
|
|
|
|
1493
|
|
|
13
|
29
|
|
|
29
|
|
182
|
use Specio::TypeChecks qw( does_role isa_class ); |
|
|
29
|
|
|
|
|
58
|
|
|
|
29
|
|
|
|
|
1254
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
29
|
|
|
29
|
|
175
|
use Specio::Constraint::Role::Interface; |
|
|
29
|
|
|
|
|
71
|
|
|
|
29
|
|
|
|
|
11955
|
|
|
16
|
|
|
|
|
|
|
with 'Specio::Constraint::Role::Interface'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
{ |
|
19
|
|
|
|
|
|
|
## no critic (Subroutines::ProtectPrivateSubs) |
|
20
|
|
|
|
|
|
|
my $role_attrs = Specio::Constraint::Role::Interface::_attrs(); |
|
21
|
|
|
|
|
|
|
## use critic |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $attrs = { |
|
24
|
|
|
|
|
|
|
%{$role_attrs}, |
|
25
|
|
|
|
|
|
|
_parameterized_constraint_generator => { |
|
26
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
27
|
|
|
|
|
|
|
init_arg => 'parameterized_constraint_generator', |
|
28
|
|
|
|
|
|
|
predicate => '_has_parameterized_constraint_generator', |
|
29
|
|
|
|
|
|
|
}, |
|
30
|
|
|
|
|
|
|
_parameterized_inline_generator => { |
|
31
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
32
|
|
|
|
|
|
|
init_arg => 'parameterized_inline_generator', |
|
33
|
|
|
|
|
|
|
predicate => '_has_parameterized_inline_generator', |
|
34
|
|
|
|
|
|
|
}, |
|
35
|
|
|
|
|
|
|
}; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
|
38
|
|
|
|
|
|
|
sub _attrs { |
|
39
|
479
|
|
|
479
|
|
965
|
return $attrs; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub BUILD { |
|
44
|
116
|
|
|
116
|
0
|
2239
|
my $self = shift; |
|
45
|
|
|
|
|
|
|
|
|
46
|
116
|
50
|
|
|
|
356
|
if ( $self->_has_constraint ) { |
|
47
|
0
|
0
|
|
|
|
0
|
die |
|
48
|
|
|
|
|
|
|
'A parameterizable constraint with a constraint parameter must also have a parameterized_constraint_generator' |
|
49
|
|
|
|
|
|
|
unless $self->_has_parameterized_constraint_generator; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
116
|
50
|
|
|
|
715
|
if ( $self->_has_inline_generator ) { |
|
53
|
116
|
50
|
|
|
|
698
|
die |
|
54
|
|
|
|
|
|
|
'A parameterizable constraint with an inline_generator parameter must also have a parameterized_inline_generator' |
|
55
|
|
|
|
|
|
|
unless $self->_has_parameterized_inline_generator; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
116
|
|
|
|
|
742
|
return; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub parameterize { |
|
62
|
15
|
|
|
15
|
1
|
195
|
my $self = shift; |
|
63
|
15
|
|
|
|
|
61
|
my %args = @_; |
|
64
|
|
|
|
|
|
|
|
|
65
|
15
|
|
|
|
|
54
|
my ( $parameter, $declared_at ) = @args{qw( of declared_at )}; |
|
66
|
15
|
50
|
|
|
|
57
|
does_role( $parameter, 'Specio::Constraint::Role::Interface' ) |
|
67
|
|
|
|
|
|
|
or confess |
|
68
|
|
|
|
|
|
|
'The "of" parameter passed to ->parameterize must be an object which does the Specio::Constraint::Role::Interface role'; |
|
69
|
|
|
|
|
|
|
|
|
70
|
15
|
100
|
|
|
|
325
|
if ($declared_at) { |
|
71
|
14
|
50
|
|
|
|
67
|
isa_class( $declared_at, 'Specio::DeclaredAt' ) |
|
72
|
|
|
|
|
|
|
or confess |
|
73
|
|
|
|
|
|
|
'The "declared_at" parameter passed to ->parameterize must be a Specio::DeclaredAt object'; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
15
|
100
|
|
|
|
64
|
$declared_at = Specio::DeclaredAt->new_from_caller(1) |
|
77
|
|
|
|
|
|
|
unless defined $declared_at; |
|
78
|
|
|
|
|
|
|
|
|
79
|
15
|
|
|
|
|
74
|
my %p = ( |
|
80
|
|
|
|
|
|
|
parent => $self, |
|
81
|
|
|
|
|
|
|
parameter => $parameter, |
|
82
|
|
|
|
|
|
|
declared_at => $declared_at, |
|
83
|
|
|
|
|
|
|
); |
|
84
|
|
|
|
|
|
|
|
|
85
|
15
|
50
|
|
|
|
89
|
if ( $self->_has_parameterized_constraint_generator ) { |
|
86
|
|
|
|
|
|
|
$p{constraint} |
|
87
|
0
|
|
|
|
|
0
|
= $self->_parameterized_constraint_generator->($parameter); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
else { |
|
90
|
15
|
100
|
|
|
|
202
|
confess |
|
91
|
|
|
|
|
|
|
'The "of" parameter passed to ->parameterize must be an inlinable constraint if the parameterizable type has an inline_generator' |
|
92
|
|
|
|
|
|
|
unless $parameter->can_be_inlined; |
|
93
|
|
|
|
|
|
|
|
|
94
|
14
|
|
|
|
|
168
|
my $ig = $self->_parameterized_inline_generator; |
|
95
|
14
|
|
|
13
|
|
136
|
$p{inline_generator} = sub { $ig->( shift, $parameter, @_ ) }; |
|
|
13
|
|
|
|
|
103
|
|
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
14
|
|
|
|
|
123
|
return Specio::Constraint::Parameterized->new(%p); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__PACKAGE__->_ooify; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# ABSTRACT: A class which represents parameterizable constraints |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=pod |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=encoding UTF-8 |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Specio::Constraint::Parameterizable - A class which represents parameterizable constraints |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
version 0.47 |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $arrayref = t('ArrayRef'); |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $arrayref_of_int = $arrayref->parameterize( of => t('Int') ); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This class implements the API for parameterizable types like C<ArrayRef> and |
|
130
|
|
|
|
|
|
|
C<Maybe>. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=for Pod::Coverage BUILD |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 API |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This class implements the same API as L<Specio::Constraint::Simple>, with a few |
|
137
|
|
|
|
|
|
|
additions. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 Specio::Constraint::Parameterizable->new(...) |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This class's constructor accepts two additional parameters: |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * parameterized_constraint_generator |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This is a subroutine that generates a new constraint subroutine when the type |
|
148
|
|
|
|
|
|
|
is parameterized. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
It will be called as a method on the type and will be passed a single argument, |
|
151
|
|
|
|
|
|
|
the type object for the type parameter. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This parameter is mutually exclusive with the C<parameterized_inline_generator> |
|
154
|
|
|
|
|
|
|
parameter. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * parameterized_inline_generator |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This is a subroutine that generates a new inline generator subroutine when the |
|
159
|
|
|
|
|
|
|
type is parameterized. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
It will be called as a method on the L<Specio::Constraint::Parameterized> |
|
162
|
|
|
|
|
|
|
object when that object needs to generate an inline constraint. It will receive |
|
163
|
|
|
|
|
|
|
the type parameter as the first argument and the variable name as a string as |
|
164
|
|
|
|
|
|
|
the second. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This probably seems fairly confusing, so looking at the examples in the |
|
167
|
|
|
|
|
|
|
L<Specio::Library::Builtins> code may be helpful. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This parameter is mutually exclusive with the |
|
170
|
|
|
|
|
|
|
C<parameterized_constraint_generator> parameter. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 $type->parameterize(...) |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This method takes two arguments. The C<of> argument should be an object which |
|
177
|
|
|
|
|
|
|
does the L<Specio::Constraint::Role::Interface> role, and is required. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
The other argument, C<declared_at>, is optional. If it is not given, then a new |
|
180
|
|
|
|
|
|
|
L<Specio::DeclaredAt> object is creating using a call stack depth of 1. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This method returns a new L<Specio::Constraint::Parameterized> object. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SUPPORT |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SOURCE |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 AUTHOR |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This software is Copyright (c) 2012 - 2021 by Dave Rolsky. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This is free software, licensed under: |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
207
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |