package Test::Form;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use DateTime;
has_constraint 'contains_aaa' => ( action => qr/aaa/, message =>
'Must contain aaa' );
has_constraint 'greater_than_10' => ( action => sub { return $_[0] > 10 } },
message => 'must be greater than 10' );
has_filter 'eight_leading_zeros' => ( action => sub{ printf("%08d",
_[0] ) } );
has_constraint 'only_mondays' => ( action => sub {
$_[0]->day_of_week eq 'Monday' }, message => 'Only Mondays' );
has_filter 'date_time' => ( action => sub{ DateTime->new( $_[0] )
}, message => 'Incorrect Date' );
has_field 'some_text' => ( actions => [ 'contains_aaa' ] );
has_field 'number' => ( actions => [ 'greater_than_10',
'eight_leading_zeros' ] );
has_field 'date_time' => (
type => 'Compound',
actions => [ 'date_time', 'only_mondays' ],
);
has_field 'date_time.year';
has_field 'date_time.month';
has_field 'date_time.day';
####
has_constraint 'contains_aaa' => ( qr/aaa/, 'Must contain aaa' );
##
##
package Test::Form;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use DateTime;
has_field 'some_text' => (
actions => [
{ check => qr/aaa/, message => 'Must contain aaa' }
]
);
has_field 'number' => (
actions => [
{
check => sub { return $_[0] > 10 },
message => 'must be greater than 10'
},
{ transformation => sub{ printf("%08d", _[0] ) } },
]
);
has_field 'date_time' => (
type => 'Compound',
actions => [
{
transformation => sub{ DateTime->new( $_[0] ) },
message => 'Incorrect Date'
},
{
check => sub { $_[0]->day_of_week eq 'Monday' },
message => 'Only Mondays'
},
],
);
has_field 'date_time.year';
has_field 'date_time.month';
has_field 'date_time.day';