blib/lib/Tags/HTML/Container.pm

filter: Statementstmt 100% 81 / 81 Branchbran 100% 16 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 100% 1 / 1 totaltotal 100% 115 / 115 CC 9 SCAR 5.9
CC
9
Cov
100%
new
3.0
_process_css
3.0
_cleanup
2.0
CRAP 1.8
↑ Summary
1 package Tags::HTML::Container;
2  
3 8 ▶use base qw(Tags::HTML);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Class::Utils qw(set_params split_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use List::Util 1.33 qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Mo::utils 0.01 qw(check_required);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Mo::utils::CSS 0.07 qw(check_css_class check_css_unit);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 Readonly::Array our @HORIZ_ALIGN => qw(center left right);
15 8 Readonly::Array our @VERT_ALIGN => qw(base bottom center fit top);
16 8 Readonly::Hash our %VERT_CONV => (
17 'base' => 'baseline',
18 'bottom' => 'flex-end',
19 'center' => 'center',
20 'fit' => 'stretch',
21 'top' => 'flex-start',
22 );
23  
24 8 our $VERSION = 0.10;
25  
26 36 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
27 36 my ($class, @params) = @_;
28  
29 # Create object.
30 36 my ($object_params_ar, $other_params_ar) = split_params(
31 ['css_container', 'css_inner', 'height', 'horiz_align',
32 'padding', 'vert_align'], @params);
33 36 my $self = $class->SUPER::new(@{$other_params_ar});
34  
35 # Container align.
36 32 $self->{'horiz_align'} = 'center';
37 32 $self->{'vert_align'} = 'center';
38  
39 # CSS classes.
40 32 $self->{'css_container'} = 'container';
41 32 $self->{'css_inner'} = 'inner';
42  
43 # Height.
44 32 $self->{'height'} = '100vh';
45  
46 # Padding.
47 32 $self->{'padding'} = undef;
48  
49 # Process params.
50 32 set_params($self, @{$object_params_ar});
51  
52 32 check_required($self, 'horiz_align');
53 31 ▶ if (none { $self->{'horiz_align'} eq $_ } @HORIZ_ALIGN) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $self->{"horiz_align"} eq $_; } , @Tags::HTML::Container::HORIZ_ALIGN)) 1 30 31
54 err "Parameter 'horiz_align' have a bad value.",
55 1 'Value', $self->{'horiz_align'},
56 ;
57 }
58  
59 30 check_required($self, 'vert_align');
60 29 ▶ if (none { $self->{'vert_align'} eq $_ } @VERT_ALIGN) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $self->{"vert_align"} eq $_; } , @Tags::HTML::Container::VERT_ALIGN)) 1 28 29
61 err "Parameter 'vert_align' have a bad value.",
62 1 'Value', $self->{'vert_align'},
63 ;
64 }
65  
66 28 check_css_class($self, 'css_container');
67 26 check_css_class($self, 'css_inner');
68  
69 24 check_css_unit($self, 'height');
70 21 check_css_unit($self, 'padding');
71  
72 # Object.
73 21 return $self;
74 }
75  
76 2 ▶sub _cleanup {
Subroutine _cleanup: called CC=2 SCAR=6.9
77 2 my ($self, $cleanup_cb) = @_;
78  
79 2 ▶ if (defined $cleanup_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cleanup_cb) 1 1 2
80 1 $cleanup_cb->($self);
81 }
82  
83 2 return;
84 }
85  
86 2 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
87 2 my ($self, $init_cb) = @_;
88  
89 2 ▶ if (defined $init_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $init_cb) 1 1 2
90 1 $init_cb->($self);
91 }
92  
93 2 return;
94 }
95  
96 2 ▶sub _prepare {
Subroutine _prepare: called CC=2 SCAR=6.9
97 2 my ($self, $prepare_cb) = @_;
98  
99 2 ▶ if (defined $prepare_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prepare_cb) 1 1 2
100 1 $prepare_cb->($self);
101 }
102  
103 2 return;
104 }
105  
106 2 ▶sub _process {
Subroutine _process: called CC=2 SCAR=6.9
107 2 my ($self, $tags_cb) = @_;
108  
109 2 ▶ if (! defined $tags_cb) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tags_cb) 1 1 2
110 1 err "There is no contained callback with Tags code.";
111 }
112  
113 $self->{'tags'}->put(
114 ['b', 'div'],
115 ['a', 'class', $self->{'css_container'}],
116 ['b', 'div'],
117 1 ['a', 'class', $self->{'css_inner'}],
118 );
119 1 $tags_cb->($self);
120 1 $self->{'tags'}->put(
121 ['e', 'div'],
122 ['e', 'div'],
123 );
124  
125 1 return;
126 }
127  
128 9 ▶sub _process_css {
Subroutine _process_css: called CC=3 SCAR=11.0
129 9 my ($self, $css_cb) = @_;
130  
131 $self->{'css'}->put(
132 ['s', '.'.$self->{'css_container'}],
133 ['d', 'display', 'flex'],
134 ['d', 'align-items', $VERT_CONV{$self->{'vert_align'}}],
135 ['d', 'justify-content', $self->{'horiz_align'}],
136 ['d', 'height', $self->{'height'}],
137 defined $self->{'padding'} ? (
138 9 ▶ ['d', 'padding', $self->{'padding'}],
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'padding'} ? : 1 8 9
139 ) : (),
140 ['e'],
141 );
142 9 ▶ if (defined $css_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $css_cb) 1 8 9
143 1 $css_cb->($self);
144 }
145  
146 9 return;
147 }
148  
149 8 1;
150  
151 __END__
↑ Summary