| 1 | package Tags::HTML::Container; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use base qw(Tags::HTML); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 5 | ▶ | use Class::Utils qw(set_params split_params); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Error::Pure qw(err); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use List::Util qw(none); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 5 | Readonly::Array our @HORIZ_ALIGN => qw(center left right); | |||||||||
| 13 | 5 | Readonly::Array our @VERT_ALIGN => qw(base bottom center fit top); | |||||||||
| 14 | 5 | Readonly::Hash our %VERT_CONV => ( | |||||||||
| 15 | 'base' => 'baseline', | ||||||||||
| 16 | 'bottom' => 'flex-end', | ||||||||||
| 17 | 'center' => 'center', | ||||||||||
| 18 | 'fit' => 'stretch', | ||||||||||
| 19 | 'top' => 'flex-start', | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 5 | our $VERSION = 0.03; | |||||||||
| 23 | |||||||||||
| 24 | sub new { | ||||||||||
| 25 | 20 | ▶ | my ($class, @params) = @_; | ||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 26 | |||||||||||
| 27 | # Create object. | ||||||||||
| 28 | 20 | my ($object_params_ar, $other_params_ar) = split_params( | |||||||||
| 29 | ['css_container', 'css_inner', 'height', 'horiz_align', 'vert_align'], @params); | ||||||||||
| 30 | 20 | my $self = $class->SUPER::new(@{$other_params_ar}); | |||||||||
| 31 | |||||||||||
| 32 | # Container align. | ||||||||||
| 33 | 18 | $self->{'horiz_align'} = 'center'; | |||||||||
| 34 | 18 | $self->{'vert_align'} = 'center'; | |||||||||
| 35 | |||||||||||
| 36 | # CSS classes. | ||||||||||
| 37 | 18 | $self->{'css_container'} = 'container'; | |||||||||
| 38 | 18 | $self->{'css_inner'} = 'inner'; | |||||||||
| 39 | |||||||||||
| 40 | # Height. | ||||||||||
| 41 | 18 | $self->{'height'} = '100vh'; | |||||||||
| 42 | |||||||||||
| 43 | # Process params. | ||||||||||
| 44 | 18 | set_params($self, @{$object_params_ar}); | |||||||||
| 45 | |||||||||||
| 46 | 18 | ▶ | if (! defined $self->{'horiz_align'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | err "Parameter 'horiz_align' is required."; | |||||||||
| 48 | } | ||||||||||
| 49 | 17 | ▶ | if (none { $self->{'horiz_align'} eq $_ } @HORIZ_ALIGN) { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 50 | err "Parameter 'horiz_align' have a bad value.", | ||||||||||
| 51 | 1 | 'Value', $self->{'horiz_align'}, | |||||||||
| 52 | ; | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 16 | ▶ | if (! defined $self->{'vert_align'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | err "Parameter 'vert_align' is required."; | |||||||||
| 57 | } | ||||||||||
| 58 | 15 | ▶ | if (none { $self->{'vert_align'} eq $_ } @VERT_ALIGN) { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 59 | err "Parameter 'vert_align' have a bad value.", | ||||||||||
| 60 | 1 | 'Value', $self->{'vert_align'}, | |||||||||
| 61 | ; | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | # Object. | ||||||||||
| 65 | 14 | return $self; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub _process { | ||||||||||
| 69 | 2 | ▶ | my ($self, $tags_cb) = @_; | ||||||||
|
Subroutine
_process: called CC=2 SCAR=6.9
| |||||||||||
| 70 | |||||||||||
| 71 | 2 | ▶ | if (! defined $tags_cb) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 1 | err "There is no contained callback with Tags code."; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | $self->{'tags'}->put( | ||||||||||
| 76 | ['b', 'div'], | ||||||||||
| 77 | ['a', 'class', $self->{'css_container'}], | ||||||||||
| 78 | ['b', 'div'], | ||||||||||
| 79 | 1 | ['a', 'class', $self->{'css_inner'}], | |||||||||
| 80 | ); | ||||||||||
| 81 | 1 | $tags_cb->($self); | |||||||||
| 82 | 1 | $self->{'tags'}->put( | |||||||||
| 83 | ['e', 'div'], | ||||||||||
| 84 | ['e', 'div'], | ||||||||||
| 85 | ); | ||||||||||
| 86 | |||||||||||
| 87 | 1 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | sub _process_css { | ||||||||||
| 91 | 7 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_process_css: called CC=1 SCAR=0.0
| |||||||||||
| 92 | |||||||||||
| 93 | $self->{'css'}->put( | ||||||||||
| 94 | ['s', '.'.$self->{'css_container'}], | ||||||||||
| 95 | ['d', 'display', 'flex'], | ||||||||||
| 96 | ['d', 'align-items', $VERT_CONV{$self->{'vert_align'}}], | ||||||||||
| 97 | ['d', 'justify-content', $self->{'horiz_align'}], | ||||||||||
| 98 | 7 | ['d', 'height', $self->{'height'}], | |||||||||
| 99 | ['e'], | ||||||||||
| 100 | ); | ||||||||||
| 101 | |||||||||||
| 102 | 7 | return; | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 5 | 1; | |||||||||
| 106 | |||||||||||
| 107 | __END__ | ||||||||||