1use strict;
2use warnings;
3
4# base the package name on the test file path
5# to stop 'redefined' warnings under Test::Aggregate::Nested
6package My::Constraints::Callback;
7use HTML::FormFu;
8
9my $form = HTML::FormFu->new;
10
11$form->element('Text')->name('foo')->constraint('Callback')->callback( \&cb );
12$form->element('Text')->name('bar')->constraint('Callback')
13    ->callback("My::Constraints::Callback::cb");
14
15sub cb {
16    my $value = shift;
17    ::ok(1) if grep { $value eq $_ ? 1 : 0 } qw/ 1 0 a /;
18    return 1;
19}
20
21package main;
22
23use Test::More tests => 5;
24
25# Valid
26{
27    $form->process(
28        {   foo => 1,
29            bar => [ 0, 'a', 'b' ],
30        } );
31
32    ::ok( $form->valid('foo'), 'foo valid' );
33    ::ok( $form->valid('bar'), 'bar valid' );
34}
35