File: include.t

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download | duplicates (5)
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
36
37
38
39
40
41
42
43
use strict;
use warnings;
use Test::More;

# Test using the 'include' attribute on a compound field
# to limit the fields that are built.
# alternative to active/inactive. Created for a situation
# in which there are a very large number of fields in a
# field/role and you don't want the overhead of building them
# and then setting them activie/inactive.
{
    package Test::FooField;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler::Field::Compound';

    has_field 'foo';
    has_field 'bar';
    has_field 'box';
    has_field 'mix';
    has_field 'nix';

}

my $field = Test::FooField->new( name => 'muddly' );
ok( $field );

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

    has_field 'fiddly';
    has_field 'muddly' => ( type => '+Test::FooField', include => ['foo', 'mix', 'nix'] );
    # no subfields. kinda weird...
    has_field 'middly' => ( type => '+Test::FooField', include => [ 'empty' ] );
}

my $form = Test::Form->new;
ok( $form );
is( $form->field('muddly')->num_fields, 3, 'right number of fields' );
is( $form->field('middly')->num_fields, 0, 'right number of fields' );

done_testing;