File Coverage

blib/lib/Moonshine/Bootstrap/Component/FormGroup.pm
Criterion Covered Total %
statement 20 22 90.9
branch 1 4 25.0
condition 1 2 50.0
subroutine 4 4 100.0
pod n/a
total 26 32 81.2


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::FormGroup;
2              
3 8     8   183322 use Moonshine::Magic;
  8         104980  
  8         69  
4 8     8   4597 use Params::Validate qw/ARRAYREF/;
  8         19  
  8         597  
5              
6 8     8   3912 use Switch::Back;
  8         7326542  
  8         81  
7              
8             extends (
9             'Moonshine::Bootstrap::Component',
10             'Moonshine::Bootstrap::Component::SubmitButton',
11             'Moonshine::Bootstrap::Component::Input',
12             );
13              
14             has(
15             form_group_spec => sub {
16             {
17             tag => { default => 'div' },
18             class_base => { default => 'form-group' },
19             fields => {
20             type => ARRAYREF,
21             build => 1,
22             }
23             };
24             }
25             );
26              
27             sub form_group {
28 11     11   10106 my ($self) = shift;
29              
30 11   50     157 my ( $base_args, $build_args ) = $self->validate_build(
31             {
32             params => $_[0] // {},
33             spec => $self->form_group_spec,
34             }
35             );
36              
37 11         170 my $form_group = Moonshine::Element->new($base_args);
38              
39 11         32613 for my $field ( @{ $build_args->{fields} } ) {
  11         68  
  11         25  
40 11 50       28 given ( delete $field->{field_type} ) {
  11 0       60  
  11         76  
41 0         0 when ( 'text' ) {
42 11         1956 $form_group->add_child( $self->input($field) );
43             }
44             when ( 'submit' ) {
45 0         0 $form_group->add_child( $self->submit_button($field) );
46             }
47             }
48             }
49              
50 11         28654 return $form_group;
51             }
52              
53             1;
54              
55             __END__