File Coverage

blib/lib/Moonshine/Bootstrap/Component/DropdownUl.pm
Criterion Covered Total %
statement 17 22 77.2
branch 3 6 50.0
condition 1 2 50.0
subroutine 3 3 100.0
pod n/a
total 24 33 72.7


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::DropdownUl;
2              
3 15     15   245265 use Moonshine::Magic;
  15         143041  
  15         146  
4 15     15   8681 use Params::Validate qw/ARRAYREF/;
  15         39  
  15         1445  
5              
6             extends(
7             'Moonshine::Bootstrap::Component',
8             'Moonshine::Bootstrap::Component::LinkedLi',
9             'Moonshine::Bootstrap::Component::SeparatorLi',
10             'Moonshine::Bootstrap::Component::DropdownHeaderLi',
11             );
12              
13             has(
14             dropdown_ul_spec => sub {
15             {
16             tag => { default => 'ul' },
17             class_base => { default => 'dropdown-menu' },
18             alignment_base => { default => 'dropdown-menu-' },
19             separators => { type => ARRAYREF, optional => 1 },
20             headers => { type => ARRAYREF, optional => 1 },
21             };
22             }
23             );
24              
25             sub dropdown_ul {
26 26     26   98119 my ($self) = shift;
27              
28 26   50     262 my ( $base_args, $build_args ) = $self->validate_build(
29             {
30             params => $_[0] // {},
31             spec => $self->dropdown_ul_spec,
32             }
33             );
34              
35 26         410 my $base_element = Moonshine::Element->new($base_args);
36              
37 26 50       61127 if ( $build_args->{headers} ) {
38 0         0 for ( @{ $build_args->{headers} } ) {
  0         0  
39 0 0       0 my $index = delete $_->{index} or die "No index";
40 0         0 splice @{ $base_element->{children} }, $index - 1, 0,
  0         0  
41             $self->dropdown_header_li($_);
42             }
43             }
44              
45 26 100       121 if ( $build_args->{separators} ) {
46 14         129 my $separator = $self->separator_li;
47 14         35051 for ( @{ $build_args->{separators} } ) {
  14         67  
48 38         62 splice @{ $base_element->{children} }, $_ - 1, 0, $separator;
  38         182  
49             }
50             }
51              
52 26         251 return $base_element;
53             }
54              
55             1;
56              
57             __END__