File Coverage

blib/lib/Moonshine/Bootstrap/Component/Nav.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition 1 2 50.0
subroutine 4 4 100.0
pod n/a
total 25 26 96.1


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::Nav;
2              
3 8     8   189712 use Moonshine::Magic;
  8         134885  
  8         68  
4 8     8   4587 use Moonshine::Util;
  8         21  
  8         128  
5 8     8   4565 use Params::Validate qw/ARRAYREF/;
  8         22  
  8         709  
6              
7             extends (
8             'Moonshine::Bootstrap::Component',
9             'Moonshine::Bootstrap::Component::NavItem',
10             );
11              
12             has(
13             nav_spec => sub {
14             {
15             tag => { default => 'ul' },
16             class_base => { default => 'nav' },
17             switch_base => { default => 'nav-' },
18             stacked => 0,
19             justified_base => { default => 'nav-justified' },
20             nav_items => { type => ARRAYREF, default => [ ] },
21             };
22             }
23             );
24              
25             sub nav {
26 27     27   163794 my ($self) = shift;
27              
28 27   50     322 my ( $base_args, $build_args ) = $self->validate_build(
29             {
30             params => $_[0] // {},
31             spec => $self->nav_spec,
32             }
33             );
34              
35 27 100       362 if ( $build_args->{stacked} ) {
36 2         10 $base_args->{class} = prepend_str('nav-stacked', $base_args->{class});
37             }
38              
39 27         249 my $base_element = Moonshine::Element->new($base_args);
40              
41 27         73482 for ( @{ $build_args->{nav_items} } ) {
  27         186  
42 81         2337 $base_element->add_child(
43             $self->nav_item($_)
44             );
45             }
46              
47 27         1181 return $base_element;
48             }
49              
50             1;
51              
52             __END__