Guest User

Untitled

a guest
May 27th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3. use Test::More;
  4.  
  5. {
  6.  
  7. package Compound;
  8. use HTML::FormHandler::Moose;
  9. extends 'HTML::FormHandler::Field::Compound';
  10.  
  11. has_field 'year' => (
  12. type => 'Integer',
  13. required => 1,
  14. );
  15.  
  16. has_field 'month' => (
  17. type => 'Integer',
  18. range_start => 1,
  19. range_end => 12,
  20. );
  21.  
  22. has_field 'day' => (
  23. type => 'Integer',
  24. range_start => 1,
  25. range_end => 31,
  26. );
  27.  
  28. sub default {
  29. return {
  30. year => undef,
  31. month => undef,
  32. day => undef
  33. };
  34. }
  35. }
  36.  
  37. {
  38.  
  39. package Form;
  40. use HTML::FormHandler::Moose;
  41. extends 'HTML::FormHandler';
  42. has_field 'date' => ( type => '+Compound' );
  43. has_field 'foo';
  44. }
  45.  
  46. my $f = Form->new;
  47. $f->process( { 'date.day' => '18', 'date.month' => '2', 'date.year' => '2010' } );
  48. is_deeply( $f->field('date')->value, { year => 2010, month => 2, day => 18 }, 'correct value' );
  49.  
  50. $f = Form->new;
  51. $f->process( { 'testing' => 'foo' } );
  52. is_deeply( $f->field('date')->value, { year => undef, month => undef, day => undef }, 'correct default' );
  53.  
  54. $f = Form->new;
  55. $f->process( { 'date.day' => '', 'date.month' => '', 'date.year' => '' } );
  56. is_deeply( $f->field('date')->value, { year => undef, month => undef, day => undef }, 'correct default' );
  57.  
  58. done_testing;
Add Comment
Please, Sign In to add comment