line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
814
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
201
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::Callback; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Constraint::Callback::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Code Callback Constraint |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
17
|
use Moose; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
27
|
|
8
|
3
|
|
|
3
|
|
20930
|
use MooseX::Attribute::Chained; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
352
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has callback => ( is => 'rw', traits => ['Chained'] ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub constrain_value { |
14
|
5
|
|
|
5
|
0
|
15
|
my ( $self, $value, $params ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
50
|
0
|
|
157
|
my $callback = $self->callback || sub {1}; |
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
## no critic (ProhibitNoStrict); |
19
|
3
|
|
|
3
|
|
22
|
no strict 'refs'; |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
274
|
|
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
26
|
my $ok = $callback->( $value, $params ); |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
|
|
1834
|
return $ok; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__END__ |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=pod |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=encoding UTF-8 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
HTML::FormFu::Constraint::Callback - Code Callback Constraint |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 VERSION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
version 2.07 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$field->constraint({ |
47
|
|
|
|
|
|
|
type => 'Callback', |
48
|
|
|
|
|
|
|
callback => \&foo, |
49
|
|
|
|
|
|
|
}); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
--- |
52
|
|
|
|
|
|
|
elements: |
53
|
|
|
|
|
|
|
- type: Text |
54
|
|
|
|
|
|
|
name: foo |
55
|
|
|
|
|
|
|
constraints: |
56
|
|
|
|
|
|
|
- type: Callback |
57
|
|
|
|
|
|
|
callback: "main::my_constraint" |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub foo { |
60
|
|
|
|
|
|
|
my ( $value, $params ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# return true or false |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
The first argument passed to the callback is the submitted value for the |
68
|
|
|
|
|
|
|
associated field. The second argument passed to the callback is a hashref of |
69
|
|
|
|
|
|
|
name/value pairs for all input fields. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This constraint doesn't honour the C<not()> value. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 callback |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Arguments: \&code-reference |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Arguments: "subroutine-name" |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
L<HTML::FormFu> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
94
|
|
|
|
|
|
|
the same terms as Perl itself. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
105
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |