line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Params::TypeConstraints; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$MooseX::Params::TypeConstraints::VERSION = '0.010'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
71128
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1465
|
use Moose::Util::TypeConstraints; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use MooseX::Params::Meta::TypeConstraint::Listable; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $registry = Moose::Util::TypeConstraints::get_type_constraint_registry; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$registry->add_type_constraint( |
15
|
|
|
|
|
|
|
MooseX::Params::Meta::TypeConstraint::Listable->new( |
16
|
|
|
|
|
|
|
name => 'Array', |
17
|
|
|
|
|
|
|
package_defined_in => __PACKAGE__, |
18
|
|
|
|
|
|
|
parent => |
19
|
|
|
|
|
|
|
Moose::Util::TypeConstraints::find_type_constraint('Ref'), |
20
|
|
|
|
|
|
|
listable => 1, |
21
|
|
|
|
|
|
|
constraint => sub { ref($_) eq 'ARRAY' }, |
22
|
|
|
|
|
|
|
constraint_generator => sub { |
23
|
|
|
|
|
|
|
my $type_parameter = shift; |
24
|
|
|
|
|
|
|
my $check = $type_parameter->_compiled_type_constraint; |
25
|
|
|
|
|
|
|
return sub { |
26
|
|
|
|
|
|
|
foreach my $x (@$_) { |
27
|
|
|
|
|
|
|
( $check->($x) ) || return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
inlined => sub { 'ref(' . $_[1] . ') eq "ARRAY"' }, |
33
|
|
|
|
|
|
|
inline_generator => sub { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my $type_parameter = shift; |
36
|
|
|
|
|
|
|
my $val = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
'do {' |
39
|
|
|
|
|
|
|
. 'my $check = ' . $val . ';' |
40
|
|
|
|
|
|
|
. 'ref($check) eq "ARRAY" ' |
41
|
|
|
|
|
|
|
. '&& &List::MoreUtils::all(' |
42
|
|
|
|
|
|
|
. 'sub { ' . $type_parameter->_inline_check('$_') . ' }, ' |
43
|
|
|
|
|
|
|
. '@{$check}' |
44
|
|
|
|
|
|
|
. ')' |
45
|
|
|
|
|
|
|
. '}'; |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
) |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$registry->add_type_constraint( |
51
|
|
|
|
|
|
|
MooseX::Params::Meta::TypeConstraint::Listable->new( |
52
|
|
|
|
|
|
|
name => 'Hash', |
53
|
|
|
|
|
|
|
package_defined_in => __PACKAGE__, |
54
|
|
|
|
|
|
|
parent => |
55
|
|
|
|
|
|
|
Moose::Util::TypeConstraints::find_type_constraint('Ref'), |
56
|
|
|
|
|
|
|
listable => 1, |
57
|
|
|
|
|
|
|
constraint => sub { ref($_) eq 'HASH' }, |
58
|
|
|
|
|
|
|
constraint_generator => sub { |
59
|
|
|
|
|
|
|
my $type_parameter = shift; |
60
|
|
|
|
|
|
|
my $check = $type_parameter->_compiled_type_constraint; |
61
|
|
|
|
|
|
|
return sub { |
62
|
|
|
|
|
|
|
foreach my $x ( values %$_ ) { |
63
|
|
|
|
|
|
|
( $check->($x) ) || return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
inlined => sub { 'ref(' . $_[1] . ') eq "HASH"' }, |
69
|
|
|
|
|
|
|
inline_generator => sub { |
70
|
|
|
|
|
|
|
my $self = shift; |
71
|
|
|
|
|
|
|
my $type_parameter = shift; |
72
|
|
|
|
|
|
|
my $val = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
'do {' |
75
|
|
|
|
|
|
|
. 'my $check = ' . $val . ';' |
76
|
|
|
|
|
|
|
. 'ref($check) eq "HASH" ' |
77
|
|
|
|
|
|
|
. '&& &List::MoreUtils::all(' |
78
|
|
|
|
|
|
|
. 'sub { ' . $type_parameter->_inline_check('$_') . ' }, ' |
79
|
|
|
|
|
|
|
. 'values %{$check}' |
80
|
|
|
|
|
|
|
. ')' |
81
|
|
|
|
|
|
|
. '}'; |
82
|
|
|
|
|
|
|
}, |
83
|
|
|
|
|
|
|
) |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
package Moose::Util::TypeConstraints; |
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
$Moose::Util::TypeConstraints::VERSION = '0.010'; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my @NEW_PARAMETERIZABLE_TYPES |
92
|
|
|
|
|
|
|
= map { $registry->get_type_constraint($_) } qw[ScalarRef Array ArrayRef Hash HashRef Maybe]; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
no warnings 'redefine'; |
95
|
|
|
|
|
|
|
sub get_all_parameterizable_types {@NEW_PARAMETERIZABLE_TYPES} |
96
|
|
|
|
|
|
|
use warnings 'redefine'; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |
101
|
|
|
|
|
|
|
=pod |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=for :stopwords Peter Shangov TODO invocant isa metaroles metarole multimethods sourcecode |
104
|
|
|
|
|
|
|
backwards buildargs checkargs slurpy preprocess |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 NAME |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
MooseX::Params::TypeConstraints |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 VERSION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
version 0.010 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Peter Shangov <pshangov@yahoo.com> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Peter Shangov. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
123
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|