line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Lite::Constraint::Moose; |
2
|
2
|
|
|
2
|
|
31603
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
79
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
1198
|
use utf8; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
15
|
|
5
|
2
|
|
|
2
|
|
94
|
use 5.008003; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
74
|
|
6
|
2
|
|
|
2
|
|
728
|
use FormValidator::Lite::Constraint; |
|
2
|
|
|
|
|
333
|
|
|
2
|
|
|
|
|
14
|
|
7
|
2
|
|
|
2
|
|
1135
|
use Moose::Util::TypeConstraints (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $get_constraint = Moose::Util::TypeConstraints->can('find_type_constraint'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @types = Moose::Util::TypeConstraints->list_all_type_constraints(); |
14
|
|
|
|
|
|
|
for my $name (@types) { |
15
|
|
|
|
|
|
|
my $constraint = $get_constraint->($name); |
16
|
|
|
|
|
|
|
rule $name => sub { |
17
|
|
|
|
|
|
|
my $value = $_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$constraint->check($value) or do { |
20
|
|
|
|
|
|
|
return unless $constraint->has_coercion; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$value = $constraint->coerce($value); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return $constraint->check($value); |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
__END__ |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
FormValidator::Lite::Constraint::Moose - Use Moose's type constraints. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use FormValidator::Lite; |
39
|
|
|
|
|
|
|
FormValidator::Lite->load_constraints(qw/Moose/); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $validator = FormValidator::Lite->new(CGI->new("flg=1")); |
42
|
|
|
|
|
|
|
$validator->check( |
43
|
|
|
|
|
|
|
flg => ['Bool'] |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#if you wanna use your original constraints. |
47
|
|
|
|
|
|
|
use FormValidator::Lite; |
48
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
enum 'HttpMethod' => [qw(GET HEAD POST PUT DELETE)]; #you must load before load 'FormValidator::Lite->load_constraints(qw/Moose/)' |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
FormValidator::Lite->load_constraints(qw/Moose/); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $validator = FormValidator::Lite->new(CGI->new("req_type=GET")); |
55
|
|
|
|
|
|
|
$validator->check( |
56
|
|
|
|
|
|
|
"req_type => ['HttpMethod'] |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This module provides Moose's type constraint as constraint rule of L<FormValidator::Lite> |
63
|
|
|
|
|
|
|
If you want to know the constraint, see L<Moose::Util::TypeConstraints> for details. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 AUTHOR |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Hideaki Ohno E<lt>hide.o.j55 {at} gmail.comE<gt> |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SEE ALSO |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L<FormValidator::Lite>,L<Moose::Util::TypeConstraints> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 LICENSE |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
76
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |