File Coverage

ex/metaobject.pl
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 19 100.0


line stmt bran cond sub pod time code
1 1     1   531 use v5.10;
  1         3  
2 1     1   7 use strict;
  1         2  
  1         21  
3 1     1   5 use warnings;
  1         1  
  1         36  
4              
5             # NOTE: this way of building the form is not covered by backwards compatibility
6             # policy. Use for educational purposes only!
7              
8             {
9              
10             package MetaForm;
11              
12             # Moo for easy role mixing and a constructor
13 1     1   582 use Moo;
  1         11640  
  1         5  
14              
15             # gives us create_form_meta function
16 1     1   1910 use Form::Tiny::Utils qw(:meta_handlers);
  1         2  
  1         223  
17              
18             # meta roles go into the qw()
19             # class roles goes into set_form_roles method call
20             my $meta = create_form_meta(__PACKAGE__, qw())
21             ->set_form_roles(['Form::Tiny::Form']);
22              
23             # if you would like to add superclasses, this is the place to do so
24             # extends '...';
25              
26             # you could use $meta directly, but you would first have to call ->bootstrap on it
27             # the from_meta method will automatically find the proper meta for this package and
28             # call that method
29             __PACKAGE__->form_meta->add_field(
30             'field-name' => (
31             required => 1,
32             )
33             );
34              
35             1;
36             }
37              
38             my $form = MetaForm->new(
39             input => {
40             'field-name' => 42,
41             }
42             );
43              
44             # just for testing
45             $form;
46