File Coverage

blib/lib/Moonshine/Bootstrap/Component.pm
Criterion Covered Total %
statement 44 49 89.8
branch 5 8 62.5
condition n/a
subroutine 11 11 100.0
pod 0 1 0.0
total 60 69 86.9


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component;
2              
3 2     2   114696 use 5.006;
  2         4  
4 2     2   6 use strict;
  2         3  
  2         33  
5 2     2   5 use warnings;
  2         14  
  2         48  
6              
7 2     2   887 use Moonshine::Element;
  2         41575  
  2         57  
8 2     2   923 use Moonshine::Magic;
  2         13910  
  2         18  
9 2     2   2135 use Moonshine::Util qw/join_class prepend_str append_str/;
  2         9276  
  2         176  
10 2     2   1507 use Moonshine::Component;
  2         13999  
  2         96  
11 2     2   16 use feature qw/switch/;
  2         3  
  2         170  
12 2     2   10 no if $] >= 5.017011, warnings => 'experimental::smartmatch';
  2         4  
  2         14  
13              
14             extends "Moonshine::Component";
15              
16             our $VERSION = '0.02';
17              
18             BEGIN {
19             my %modify_spec = (
20             (
21 30         31 map { $_ => 0 }
22             qw/row switch lead txt switch_base class_base sizing
23             sizing_base alignment alignment_base active disable
24             justified justified_base container/
25             ),
26             (
27 6         14 map { $_ => { optional => 1, type => 'ARRAYREF' } }
28             qw/before_element after_element children/
29             ),
30             (
31             map {
32 6         51 $_ => 0,
33             $_ . '_base' => { default => 'col-' . $_ . '-' },
34             $_ . '_offset' => 0,
35             $_ . '_offset_base' => { default => 'col-' . $_ . '-offset-' },
36             $_ . '_pull' => 0,
37             $_ . '_pull_base' => { default => 'col-' . $_ . '-pull-' },
38             $_ . '_push' => 0,
39             $_ . '_push_base' => { default => 'col-' . $_ . '-push-' },
40             } qw/xs sm md/
41             ),
42             (
43 2     2   827 map { $_ . '_base' => { default => $_ } }
  8         79  
44             qw/active lead row container/
45             ),
46             disable_base => { default => 'disabled' },
47             txt_base => { default => 'text-' },
48             );
49             has(
50             modifier_spec => sub {
51             return \%modify_spec;
52             }
53 2         68 );
54             }
55              
56             sub modify {
57 4     4 0 2249 my $self = shift;
58 4         5 my ( $base, $build, $modify ) = @_;
59              
60 4         7 for (qw/class active justified disable row lead/) {
61 24 100       43 if ( defined $modify->{$_} ) {
62 1         5 $base->{class} = prepend_str( $modify->{ $_ . '_base' }, $base->{class} );
63             }
64             }
65              
66 0         0 my @grid_keys = map { $_ }
67 4         5 grep { $_ !~ m{^.*_base$}xms } sort keys %{ $self->{grid_spec} };
  0         0  
  4         15  
68 4         7 for ( @grid_keys, qw/sizing alignment txt switch/ ) {
69 16 100       78 if ( my $append_class = join_class( $modify->{ $_ . '_base' }, $modify->{$_} ) ) {
70 7         37 $base->{class} = prepend_str( $append_class, $base->{class} );
71             }
72             }
73              
74              
75 4 50       24 if ( my $container = $modify->{container} ) {
76 0         0 my $cb = $modify->{container_base};
77 0 0       0 my $container_class = ( $container =~ m/^\D/ )
78             ? sprintf "%s-%s", $cb, $container
79             : $cb;
80 0         0 $base->{class} = prepend_str( $container_class, $base->{class} );
81             }
82              
83 4         11 return $base, $build, $modify;
84             }
85              
86             1;
87              
88             __END__