line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::CallbackOnce; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
849
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
189
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
18
|
use Moose; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
72
|
|
7
|
4
|
|
|
4
|
|
17103
|
use MooseX::Attribute::FormFuChained; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
429
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has callback => ( is => 'rw', traits => ['FormFuChained'] ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub process { |
13
|
8
|
|
|
8
|
0
|
10
|
my ( $self, $params ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# check when condition |
16
|
8
|
50
|
|
|
|
26
|
return if !$self->_process_when($params); |
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
|
|
30
|
my $value = $self->get_nested_hash_value( $params, $self->nested_name ); |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
50
|
0
|
|
210
|
my $callback = $self->callback || sub {1}; |
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
## no critic (ProhibitNoStrict); |
23
|
4
|
|
|
4
|
|
17
|
no strict 'refs'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
422
|
|
24
|
|
|
|
|
|
|
|
25
|
8
|
|
|
|
|
10
|
my $ok = eval { $callback->( $value, $params ) }; |
|
8
|
|
|
|
|
19
|
|
26
|
|
|
|
|
|
|
|
27
|
8
|
100
|
66
|
|
|
2378
|
return $self->mk_errors( { |
28
|
|
|
|
|
|
|
pass => ( $@ or !$ok ) ? 0 : 1, |
29
|
|
|
|
|
|
|
message => $@, |
30
|
|
|
|
|
|
|
} ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
HTML::FormFu::Constraint::CallbackOnce - Code Callback Constraint |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 VERSION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
version 2.05 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$form->constraint({ |
50
|
|
|
|
|
|
|
type => 'CallbackOnce', |
51
|
|
|
|
|
|
|
name => 'foo', |
52
|
|
|
|
|
|
|
callback => \&sfoo, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub foo { |
56
|
|
|
|
|
|
|
my ( $value, $params ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# return true or false |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Unlinke the L<HTML::FormFu::Constraint::Callback>, this callback is only |
64
|
|
|
|
|
|
|
called once, regardless of how many values are submitted. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The first argument passed to the callback is the submitted value for the |
67
|
|
|
|
|
|
|
associated field; this may be a single value or an arrayref of value. |
68
|
|
|
|
|
|
|
The second argument passed to the callback is a hashref of name/value pairs |
69
|
|
|
|
|
|
|
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: \&sub_ref |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SEE ALSO |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L<HTML::FormFu> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 LICENSE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
92
|
|
|
|
|
|
|
the same terms as Perl itself. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |