File Coverage

blib/lib/Moonshine/Bootstrap/Component/InputGroupAddon.pm
Criterion Covered Total %
statement 24 24 100.0
branch 8 8 100.0
condition 1 2 50.0
subroutine 3 3 100.0
pod n/a
total 36 37 97.3


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::InputGroupAddon;
2              
3 6     6   169698 use Moonshine::Magic;
  6         106796  
  6         55  
4 6     6   3593 use Params::Validate qw/HASHREF/;
  6         19  
  6         521  
5              
6             extends (
7             'Moonshine::Bootstrap::Component',
8             'Moonshine::Bootstrap::Component::Input',
9             'Moonshine::Bootstrap::Component::DropdownButton',
10             'Moonshine::Bootstrap::Component::DropdownUl',
11             );
12              
13             has(
14             input_group_addon_spec => sub {
15             {
16             tag => { default => 'span' },
17             class_base => { default => 'input-group-addon' },
18             checkbox => 0,
19             radio => 0,
20             button => { type => HASHREF, optional => 1 },
21             dropdown => { type => HASHREF, optional => 1 },
22             };
23             }
24             );
25              
26             sub input_group_addon {
27 27     27   72551 my ($self) = shift;
28              
29 27   50     220 my ( $base_args, $build_args ) = $self->validate_build(
30             {
31             params => $_[0] // {},
32             spec => $self->input_group_addon_spec,
33             }
34             );
35              
36 27         305 my $base_element = Moonshine::Element->new($base_args);
37            
38 27 100       54939 if ( my $button = $build_args->{button} ) {
39 2         29 $base_element->class("input-group-btn");
40 2         79 $base_element->add_child( $self->button($button) );
41             }
42              
43 27 100       4309 if ( my $dropdown = $build_args->{dropdown} ) {
44 3         39 $base_element->class("input-group-btn");
45 3         57 $base_element->tag('div');
46             $base_element->add_child(
47             $self->dropdown_button(
48 3         73 { %{ $dropdown->{button} }, id => $dropdown->{mid} }
49             )
50 3         33 );
51             $base_element->add_child(
52             $self->dropdown_ul(
53 3         52 { %{ $dropdown->{ul} }, aria_labelledby => $dropdown->{mid} }
54             )
55 3         51 );
56             }
57              
58 27 100       195 if ( $build_args->{checkbox} ) {
59 2         33 $base_element->add_child($self->input( { type => 'checkbox' } ));
60             }
61              
62 27 100       3847 if ( $build_args->{radio} ) {
63 2         24 $base_element->add_child($self->input( { type => 'radio' } ));
64             }
65              
66 27         5800 return $base_element;
67             }
68              
69             1;
70              
71             __END__