File Coverage

blib/lib/Moonshine/Bootstrap/Component.pm
Criterion Covered Total %
statement 56 56 100.0
branch 9 10 90.0
condition n/a
subroutine 12 12 100.0
pod 0 1 0.0
total 77 79 97.4


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component;
2              
3 74     74   445007 use 5.006;
  74         336  
4 74     74   588 use strict;
  74         174  
  74         2842  
5 74     74   438 use warnings;
  74         197  
  74         5919  
6              
7 74     74   2059 use Moonshine::Element;
  74         109247  
  74         2763  
8 74     74   1472 use Moonshine::Magic;
  74         127487  
  74         561  
9 74     74   50268 use Moonshine::Util;
  74         186  
  74         919  
10 74     74   87057 use Moonshine::Component;
  74         343223  
  74         4517  
11 74     74   609 use Params::Validate qw(:all);
  74         144  
  74         15411  
12 74     74   644 use feature qw/switch/;
  74         204  
  74         10132  
13 74     74   528 no if $] >= 5.017011, warnings => 'experimental::smartmatch';
  74         190  
  74         4738  
14              
15             extends ("Moonshine::Component");
16              
17             our $VERSION = '0.05';
18              
19             BEGIN {
20             my %grid = (
21             map {
22 74     74   69824 $_ => 0,
  222         4216  
23             $_ . '_base' => { default => 'col-' . $_ . '-' },
24             $_ . '_offset' => 0,
25             $_ . '_offset_base' => { default => 'col-' . $_ . '-offset-' },
26             $_ . '_pull' => 0,
27             $_ . '_pull_base' => { default => 'col-' . $_ . '-pull-' },
28             $_ . '_push' => 0,
29             $_ . '_push_base' => { default => 'col-' . $_ . '-push-' },
30             } qw/xs sm md/
31             );
32              
33             my %modify_spec = (
34             (
35 1110         2470 map { $_ => 0 }
36             qw/row switch lead txt switch_base class_base sizing
37             sizing_base alignment alignment_base active disable
38             justified justified_base container/
39             ),
40             (
41 222         1250 map { $_ => { optional => 1, type => ARRAYREF } }
42             qw/before_element after_element children/
43             ),
44             %grid,
45             (
46 74         540 map { $_ . '_base' => { default => $_ } }
  296         3216  
47             qw/active lead row container/
48             ),
49             disable_base => { default => 'disabled' },
50             txt_base => { default => 'text-' },
51             );
52             has(
53             modifier_spec => sub {
54             return \%modify_spec;
55             },
56             grid_spec => sub {
57             return \%grid
58             }
59 74         3694 );
60             }
61              
62             sub modify {
63 1342     1342 0 555785 my $self = shift;
64 1342         4751 my ( $base, $build, $modify ) = @_;
65              
66 1342         3768 for (qw/class_base/) {
67 1342 100       5668 if ( defined $modify->{$_} ) {
68 585         4632 $base->{class} = prepend_str( $modify->{ $_ }, $base->{class} );
69             }
70             }
71              
72 16104         29017 my @grid_keys = map { $_ }
73 1342         7089 grep { $_ !~ m{_base$}xms } sort keys %{ $self->grid_spec };
  32208         74826  
  1342         15096  
74 1342         6732 for ( @grid_keys, qw/switch sizing alignment txt/ ) {
75 21472 100       156804 if ( my $append_class = join_class( $modify->{ $_ . '_base' }, $modify->{$_} ) ) {
76 287         2628 $base->{class} = prepend_str( $append_class, $base->{class} );
77             }
78             }
79              
80 1342         10005 for (qw/active justified disable row lead/) {
81 6710 100       16669 if ( defined $modify->{$_} ) {
82 78         563 $base->{class} = prepend_str( $modify->{ $_ . '_base' }, $base->{class} );
83             }
84             }
85              
86 1342 100       7437 if ( my $container = $modify->{container} ) {
87 2         5 my $cb = $modify->{container_base};
88 2 50       14 my $container_class = ( $container =~ m/^\D/ )
89             ? sprintf "%s-%s", $cb, $container
90             : $cb;
91 2         12 $base->{class} = prepend_str( $container_class, $base->{class} );
92             }
93              
94 1342         50910 return $base, $build, $modify;
95             }
96              
97             1;
98              
99             __END__