blib/lib/Tags/HTML/Footer.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Tags::HTML::Footer;
2  
3 3 ▶use base qw(Tags::HTML);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶use Class::Utils qw(set_params split_params);
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Error::Pure qw(err);
9 use Mo::utils::Hash 0.02 qw(check_hash check_hash_keys);
10 use Mo::utils::Language 0.05 qw(check_language_639_2);
11 use Readonly;
12 use Scalar::Util qw(blessed);
13 use Unicode::UTF8 qw(decode_utf8);
14  
15 Readonly::Scalar our $DEFAULT_HEIGHT => '40px';
16  
17 our $VERSION = 0.05;
18  
19 # Constructor.
20 sub new {
21 my ($class, @params) = @_;
22  
23 # Create object.
24 my ($object_params_ar, $other_params_ar) = split_params(
25 ['lang', 'text'], @params);
26 my $self = $class->SUPER::new(@{$other_params_ar});
27  
28 # Language.
29 $self->{'lang'} = 'eng';
30  
31 # Language texts.
32 $self->{'text'} = {
33 'eng' => {
34 'version' => 'Version',
35 },
36 };
37  
38 # Process params.
39 set_params($self, @{$object_params_ar});
40  
41 # Check lang.
42 check_language_639_2($self, 'lang');
43  
44 # Check text.
45 check_hash($self, 'text');
46 check_hash_keys($self, 'text', $self->{'lang'}, 'version');
47  
48 # Object.
49 return $self;
50 }
51  
52 sub _cleanup {
53 my $self = shift;
54  
55 delete $self->{'_footer'};
56  
57 return;
58 }
59  
60 sub _init {
61 my ($self, $footer) = @_;
62  
63 # Check a.
64 if (! defined $footer
65 || ! blessed($footer)
66 || ! $footer->isa('Data::HTML::Footer')) {
67  
68 err "Footer object must be a 'Data::HTML::Footer' instance.";
69 }
70  
71 $self->{'_footer'} = $footer;
72  
73 return;
74 }
75  
76 # Process 'Tags'.
77 sub _process {
78 my $self = shift;
79  
80 if (! exists $self->{'_footer'}) {
81 return;
82 }
83  
84 $self->{'tags'}->put(
85 ['b', 'footer'],
86  
87 defined $self->{'_footer'}->version ? (
88 ['b', 'span'],
89 ['a', 'class', 'version'],
90 defined $self->{'_footer'}->version_url ? (
91 ['b', 'a'],
92 ['a', 'href', $self->{'_footer'}->version_url],
93 ) : (),
94 ['d', $self->_text('version').': '.$self->{'_footer'}->version],
95 defined $self->{'_footer'}->version_url ? (
96 ['e', 'a'],
97 ) : (),
98 ['e', 'span'],
99  
100 ($self->{'_footer'}->copyright_years || $self->{'_footer'}->author)
101 ? ['d', ', ']
102 : (),
103 ) : (),
104  
105  
106 defined $self->{'_footer'}->copyright_years ? (
107 ['d', decode_utf8('©').' '.$self->{'_footer'}->copyright_years],
108 defined $self->{'_footer'}->author ? ['d', ' '] : (),
109 ) : (),
110  
111 defined $self->{'_footer'}->author ? (
112 ['b', 'span'],
113 ['a', 'class', 'author'],
114 defined $self->{'_footer'}->author_url ? (
115 ['b', 'a'],
116 ['a', 'href', $self->{'_footer'}->author_url],
117 ) : (),
118 ['d', $self->{'_footer'}->author],
119 defined $self->{'_footer'}->author_url ? (
120 ['e', 'a'],
121 ) : (),
122 ['e', 'span'],
123 ) : (),
124  
125 ['e', 'footer'],
126 );
127  
128 return;
129 }
130  
131 sub _process_css {
132 my $self = shift;
133  
134 if (! exists $self->{'_footer'}) {
135 return;
136 }
137  
138 my $height = $self->{'_footer'}->height;
139 if (! defined $height) {
140 $height = $DEFAULT_HEIGHT;
141 }
142 $self->{'css'}->put(
143 ['s', '#main'],
144 ['d', 'padding-bottom', $height],
145 ['e'],
146  
147 ['s', 'footer'],
148 ['d', 'text-align', 'center'],
149 ['d', 'padding', '10px 0'],
150 ['d', 'background-color', '#f3f3f3'],
151 ['d', 'color', '#333'],
152 ['d', 'position', 'fixed'],
153 ['d', 'bottom', 0],
154 ['d', 'width', '100%'],
155 ['d', 'height', $height],
156 ['d', 'font-family', 'Arial, Helvetica, sans-serif'],
157 ['e'],
158 );
159  
160 return;
161 }
162  
163 sub _text {
164 my ($self, $key) = @_;
165  
166 return $self->{'text'}->{$self->{'lang'}}->{$key};
167 }
168  
169 1;
170  
171 __END__
↑ Summary