| 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.02; | |||||||||
| 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', '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 | # Process params. | ||||||||||
| 41 | 18 | set_params($self, @{$object_params_ar}); | |||||||||
| 42 | |||||||||||
| 43 | 18 | ▶ | if (! defined $self->{'horiz_align'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 1 | err "Parameter 'horiz_align' is required."; | |||||||||
| 45 | } | ||||||||||
| 46 | 17 | ▶ | if (none { $self->{'horiz_align'} eq $_ } @HORIZ_ALIGN) { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 47 | err "Parameter 'horiz_align' have a bad value.", | ||||||||||
| 48 | 1 | 'Value', $self->{'horiz_align'}, | |||||||||
| 49 | ; | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 16 | ▶ | if (! defined $self->{'vert_align'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | err "Parameter 'vert_align' is required."; | |||||||||
| 54 | } | ||||||||||
| 55 | 15 | ▶ | if (none { $self->{'vert_align'} eq $_ } @VERT_ALIGN) { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 56 | err "Parameter 'vert_align' have a bad value.", | ||||||||||
| 57 | 1 | 'Value', $self->{'vert_align'}, | |||||||||
| 58 | ; | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | # Object. | ||||||||||
| 62 | 14 | return $self; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub _process { | ||||||||||
| 66 | 2 | ▶ | my ($self, $tags_cb) = @_; | ||||||||
|
Subroutine
_process: called CC=2 SCAR=6.9
| |||||||||||
| 67 | |||||||||||
| 68 | 2 | ▶ | if (! defined $tags_cb) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 1 | err "There is no contained callback with Tags code."; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | $self->{'tags'}->put( | ||||||||||
| 73 | ['b', 'div'], | ||||||||||
| 74 | ['a', 'class', $self->{'css_container'}], | ||||||||||
| 75 | ['b', 'div'], | ||||||||||
| 76 | 1 | ['a', 'class', $self->{'css_inner'}], | |||||||||
| 77 | ); | ||||||||||
| 78 | 1 | $tags_cb->($self); | |||||||||
| 79 | 1 | $self->{'tags'}->put( | |||||||||
| 80 | ['e', 'div'], | ||||||||||
| 81 | ['e', 'div'], | ||||||||||
| 82 | ); | ||||||||||
| 83 | |||||||||||
| 84 | 1 | return; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | sub _process_css { | ||||||||||
| 88 | 7 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_process_css: called CC=1 SCAR=0.0
| |||||||||||
| 89 | |||||||||||
| 90 | $self->{'css'}->put( | ||||||||||
| 91 | ['s', '.'.$self->{'css_container'}], | ||||||||||
| 92 | ['d', 'display', 'flex'], | ||||||||||
| 93 | ['d', 'align-items', $VERT_CONV{$self->{'vert_align'}}], | ||||||||||
| 94 | 7 | ['d', 'justify-content', $self->{'horiz_align'}], | |||||||||
| 95 | ['d', 'height', '100vh'], | ||||||||||
| 96 | ['e'], | ||||||||||
| 97 | ); | ||||||||||
| 98 | |||||||||||
| 99 | 7 | return; | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 5 | 1; | |||||||||
| 103 | |||||||||||
| 104 | __END__ | ||||||||||