| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id$ |
|
2
|
|
|
|
|
|
|
# $Source$ |
|
3
|
|
|
|
|
|
|
# $Author$ |
|
4
|
|
|
|
|
|
|
# $HeadURL$ |
|
5
|
|
|
|
|
|
|
# $Revision$ |
|
6
|
|
|
|
|
|
|
# $Date$ |
|
7
|
|
|
|
|
|
|
package Class::Dot::Typemap; |
|
8
|
|
|
|
|
|
|
# ##### !!!!! WARNING !!!!!! ################################################ |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# This module is generated automatically by the Typemap program in the top |
|
11
|
|
|
|
|
|
|
# of the Class::Dot distribution, so any changes to this file will be lost! |
|
12
|
|
|
|
|
|
|
# |
|
13
|
|
|
|
|
|
|
############################################################################# |
|
14
|
|
|
|
|
|
|
|
|
15
|
16
|
|
|
16
|
|
64414
|
use strict; |
|
|
16
|
|
|
|
|
34
|
|
|
|
16
|
|
|
|
|
852
|
|
|
16
|
16
|
|
|
16
|
|
95
|
use warnings; |
|
|
16
|
|
|
|
|
28
|
|
|
|
16
|
|
|
|
|
515
|
|
|
17
|
16
|
|
|
16
|
|
1073
|
use version; |
|
|
16
|
|
|
|
|
2451
|
|
|
|
16
|
|
|
|
|
133
|
|
|
18
|
16
|
|
|
16
|
|
1407
|
use 5.00600; |
|
|
16
|
|
|
|
|
62
|
|
|
|
16
|
|
|
|
|
718
|
|
|
19
|
16
|
|
|
16
|
|
87
|
use vars qw(%__TYPEDICT__); |
|
|
16
|
|
|
|
|
31
|
|
|
|
16
|
|
|
|
|
1466
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ASKSH'; |
|
22
|
|
|
|
|
|
|
our $VERSION = qv('2.0.0_15'); |
|
23
|
|
|
|
|
|
|
|
|
24
|
16
|
|
|
16
|
|
92
|
use Carp qw(confess carp croak); |
|
|
16
|
|
|
|
|
31
|
|
|
|
16
|
|
|
|
|
1164
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
16
|
|
|
16
|
|
12154
|
use Class::Dot::Type; |
|
|
16
|
|
|
|
|
43
|
|
|
|
16
|
|
|
|
|
454
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
16
|
|
|
16
|
|
9814
|
use Class::Dot::Devel::Sub::Name; |
|
|
16
|
|
|
|
|
45
|
|
|
|
16
|
|
|
|
|
116
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
16
|
|
|
16
|
|
9672
|
use Class::Dot::Meta::Class; |
|
|
16
|
|
|
|
|
50
|
|
|
|
16
|
|
|
|
|
736
|
|
|
31
|
16
|
|
|
16
|
|
106
|
use Class::Dot::Meta::Type qw(create_type_instance); |
|
|
16
|
|
|
|
|
29
|
|
|
|
16
|
|
|
|
|
163
|
|
|
32
|
16
|
|
|
|
|
167
|
use Class::Dot::Meta::Method qw( |
|
33
|
|
|
|
|
|
|
install_sub_from_class |
|
34
|
|
|
|
|
|
|
install_sub_from_coderef |
|
35
|
16
|
|
|
16
|
|
97
|
); |
|
|
16
|
|
|
|
|
31
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $PKG = __PACKAGE__; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# ------ TYPES REQUIRE MODULES ----- # |
|
40
|
|
|
|
|
|
|
if (!$INC{'Scalar/Util.pm'}) { require Scalar::Util }; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# --------- STANDARD TYPES --------- # |
|
44
|
|
|
|
|
|
|
our @STD_TYPES = qw( |
|
45
|
|
|
|
|
|
|
isa_String isa_Int isa_Array isa_Hash isa_Data isa_Object isa_Code isa_File isa_Bool isa_Regex |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
my @EXPORT_OK = @STD_TYPES; |
|
48
|
|
|
|
|
|
|
my %EXPORT_CLASS = ( |
|
49
|
|
|
|
|
|
|
':std' => [@EXPORT_OK], |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# ------------ ALIASES ------------- # |
|
54
|
|
|
|
|
|
|
our %__TYPEALIASES__ = ( |
|
55
|
|
|
|
|
|
|
'Regex' => 'Regexp', |
|
56
|
|
|
|
|
|
|
'RegexRef' => 'RegexpRef', |
|
57
|
|
|
|
|
|
|
'Num' => 'Number', |
|
58
|
|
|
|
|
|
|
'Str' => 'String', |
|
59
|
|
|
|
|
|
|
'FileHandle' => 'File', |
|
60
|
|
|
|
|
|
|
'...' => 'Any', |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# ------------ COMPAT -------------- # |
|
64
|
|
|
|
|
|
|
our %__COMPAT_TYPESUBS__ = ( |
|
65
|
|
|
|
|
|
|
'isa_Bool' => sub { |
|
66
|
1
|
|
|
1
|
|
3
|
my $real_sub = $__TYPEDICT__{'Bool'}; |
|
67
|
1
|
|
|
|
|
1
|
goto &{ $real_sub }; |
|
|
1
|
|
|
|
|
4
|
|
|
68
|
|
|
|
|
|
|
}, |
|
69
|
|
|
|
|
|
|
'isa_String' => sub { |
|
70
|
21
|
|
|
21
|
|
66
|
my $real_sub = $__TYPEDICT__{'String'}; |
|
71
|
21
|
|
|
|
|
27
|
goto &{ $real_sub }; |
|
|
21
|
|
|
|
|
67
|
|
|
72
|
|
|
|
|
|
|
}, |
|
73
|
|
|
|
|
|
|
'isa_Ref' => sub { |
|
74
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Ref'}; |
|
75
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
76
|
|
|
|
|
|
|
}, |
|
77
|
|
|
|
|
|
|
'isa_Number' => sub { |
|
78
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Number'}; |
|
79
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
80
|
|
|
|
|
|
|
}, |
|
81
|
|
|
|
|
|
|
'isa_Defined' => sub { |
|
82
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Defined'}; |
|
83
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
84
|
|
|
|
|
|
|
}, |
|
85
|
|
|
|
|
|
|
'isa_ScalarRef' => sub { |
|
86
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'ScalarRef'}; |
|
87
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
88
|
|
|
|
|
|
|
}, |
|
89
|
|
|
|
|
|
|
'isa_Object' => sub { |
|
90
|
3
|
|
|
3
|
|
6
|
my $real_sub = $__TYPEDICT__{'Object'}; |
|
91
|
3
|
|
|
|
|
4
|
goto &{ $real_sub }; |
|
|
3
|
|
|
|
|
6
|
|
|
92
|
|
|
|
|
|
|
}, |
|
93
|
|
|
|
|
|
|
'isa_File' => sub { |
|
94
|
2
|
|
|
2
|
|
11
|
my $real_sub = $__TYPEDICT__{'File'}; |
|
95
|
2
|
|
|
|
|
4
|
goto &{ $real_sub }; |
|
|
2
|
|
|
|
|
7
|
|
|
96
|
|
|
|
|
|
|
}, |
|
97
|
|
|
|
|
|
|
'isa_GlobRef' => sub { |
|
98
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'GlobRef'}; |
|
99
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
100
|
|
|
|
|
|
|
}, |
|
101
|
|
|
|
|
|
|
'isa_Regexp' => sub { |
|
102
|
2
|
|
|
2
|
|
6
|
my $real_sub = $__TYPEDICT__{'Regexp'}; |
|
103
|
2
|
|
|
|
|
3
|
goto &{ $real_sub }; |
|
|
2
|
|
|
|
|
6
|
|
|
104
|
|
|
|
|
|
|
}, |
|
105
|
|
|
|
|
|
|
'isa_Array' => sub { |
|
106
|
5
|
|
|
5
|
|
13
|
my $real_sub = $__TYPEDICT__{'Array'}; |
|
107
|
5
|
|
|
|
|
7
|
goto &{ $real_sub }; |
|
|
5
|
|
|
|
|
22
|
|
|
108
|
|
|
|
|
|
|
}, |
|
109
|
|
|
|
|
|
|
'isa_Value' => sub { |
|
110
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Value'}; |
|
111
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
112
|
|
|
|
|
|
|
}, |
|
113
|
|
|
|
|
|
|
'isa_Role' => sub { |
|
114
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Role'}; |
|
115
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
116
|
|
|
|
|
|
|
}, |
|
117
|
|
|
|
|
|
|
'isa_Item' => sub { |
|
118
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Item'}; |
|
119
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
120
|
|
|
|
|
|
|
}, |
|
121
|
|
|
|
|
|
|
'isa_HashRef' => sub { |
|
122
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'HashRef'}; |
|
123
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
124
|
|
|
|
|
|
|
}, |
|
125
|
|
|
|
|
|
|
'isa_ArrayRef' => sub { |
|
126
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'ArrayRef'}; |
|
127
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
128
|
|
|
|
|
|
|
}, |
|
129
|
|
|
|
|
|
|
'isa_Hash' => sub { |
|
130
|
7
|
|
|
7
|
|
33
|
my $real_sub = $__TYPEDICT__{'Hash'}; |
|
131
|
7
|
|
|
|
|
12
|
goto &{ $real_sub }; |
|
|
7
|
|
|
|
|
21
|
|
|
132
|
|
|
|
|
|
|
}, |
|
133
|
|
|
|
|
|
|
'isa_Undef' => sub { |
|
134
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Undef'}; |
|
135
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
136
|
|
|
|
|
|
|
}, |
|
137
|
|
|
|
|
|
|
'isa_RegexpRef' => sub { |
|
138
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'RegexpRef'}; |
|
139
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
140
|
|
|
|
|
|
|
}, |
|
141
|
|
|
|
|
|
|
'isa_Int' => sub { |
|
142
|
5
|
|
|
5
|
|
13
|
my $real_sub = $__TYPEDICT__{'Int'}; |
|
143
|
5
|
|
|
|
|
9
|
goto &{ $real_sub }; |
|
|
5
|
|
|
|
|
91
|
|
|
144
|
|
|
|
|
|
|
}, |
|
145
|
|
|
|
|
|
|
'isa_Code' => sub (;&;) { |
|
146
|
2
|
|
|
2
|
|
11
|
my $real_sub = $__TYPEDICT__{'Code'}; |
|
147
|
2
|
|
|
|
|
4
|
goto &{ $real_sub }; |
|
|
2
|
|
|
|
|
8
|
|
|
148
|
|
|
|
|
|
|
}, |
|
149
|
|
|
|
|
|
|
'isa_ClassName' => sub { |
|
150
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'ClassName'}; |
|
151
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
152
|
|
|
|
|
|
|
}, |
|
153
|
|
|
|
|
|
|
'isa_Any' => sub { |
|
154
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'Any'}; |
|
155
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
156
|
|
|
|
|
|
|
}, |
|
157
|
|
|
|
|
|
|
'isa_CodeRef' => sub { |
|
158
|
|
|
|
|
|
|
my $real_sub = $__TYPEDICT__{'CodeRef'}; |
|
159
|
|
|
|
|
|
|
goto &{ $real_sub }; |
|
160
|
|
|
|
|
|
|
}, |
|
161
|
|
|
|
|
|
|
'isa_Data' => sub { |
|
162
|
7
|
|
|
7
|
|
1275
|
my $real_sub = $__TYPEDICT__{'Data'}; |
|
163
|
7
|
|
|
|
|
9
|
goto &{ $real_sub }; |
|
|
7
|
|
|
|
|
18
|
|
|
164
|
|
|
|
|
|
|
}, |
|
165
|
|
|
|
|
|
|
); |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# ------------ TYPES -------------- # |
|
168
|
|
|
|
|
|
|
our %__TYPEDICT__ = ( |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
'Bool' => (subname '${PKG}::create_type_Bool' => sub { ## no critic |
|
171
|
|
|
|
|
|
|
my (@args) = @_; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Bool_defval" => sub { |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my ($default_value) = @args; |
|
176
|
|
|
|
|
|
|
return $default_value ? 1 : 0 |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
}; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Bool_check" => sub { |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
!defined $_[0] || $_[0] eq q{} || "$_[0]" eq '1' || "$_[0]" eq '0'; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
}; |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
return create_type_instance( |
|
188
|
|
|
|
|
|
|
'Bool', $generator, $constraint, |
|
189
|
|
|
|
|
|
|
[qw(Bool Item)], |
|
190
|
|
|
|
|
|
|
); |
|
191
|
|
|
|
|
|
|
}), |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
'String' => (subname '${PKG}::create_type_String' => sub { ## no critic |
|
194
|
|
|
|
|
|
|
my (@args) = @_; |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_String_defval" => sub { |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my ($default_value) = @args; |
|
199
|
|
|
|
|
|
|
return $default_value |
|
200
|
|
|
|
|
|
|
if defined $default_value; |
|
201
|
|
|
|
|
|
|
return; |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
}; |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_String_check" => sub { |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
defined($_[0]) && !ref($_[0]); |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
}; |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
return create_type_instance( |
|
212
|
|
|
|
|
|
|
'String', $generator, $constraint, |
|
213
|
|
|
|
|
|
|
[qw(String Value Defined Item)], |
|
214
|
|
|
|
|
|
|
); |
|
215
|
|
|
|
|
|
|
}), |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
'Ref' => (subname '${PKG}::create_type_Ref' => sub { ## no critic |
|
218
|
|
|
|
|
|
|
my (@args) = @_; |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Ref_defval" => sub { |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
223
|
|
|
|
|
|
|
if scalar @args; |
|
224
|
|
|
|
|
|
|
return; |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
}; |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Ref_check" => sub { |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
ref $_[0]; |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
}; |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
return create_type_instance( |
|
235
|
|
|
|
|
|
|
'Ref', $generator, $constraint, |
|
236
|
|
|
|
|
|
|
[qw(Ref Defined Item)], |
|
237
|
|
|
|
|
|
|
); |
|
238
|
|
|
|
|
|
|
}), |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
'Number' => (subname '${PKG}::create_type_Number' => sub { ## no critic |
|
241
|
|
|
|
|
|
|
my (@args) = @_; |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Number_defval" => sub { |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
my ($default_value) = @args; |
|
246
|
|
|
|
|
|
|
return $default_value |
|
247
|
|
|
|
|
|
|
if defined $default_value; |
|
248
|
|
|
|
|
|
|
return; |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
}; |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Number_check" => sub { |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
!ref $_[0] && Scalar::Util::looks_like_number( $_[0] ); |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
}; |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
return create_type_instance( |
|
259
|
|
|
|
|
|
|
'Number', $generator, $constraint, |
|
260
|
|
|
|
|
|
|
[qw(Number Value Defined Item)], |
|
261
|
|
|
|
|
|
|
); |
|
262
|
|
|
|
|
|
|
}), |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
'Defined' => (subname '${PKG}::create_type_Defined' => sub { ## no critic |
|
265
|
|
|
|
|
|
|
my (@args) = @_; |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Defined_defval" => sub { |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
270
|
|
|
|
|
|
|
if scalar @args; |
|
271
|
|
|
|
|
|
|
return; |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
}; |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Defined_check" => sub { |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
defined $_[0]; |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
}; |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
return create_type_instance( |
|
282
|
|
|
|
|
|
|
'Defined', $generator, $constraint, |
|
283
|
|
|
|
|
|
|
[qw(Defined Item)], |
|
284
|
|
|
|
|
|
|
); |
|
285
|
|
|
|
|
|
|
}), |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
'ScalarRef' => (subname '${PKG}::create_type_ScalarRef' => sub { ## no critic |
|
288
|
|
|
|
|
|
|
my (@args) = @_; |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_ScalarRef_defval" => sub { |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
293
|
|
|
|
|
|
|
if scalar @args; |
|
294
|
|
|
|
|
|
|
return; |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
}; |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_ScalarRef_check" => sub { |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
ref $_[0] eq "SCALAR"; |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
}; |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
return create_type_instance( |
|
305
|
|
|
|
|
|
|
'ScalarRef', $generator, $constraint, |
|
306
|
|
|
|
|
|
|
[qw(ScalarRef Ref Defined Item)], |
|
307
|
|
|
|
|
|
|
); |
|
308
|
|
|
|
|
|
|
}), |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
'Object' => (subname '${PKG}::create_type_Object' => sub { ## no critic |
|
311
|
|
|
|
|
|
|
my (@args) = @_; |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Object_defval" => sub { |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
my ($class, %opts); |
|
316
|
|
|
|
|
|
|
if (+@args % 2) { # is odd number (class + a hash) |
|
317
|
|
|
|
|
|
|
($class, %opts) = @args; |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
else { |
|
320
|
|
|
|
|
|
|
($class) = @args; |
|
321
|
|
|
|
|
|
|
} |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
return if not defined $class; |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
if (delete $opts{auto}) { |
|
326
|
|
|
|
|
|
|
my $class_opts = scalar keys %opts ? {%opts} : (); |
|
327
|
|
|
|
|
|
|
my $new_object = $class->new($class_opts); |
|
328
|
|
|
|
|
|
|
return $new_object; |
|
329
|
|
|
|
|
|
|
} |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
return; |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
}; |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Object_check" => sub { |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
my $blessed = Scalar::Util::blessed($_[0]); |
|
338
|
|
|
|
|
|
|
$blessed && $blessed ne 'Regexp'; |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
}; |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
return create_type_instance( |
|
343
|
|
|
|
|
|
|
'Object', $generator, $constraint, |
|
344
|
|
|
|
|
|
|
[qw(Object Ref Defined Item)], |
|
345
|
|
|
|
|
|
|
); |
|
346
|
|
|
|
|
|
|
}), |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
'File' => (subname '${PKG}::create_type_File' => sub { ## no critic |
|
349
|
|
|
|
|
|
|
my (@args) = @_; |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_File_defval" => sub { |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
my ($default_value) = @args; |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
return $default_value |
|
356
|
|
|
|
|
|
|
if defined $default_value; |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
if (! $INC{'FileHandle.pm'}) { |
|
359
|
|
|
|
|
|
|
require FileHandle; |
|
360
|
|
|
|
|
|
|
} |
|
361
|
|
|
|
|
|
|
return FileHandle->new(); |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
}; |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_File_check" => sub { |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
ref $_[0] eq 'GLOB' && Scalar::Util::openhandle($_[0]); |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
}; |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
return create_type_instance( |
|
372
|
|
|
|
|
|
|
'File', $generator, $constraint, |
|
373
|
|
|
|
|
|
|
[qw(File GlobRef Ref Defined Item)], |
|
374
|
|
|
|
|
|
|
); |
|
375
|
|
|
|
|
|
|
}), |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
'GlobRef' => (subname '${PKG}::create_type_GlobRef' => sub { ## no critic |
|
378
|
|
|
|
|
|
|
my (@args) = @_; |
|
379
|
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_GlobRef_defval" => sub { |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
383
|
|
|
|
|
|
|
if scalar @args; |
|
384
|
|
|
|
|
|
|
return; |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
}; |
|
387
|
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_GlobRef_check" => sub { |
|
389
|
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
ref $_[0] eq "GLOB"; |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
}; |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
return create_type_instance( |
|
395
|
|
|
|
|
|
|
'GlobRef', $generator, $constraint, |
|
396
|
|
|
|
|
|
|
[qw(GlobRef Ref Defined Item)], |
|
397
|
|
|
|
|
|
|
); |
|
398
|
|
|
|
|
|
|
}), |
|
399
|
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
'Regexp' => (subname '${PKG}::create_type_Regexp' => sub { ## no critic |
|
401
|
|
|
|
|
|
|
my (@args) = @_; |
|
402
|
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Regexp_defval" => sub { |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
my ($default_regex) = @args; |
|
406
|
|
|
|
|
|
|
return defined $default_regex && ref $default_regex eq 'Regexp' |
|
407
|
|
|
|
|
|
|
? $default_regex |
|
408
|
|
|
|
|
|
|
: qr{\A\z}xms |
|
409
|
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
}; |
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Regexp_check" => sub { |
|
413
|
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
ref $_[0] eq "Regexp"; |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
}; |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
return create_type_instance( |
|
419
|
|
|
|
|
|
|
'Regexp', $generator, $constraint, |
|
420
|
|
|
|
|
|
|
[qw(Regexp RegexpRef Ref Defined Item)], |
|
421
|
|
|
|
|
|
|
); |
|
422
|
|
|
|
|
|
|
}), |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
'Array' => (subname '${PKG}::create_type_Array' => sub { ## no critic |
|
425
|
|
|
|
|
|
|
my (@args) = @_; |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Array_defval" => sub { |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
my @default_values = @args; |
|
430
|
|
|
|
|
|
|
return scalar @default_values ? \@default_values |
|
431
|
|
|
|
|
|
|
: [ ]; |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
}; |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Array_check" => sub { |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
ref $_[0] eq "ARRAY"; |
|
438
|
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
}; |
|
440
|
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
return create_type_instance( |
|
442
|
|
|
|
|
|
|
'Array', $generator, $constraint, |
|
443
|
|
|
|
|
|
|
[qw(Array ArrayRef Ref Defined Item)], |
|
444
|
|
|
|
|
|
|
); |
|
445
|
|
|
|
|
|
|
}), |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
'Value' => (subname '${PKG}::create_type_Value' => sub { ## no critic |
|
448
|
|
|
|
|
|
|
my (@args) = @_; |
|
449
|
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Value_defval" => sub { |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
my ($default_value) = @args; |
|
453
|
|
|
|
|
|
|
return $default_value |
|
454
|
|
|
|
|
|
|
if defined $default_value; |
|
455
|
|
|
|
|
|
|
return; |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
}; |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Value_check" => sub { |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
defined $_[0] && !ref $_[0]; |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
}; |
|
464
|
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
return create_type_instance( |
|
466
|
|
|
|
|
|
|
'Value', $generator, $constraint, |
|
467
|
|
|
|
|
|
|
[qw(Value Defined Item)], |
|
468
|
|
|
|
|
|
|
); |
|
469
|
|
|
|
|
|
|
}), |
|
470
|
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
'Role' => (subname '${PKG}::create_type_Role' => sub { ## no critic |
|
472
|
|
|
|
|
|
|
my (@args) = @_; |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Role_defval" => sub { |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
my ($class, %opts); |
|
477
|
|
|
|
|
|
|
if (+@args % 2) { # is odd number (class + a hash) |
|
478
|
|
|
|
|
|
|
($class, %opts) = @args; |
|
479
|
|
|
|
|
|
|
} |
|
480
|
|
|
|
|
|
|
else { |
|
481
|
|
|
|
|
|
|
($class) = @args; |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
return if not defined $class; |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
if (delete $opts{auto}) { |
|
487
|
|
|
|
|
|
|
my $class_opts = scalar keys %opts ? {%opts} : (); |
|
488
|
|
|
|
|
|
|
my $new_object = $class->new($class_opts); |
|
489
|
|
|
|
|
|
|
return $new_object; |
|
490
|
|
|
|
|
|
|
} |
|
491
|
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
return; |
|
493
|
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
}; |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Role_check" => sub { |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
Scalar::Util::blessed($_[0]) && $_[0]->can('does') |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
}; |
|
501
|
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
return create_type_instance( |
|
503
|
|
|
|
|
|
|
'Role', $generator, $constraint, |
|
504
|
|
|
|
|
|
|
[qw(Role Object Ref Defined Item)], |
|
505
|
|
|
|
|
|
|
); |
|
506
|
|
|
|
|
|
|
}), |
|
507
|
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
'Item' => (subname '${PKG}::create_type_Item' => sub { ## no critic |
|
509
|
|
|
|
|
|
|
my (@args) = @_; |
|
510
|
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Item_defval" => sub { |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
514
|
|
|
|
|
|
|
if scalar @args; |
|
515
|
|
|
|
|
|
|
return; |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
}; |
|
518
|
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Item_check" => sub { |
|
520
|
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
1 |
|
522
|
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
}; |
|
524
|
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
return create_type_instance( |
|
526
|
|
|
|
|
|
|
'Item', $generator, $constraint, |
|
527
|
|
|
|
|
|
|
[qw(Item)], |
|
528
|
|
|
|
|
|
|
); |
|
529
|
|
|
|
|
|
|
}), |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
'HashRef' => (subname '${PKG}::create_type_HashRef' => sub { ## no critic |
|
532
|
|
|
|
|
|
|
my (@args) = @_; |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_HashRef_defval" => sub { |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
537
|
|
|
|
|
|
|
if scalar @args; |
|
538
|
|
|
|
|
|
|
return; |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
}; |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_HashRef_check" => sub { |
|
543
|
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
ref $_[0] eq "HASH"; |
|
545
|
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
}; |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
return create_type_instance( |
|
549
|
|
|
|
|
|
|
'HashRef', $generator, $constraint, |
|
550
|
|
|
|
|
|
|
[qw(HashRef Ref Defined Item)], |
|
551
|
|
|
|
|
|
|
); |
|
552
|
|
|
|
|
|
|
}), |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
'ArrayRef' => (subname '${PKG}::create_type_ArrayRef' => sub { ## no critic |
|
555
|
|
|
|
|
|
|
my (@args) = @_; |
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_ArrayRef_defval" => sub { |
|
558
|
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
560
|
|
|
|
|
|
|
if scalar @args; |
|
561
|
|
|
|
|
|
|
return; |
|
562
|
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
}; |
|
564
|
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_ArrayRef_check" => sub { |
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
ref $_[0] eq "ARRAY"; |
|
568
|
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
}; |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
return create_type_instance( |
|
572
|
|
|
|
|
|
|
'ArrayRef', $generator, $constraint, |
|
573
|
|
|
|
|
|
|
[qw(ArrayRef Ref Defined Item)], |
|
574
|
|
|
|
|
|
|
); |
|
575
|
|
|
|
|
|
|
}), |
|
576
|
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
'Hash' => (subname '${PKG}::create_type_Hash' => sub { ## no critic |
|
578
|
|
|
|
|
|
|
my (@args) = @_; |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Hash_defval" => sub { |
|
581
|
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
if (scalar @args == 1) { |
|
583
|
|
|
|
|
|
|
return $args[0] if ref $args[0] eq 'HASH'; |
|
584
|
|
|
|
|
|
|
confess "Attribute type Hash can't have default" |
|
585
|
|
|
|
|
|
|
. "value with odd number of elements."; |
|
586
|
|
|
|
|
|
|
} |
|
587
|
|
|
|
|
|
|
return { } if !+@args % 2; |
|
588
|
|
|
|
|
|
|
my %default_values = @args; |
|
589
|
|
|
|
|
|
|
return scalar keys %default_values ? \%default_values |
|
590
|
|
|
|
|
|
|
: { }; |
|
591
|
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
# have to test if there are any entries in the hash |
|
593
|
|
|
|
|
|
|
# so we return a new anonymous hash if it ain't. |
|
594
|
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
}; |
|
596
|
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Hash_check" => sub { |
|
598
|
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
ref $_[0] eq "HASH"; |
|
600
|
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
}; |
|
602
|
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
return create_type_instance( |
|
604
|
|
|
|
|
|
|
'Hash', $generator, $constraint, |
|
605
|
|
|
|
|
|
|
[qw(Hash HashRef Ref Defined Item)], |
|
606
|
|
|
|
|
|
|
); |
|
607
|
|
|
|
|
|
|
}), |
|
608
|
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
'Undef' => (subname '${PKG}::create_type_Undef' => sub { ## no critic |
|
610
|
|
|
|
|
|
|
my (@args) = @_; |
|
611
|
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Undef_defval" => sub { |
|
613
|
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
615
|
|
|
|
|
|
|
if scalar @args; |
|
616
|
|
|
|
|
|
|
return; |
|
617
|
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
}; |
|
619
|
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Undef_check" => sub { |
|
621
|
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
!defined $_[0]; |
|
623
|
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
}; |
|
625
|
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
return create_type_instance( |
|
627
|
|
|
|
|
|
|
'Undef', $generator, $constraint, |
|
628
|
|
|
|
|
|
|
[qw(Undef Item)], |
|
629
|
|
|
|
|
|
|
); |
|
630
|
|
|
|
|
|
|
}), |
|
631
|
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
'RegexpRef' => (subname '${PKG}::create_type_RegexpRef' => sub { ## no critic |
|
633
|
|
|
|
|
|
|
my (@args) = @_; |
|
634
|
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_RegexpRef_defval" => sub { |
|
636
|
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
638
|
|
|
|
|
|
|
if scalar @args; |
|
639
|
|
|
|
|
|
|
return; |
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
}; |
|
642
|
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_RegexpRef_check" => sub { |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
ref $_[0] eq "Regexp"; |
|
646
|
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
}; |
|
648
|
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
return create_type_instance( |
|
650
|
|
|
|
|
|
|
'RegexpRef', $generator, $constraint, |
|
651
|
|
|
|
|
|
|
[qw(RegexpRef Ref Defined Item)], |
|
652
|
|
|
|
|
|
|
); |
|
653
|
|
|
|
|
|
|
}), |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
'Int' => (subname '${PKG}::create_type_Int' => sub { ## no critic |
|
656
|
|
|
|
|
|
|
my (@args) = @_; |
|
657
|
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Int_defval" => sub { |
|
659
|
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
my ($default_value) = @args; |
|
661
|
|
|
|
|
|
|
return $default_value |
|
662
|
|
|
|
|
|
|
if defined $default_value; |
|
663
|
|
|
|
|
|
|
return; |
|
664
|
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
}; |
|
666
|
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Int_check" => sub { |
|
668
|
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
defined $_[0] && !ref $_[0] && $_[0] =~ m/^-?[0-9]+$/xms; |
|
670
|
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
}; |
|
672
|
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
return create_type_instance( |
|
674
|
|
|
|
|
|
|
'Int', $generator, $constraint, |
|
675
|
|
|
|
|
|
|
[qw(Int Number Value Defined Item)], |
|
676
|
|
|
|
|
|
|
); |
|
677
|
|
|
|
|
|
|
}), |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
'Code' => (subname '${PKG}::create_type_Code' => sub (;&;) { ## no critic |
|
680
|
|
|
|
|
|
|
my (@args) = @_; |
|
681
|
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Code_defval" => sub { |
|
683
|
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
my ($default_coderef) = @args; |
|
685
|
|
|
|
|
|
|
return defined $default_coderef ? $default_coderef |
|
686
|
|
|
|
|
|
|
: subname 'lambda-nil' => sub { }; |
|
687
|
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
}; |
|
689
|
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Code_check" => sub { |
|
691
|
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
ref $_[0] eq "CODE"; |
|
693
|
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
}; |
|
695
|
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
return create_type_instance( |
|
697
|
|
|
|
|
|
|
'Code', $generator, $constraint, |
|
698
|
|
|
|
|
|
|
[qw(Code CodeRef Ref Defined Item)], |
|
699
|
|
|
|
|
|
|
); |
|
700
|
|
|
|
|
|
|
}), |
|
701
|
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
'ClassName' => (subname '${PKG}::create_type_ClassName' => sub { ## no critic |
|
703
|
|
|
|
|
|
|
my (@args) = @_; |
|
704
|
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_ClassName_defval" => sub { |
|
706
|
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
}; |
|
708
|
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_ClassName_check" => sub { |
|
710
|
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
_is_valid_class_name($_[0]); |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
}; |
|
714
|
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
return create_type_instance( |
|
716
|
|
|
|
|
|
|
'ClassName', $generator, $constraint, |
|
717
|
|
|
|
|
|
|
[qw(ClassName)], |
|
718
|
|
|
|
|
|
|
); |
|
719
|
|
|
|
|
|
|
}), |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
'Any' => (subname '${PKG}::create_type_Any' => sub { ## no critic |
|
722
|
|
|
|
|
|
|
my (@args) = @_; |
|
723
|
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Any_defval" => sub { |
|
725
|
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
727
|
|
|
|
|
|
|
if scalar @args; |
|
728
|
|
|
|
|
|
|
return; |
|
729
|
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
}; |
|
731
|
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Any_check" => sub { |
|
733
|
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
1 |
|
735
|
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
}; |
|
737
|
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
return create_type_instance( |
|
739
|
|
|
|
|
|
|
'Any', $generator, $constraint, |
|
740
|
|
|
|
|
|
|
[qw(Any)], |
|
741
|
|
|
|
|
|
|
); |
|
742
|
|
|
|
|
|
|
}), |
|
743
|
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
'CodeRef' => (subname '${PKG}::create_type_CodeRef' => sub { ## no critic |
|
745
|
|
|
|
|
|
|
my (@args) = @_; |
|
746
|
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_CodeRef_defval" => sub { |
|
748
|
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
750
|
|
|
|
|
|
|
if scalar @args; |
|
751
|
|
|
|
|
|
|
return; |
|
752
|
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
}; |
|
754
|
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_CodeRef_check" => sub { |
|
756
|
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
ref $_[0] eq "CODE"; |
|
758
|
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
}; |
|
760
|
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
return create_type_instance( |
|
762
|
|
|
|
|
|
|
'CodeRef', $generator, $constraint, |
|
763
|
|
|
|
|
|
|
[qw(CodeRef Ref Defined Item)], |
|
764
|
|
|
|
|
|
|
); |
|
765
|
|
|
|
|
|
|
}), |
|
766
|
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
'Data' => (subname '${PKG}::create_type_Data' => sub { ## no critic |
|
768
|
|
|
|
|
|
|
my (@args) = @_; |
|
769
|
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
my $generator = subname "${PKG}::isa_Data_defval" => sub { |
|
771
|
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
return wantarray ? @args : $args[0] |
|
773
|
|
|
|
|
|
|
if scalar @args; |
|
774
|
|
|
|
|
|
|
return; |
|
775
|
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
}; |
|
777
|
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
my $constraint = subname "${PKG}::isa_Data_check" => sub { |
|
779
|
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
1 |
|
781
|
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
}; |
|
783
|
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
return create_type_instance( |
|
785
|
|
|
|
|
|
|
'Data', $generator, $constraint, |
|
786
|
|
|
|
|
|
|
[qw(Data)], |
|
787
|
|
|
|
|
|
|
); |
|
788
|
|
|
|
|
|
|
}), |
|
789
|
|
|
|
|
|
|
); |
|
790
|
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
my @ALWAYS_EXPORT = qw( |
|
793
|
|
|
|
|
|
|
find_type_constraint |
|
794
|
|
|
|
|
|
|
); |
|
795
|
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
sub import { |
|
797
|
19
|
|
|
19
|
|
2003
|
my ($this_class, @tags) = @_; |
|
798
|
19
|
|
|
|
|
76
|
my $caller_class = caller 0; |
|
799
|
|
|
|
|
|
|
|
|
800
|
19
|
|
|
|
|
157
|
my $export_class; |
|
801
|
|
|
|
|
|
|
my @subs; |
|
802
|
19
|
|
|
|
|
49
|
for my $arg (@tags) { |
|
803
|
18
|
100
|
|
|
|
148
|
if ($arg =~ m/^:/xms) { |
|
804
|
17
|
100
|
|
|
|
82
|
croak('Only one export class can be used. ', |
|
805
|
|
|
|
|
|
|
"(Used already: [$export_class] now: [$arg])") |
|
806
|
|
|
|
|
|
|
if $export_class; |
|
807
|
|
|
|
|
|
|
|
|
808
|
16
|
|
|
|
|
54
|
$export_class = $arg; |
|
809
|
|
|
|
|
|
|
} |
|
810
|
|
|
|
|
|
|
else { |
|
811
|
1
|
|
|
|
|
4
|
push @subs, $arg; |
|
812
|
|
|
|
|
|
|
} |
|
813
|
|
|
|
|
|
|
} |
|
814
|
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
my @subs_to_export |
|
816
|
14
|
|
|
|
|
66
|
= $export_class && $EXPORT_CLASS{$export_class} |
|
817
|
18
|
100
|
100
|
|
|
166
|
? (@{ $EXPORT_CLASS{$export_class}}, @subs) |
|
818
|
|
|
|
|
|
|
: @subs; |
|
819
|
|
|
|
|
|
|
|
|
820
|
16
|
|
|
16
|
|
191
|
no strict 'refs'; ## no critic |
|
|
16
|
|
|
|
|
41
|
|
|
|
16
|
|
|
|
|
11798
|
|
|
821
|
18
|
|
|
|
|
42
|
for my $sub_to_export (@subs_to_export) { |
|
822
|
141
|
|
|
|
|
639
|
(my $type = $sub_to_export) =~ s/^isa_//xms; |
|
823
|
|
|
|
|
|
|
|
|
824
|
141
|
|
|
|
|
199
|
my $real_name = $sub_to_export; |
|
825
|
141
|
100
|
|
|
|
375
|
if (exists $__TYPEALIASES__{$type}) { |
|
826
|
14
|
|
|
|
|
58
|
$real_name = q{isa_} . $__TYPEALIASES__{$type}; |
|
827
|
|
|
|
|
|
|
} |
|
828
|
|
|
|
|
|
|
|
|
829
|
141
|
|
|
|
|
221
|
my $the_subref = $__COMPAT_TYPESUBS__{$real_name}; |
|
830
|
141
|
100
|
|
|
|
274
|
if (! defined $the_subref) { |
|
831
|
1
|
|
|
|
|
17
|
croak "There is no $sub_to_export for type $type"; |
|
832
|
|
|
|
|
|
|
} |
|
833
|
|
|
|
|
|
|
|
|
834
|
140
|
|
|
|
|
372
|
install_sub_from_coderef($the_subref => $caller_class, $sub_to_export); |
|
835
|
|
|
|
|
|
|
} |
|
836
|
17
|
|
|
|
|
74
|
for my $sub_to_export (@ALWAYS_EXPORT) { |
|
837
|
17
|
|
|
|
|
85
|
install_sub_from_class($this_class, $sub_to_export => $caller_class); |
|
838
|
|
|
|
|
|
|
} |
|
839
|
|
|
|
|
|
|
|
|
840
|
17
|
|
|
|
|
527
|
return; |
|
841
|
|
|
|
|
|
|
} |
|
842
|
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
sub find_type_constraint { |
|
845
|
17
|
|
|
17
|
1
|
9183
|
my ($type_name, @defaults) = @_; |
|
846
|
17
|
|
|
|
|
30
|
my $self = __PACKAGE__; |
|
847
|
|
|
|
|
|
|
|
|
848
|
17
|
|
|
|
|
44
|
my $lazy_type_init = $self->get_type($type_name); |
|
849
|
17
|
|
|
|
|
42
|
my $type = $lazy_type_init->(@defaults); |
|
850
|
|
|
|
|
|
|
|
|
851
|
17
|
|
|
|
|
107
|
return $type; |
|
852
|
|
|
|
|
|
|
} |
|
853
|
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
sub get_type { |
|
856
|
54
|
|
|
54
|
1
|
95
|
my ($self, $type_name) = @_; |
|
857
|
|
|
|
|
|
|
|
|
858
|
54
|
100
|
|
|
|
174
|
if (exists $__TYPEALIASES__{$type_name}) { |
|
859
|
24
|
|
|
|
|
79
|
$type_name = $__TYPEALIASES__{$type_name}; |
|
860
|
|
|
|
|
|
|
} |
|
861
|
|
|
|
|
|
|
|
|
862
|
54
|
100
|
|
|
|
172
|
return if not exists $__TYPEDICT__{$type_name}; |
|
863
|
53
|
|
|
|
|
156
|
return $__TYPEDICT__{$type_name}; |
|
864
|
|
|
|
|
|
|
} |
|
865
|
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
sub get_compiled_constraint { |
|
867
|
31
|
|
|
31
|
1
|
47
|
my ($self, $type_name) = @_; |
|
868
|
31
|
50
|
|
|
|
80
|
confess "Unknown type: $type_name" |
|
869
|
|
|
|
|
|
|
if not exists $__TYPEDICT__{$type_name}; |
|
870
|
|
|
|
|
|
|
|
|
871
|
31
|
|
|
|
|
46
|
my $lazy_type_init = $__TYPEDICT__{$type_name}; |
|
872
|
31
|
|
|
|
|
73
|
my $type = $lazy_type_init->(); |
|
873
|
31
|
|
|
|
|
156
|
my $constraint = $type->constraint(); |
|
874
|
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
my $check_constraint = sub { |
|
876
|
268
|
100
|
|
268
|
|
713
|
return 1 if $constraint->(@_); |
|
877
|
191
|
|
|
|
|
1144
|
return; |
|
878
|
31
|
|
|
|
|
153
|
}; |
|
879
|
|
|
|
|
|
|
|
|
880
|
31
|
|
|
|
|
432
|
return $check_constraint; |
|
881
|
|
|
|
|
|
|
} |
|
882
|
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
sub get_types { |
|
884
|
1
|
|
|
1
|
1
|
16
|
return keys %__TYPEDICT__; |
|
885
|
|
|
|
|
|
|
} |
|
886
|
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
sub type_constraints { |
|
888
|
1
|
|
|
1
|
1
|
3
|
my ($self) = @_; |
|
889
|
|
|
|
|
|
|
|
|
890
|
1
|
|
|
|
|
2
|
my %constraints; |
|
891
|
1
|
|
|
|
|
6
|
for my $type_name ($self->get_types) { |
|
892
|
25
|
|
|
|
|
67
|
$constraints{$type_name} = $self->get_compiled_constraint($type_name); |
|
893
|
|
|
|
|
|
|
} |
|
894
|
|
|
|
|
|
|
|
|
895
|
1
|
|
|
|
|
13
|
while (my ($a_name, $a_dest) = each %__TYPEALIASES__) { |
|
896
|
6
|
|
|
|
|
47
|
$constraints{$a_name} = $self->get_compiled_constraint($a_dest); |
|
897
|
|
|
|
|
|
|
} |
|
898
|
|
|
|
|
|
|
|
|
899
|
1
|
|
|
|
|
4
|
return \%constraints; |
|
900
|
|
|
|
|
|
|
} |
|
901
|
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
sub export_type_constraints_as_functions { |
|
903
|
1
|
|
|
1
|
1
|
90
|
my ($self) = @_; |
|
904
|
1
|
|
|
|
|
7
|
my $caller_class = caller 0; |
|
905
|
|
|
|
|
|
|
|
|
906
|
16
|
|
|
16
|
|
103
|
no strict 'refs'; ## no critic |
|
|
16
|
|
|
|
|
41
|
|
|
|
16
|
|
|
|
|
2349
|
|
|
907
|
1
|
|
|
|
|
27
|
my $type_constraints = $self->type_constraints; |
|
908
|
1
|
|
|
|
|
2
|
while (my ($type, $constraint) = each %{ $type_constraints }) { |
|
|
32
|
|
|
|
|
68
|
|
|
909
|
31
|
|
|
|
|
28
|
*{ "$caller_class\::$type" } = $constraint; |
|
|
31
|
|
|
|
|
99
|
|
|
910
|
|
|
|
|
|
|
} |
|
911
|
|
|
|
|
|
|
|
|
912
|
1
|
|
|
|
|
8
|
return; |
|
913
|
|
|
|
|
|
|
} |
|
914
|
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
sub _is_valid_class_name { |
|
916
|
15
|
|
|
15
|
|
23
|
my ($class) = @_; |
|
917
|
15
|
100
|
|
|
|
51
|
return if ref $class; |
|
918
|
7
|
100
|
66
|
|
|
35
|
return if !defined $class || !length $class; |
|
919
|
|
|
|
|
|
|
|
|
920
|
16
|
|
|
16
|
|
89
|
no strict 'refs'; ## no critic |
|
|
16
|
|
|
|
|
33
|
|
|
|
16
|
|
|
|
|
12444
|
|
|
921
|
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
# check if the symbol entry exists at all. |
|
923
|
5
|
|
|
|
|
11
|
my $pack = \*::; |
|
924
|
5
|
|
|
|
|
16
|
for my $part (split q{::}, $class) { |
|
925
|
7
|
100
|
|
|
|
8
|
return if not exists ${$$pack}{"$part\::"}; |
|
|
7
|
|
|
|
|
36
|
|
|
926
|
4
|
|
|
|
|
5
|
$pack = \*{ ${$$pack}{"$part\::"} }; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
19
|
|
|
927
|
|
|
|
|
|
|
} |
|
928
|
|
|
|
|
|
|
|
|
929
|
|
|
|
|
|
|
# It's already loaded if $VERSION or @ISA is defined in the |
|
930
|
|
|
|
|
|
|
# class. |
|
931
|
2
|
100
|
|
|
|
6
|
return 1 if defined ${"${class}::VERSION"}; |
|
|
2
|
|
|
|
|
15
|
|
|
932
|
1
|
50
|
|
|
|
2
|
return 1 if defined @{"${class}::ISA"}; |
|
|
1
|
|
|
|
|
10
|
|
|
933
|
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
# It's also loaded if we find a function in that class. |
|
935
|
1
|
|
|
|
|
6
|
METHOD: |
|
936
|
1
|
|
|
|
|
2
|
for my $namespace_entry (keys %{"${class}::"}) { |
|
937
|
1
|
50
|
|
|
|
6
|
if (substr($namespace_entry, -2, 2) eq q{::}) { |
|
938
|
|
|
|
|
|
|
# It's a subclass, so skip it. |
|
939
|
0
|
|
|
|
|
0
|
next METHOD; |
|
940
|
|
|
|
|
|
|
} |
|
941
|
1
|
50
|
|
|
|
2
|
return 1 if defined &{"${class}::$namespace_entry"}; |
|
|
1
|
|
|
|
|
12
|
|
|
942
|
|
|
|
|
|
|
} |
|
943
|
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
# fail |
|
945
|
0
|
|
|
|
|
|
return; |
|
946
|
|
|
|
|
|
|
} |
|
947
|
|
|
|
|
|
|
|
|
948
|
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
1; |
|
952
|
|
|
|
|
|
|
__END__ |