File Coverage

blib/lib/Moonshine/Bootstrap/Component/DropdownButton.pm
Criterion Covered Total %
statement 10 10 100.0
branch 4 4 100.0
condition 1 2 50.0
subroutine 2 2 100.0
pod n/a
total 17 18 94.4


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::DropdownButton;
2              
3 10     10   201848 use Moonshine::Magic;
  10         135474  
  10         91  
4              
5             extends(
6             'Moonshine::Bootstrap::Component',
7             'Moonshine::Bootstrap::Component::Caret',
8             'Moonshine::Bootstrap::Component::Button'
9             );
10              
11             has(
12             dropdown_button_spec => sub {
13             {
14             switch => { default => 'default', base => 1 },
15             class_base => { default => 'dropdown-toggle' },
16             id => 1,
17             split => 0,
18             data_toggle => { default => 'dropdown' },
19             aria_haspopup => { default => 'true' },
20             aria_expanded => { default => 'true' },
21             data => 1,
22             };
23             }
24             );
25              
26             sub dropdown_button {
27 17     17   24413 my ($self) = shift;
28              
29 17   50     170 my ( $base_args, $build_args ) = $self->validate_build(
30             {
31             params => $_[0] // {},
32             spec => $self->dropdown_button_spec,
33             }
34             );
35              
36             $build_args->{data} = delete $base_args->{data}
37 17 100       190 if $build_args->{split};
38              
39 17         128 my $button = $self->button($base_args);
40              
41             $button->add_before_element(
42             $self->button(
43             { data => $build_args->{data}, class => $base_args->{class} }
44             )
45 17 100       41188 ) if $build_args->{split};
46              
47 17         8720 $button->add_child( $self->caret );
48 17         43907 return $button;
49             }
50              
51             1;
52              
53             __END__