| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
{ |
| 6 |
package MyApp::Test; |
| 7 |
use Moose; |
| 8 |
with 'HTML::FormHandler::TraitFor::Types'; |
| 9 |
|
| 10 |
has 'foo' => ( |
| 11 |
is => 'rw', |
| 12 |
isa => 'HFH::SelectOptions', |
| 13 |
coerce => 1, |
| 14 |
); |
| 15 |
} |
| 16 |
|
| 17 |
my $obj = MyApp::Test->new( foo => [ 1 => 'One', 2 => 'Two', 3 => 'Three' ] ); |
| 18 |
|
| 19 |
is_deeply( $obj->foo, |
| 20 |
[ { value => 1, label => 'One' }, { value => 2, label => 'Two' }, { value => 3, label => 'Three' } ], |
| 21 |
'value of foo is correct' ); |
| 22 |
|
| 23 |
|
| 24 |
{ |
| 25 |
package MyApp::Form::Test; |
| 26 |
use HTML::FormHandler::Moose; |
| 27 |
extends 'HTML::FormHandler'; |
| 28 |
|
| 29 |
has_field 'foo' => ( |
| 30 |
type => 'Select', |
| 31 |
options => [ |
| 32 |
1 => 'One', |
| 33 |
2 => 'Two', |
| 34 |
3 => 'Three', |
| 35 |
], |
| 36 |
); |
| 37 |
has_field 'bar'; |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
my $form = MyApp::Form::Test->new; |
| 42 |
ok( $form ); |
| 43 |
|
| 44 |
done_testing; |