Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use Test::More;
- {
- package Compound;
- use HTML::FormHandler::Moose;
- extends 'HTML::FormHandler::Field::Compound';
- has_field 'year' => (
- type => 'Integer',
- required => 1,
- );
- has_field 'month' => (
- type => 'Integer',
- range_start => 1,
- range_end => 12,
- );
- has_field 'day' => (
- type => 'Integer',
- range_start => 1,
- range_end => 31,
- );
- sub default {
- return {
- year => undef,
- month => undef,
- day => undef
- };
- }
- }
- {
- package Form;
- use HTML::FormHandler::Moose;
- extends 'HTML::FormHandler';
- has_field 'date' => ( type => '+Compound' );
- has_field 'foo';
- }
- my $f = Form->new;
- $f->process( { 'date.day' => '18', 'date.month' => '2', 'date.year' => '2010' } );
- is_deeply( $f->field('date')->value, { year => 2010, month => 2, day => 18 }, 'correct value' );
- $f = Form->new;
- $f->process( { 'testing' => 'foo' } );
- is_deeply( $f->field('date')->value, { year => undef, month => undef, day => undef }, 'correct default' );
- $f = Form->new;
- $f->process( { 'date.day' => '', 'date.month' => '', 'date.year' => '' } );
- is_deeply( $f->field('date')->value, { year => undef, month => undef, day => undef }, 'correct default' );
- done_testing;
Add Comment
Please, Sign In to add comment