File: undef_deflation.t

package info (click to toggle)
libhtml-formhandler-perl 0.40068-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 2,484 kB
  • sloc: perl: 9,416; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use strict;
use warnings;
use Test::More;

{
    package MyApp::Form::Test;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';

    has_field 'foo' => ( deflate_method => \&deflate_foo );
    has_field 'bar';

    sub deflate_foo {
        my ( $self, $value ) = @_;
        if ( ! defined $value ) {
            $value = 'deflated';
        }
        return $value;
    }

}

my $form = MyApp::Form::Test->new;
ok( $form );

my $init_obj = {
   foo => undef,
   bar => 'somebar',
};

$form->process( init_object => $init_obj, params => {} );
my $fif = $form->fif;
is_deeply( $fif, { foo => 'deflated', bar => 'somebar' }, 'undef value was deflated' );

done_testing;