File Coverage

blib/lib/Moonshine/Bootstrap/Component/Alert.pm
Criterion Covered Total %
statement 16 16 100.0
branch 2 2 100.0
condition 1 2 50.0
subroutine 4 4 100.0
pod n/a
total 23 24 95.8


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::Alert;
2              
3 5     5   230375 use Moonshine::Magic;
  5         133823  
  5         37  
4 5     5   2730 use Params::Validate qw/HASHREF/;
  5         10  
  5         394  
5 5     5   54 use Moonshine::Util;
  5         12  
  5         47  
6              
7             lazy_components qw/a/;
8             extends 'Moonshine::Bootstrap::Component';
9              
10             has(
11             alert_spec => sub {
12             {
13             tag => { default => 'div' },
14             class_base => { default => 'alert' },
15             switch => { default => 'success' },
16             switch_base => { default => 'alert-' },
17             link => { type => HASHREF, optional => 1 },
18             };
19             }
20             );
21              
22             sub alert {
23 13     13   82446 my ($self) = shift;
24              
25 13   50     108 my ( $base_args, $build_args ) = $self->validate_build(
26             {
27             params => $_[0] // {},
28             spec => $self->alert_spec,
29             }
30             );
31              
32 13         162 my $base_element = Moonshine::Element->new($base_args);
33              
34 13 100       36419 if ( my $link = $build_args->{link} ) {
35 2         17 $link->{class} = append_str('alert-link', $link->{class});
36 2         23 $base_element->add_child( $self->a($link) );
37             }
38              
39 13         5212 return $base_element;
40             }
41              
42             1;
43              
44             __END__