File Coverage

blib/lib/Tags/HTML/DefinitionList.pm
Criterion Covered Total %
statement 35 61 57.3
branch 0 8 0.0
condition n/a
subroutine 7 13 53.8
pod 1 1 100.0
total 43 83 51.8


line stmt bran cond sub pod time code
1             package Tags::HTML::DefinitionList;
2              
3 3     3   161036 use base qw(Tags::HTML);
  3         5  
  3         1528  
4 3     3   36326 use strict;
  3         7  
  3         69  
5 3     3   12 use warnings;
  3         6  
  3         2084  
6              
7 3     3   18 use Class::Utils qw(set_params split_params);
  3         5  
  3         154  
8 3     3   17 use Error::Pure qw(err);
  3         5  
  3         200  
9 3     3   1750 use Mo::utils::CSS 0.07 qw(check_css_border check_css_class check_css_unit);
  3         31726  
  3         64  
10              
11             our $VERSION = 0.02;
12              
13             # Constructor.
14             sub new {
15 14     14 1 377244 my ($class, @params) = @_;
16              
17             # Create object.
18 14         85 my ($object_params_ar, $other_params_ar) = split_params(
19             ['border', 'color', 'css_class', 'dd_left_padding', 'dt_sep',
20             'dt_width'], @params);
21 14         502 my $self = $class->SUPER::new(@{$other_params_ar});
  14         65  
22              
23             # Border of dl.
24 10         337 $self->{'border'} = undef;
25              
26             # Definition key color.
27 10         23 $self->{'color'} = 'black';
28              
29             # CSS class.
30 10         24 $self->{'css_class'} = 'dl';
31              
32             # Left padding after term.
33 10         25 $self->{'dd_left_padding'} = '110px';
34              
35             # Definition term separator.
36 10         21 $self->{'dt_sep'} = ':';
37              
38             # Definition term width.
39 10         17 $self->{'dt_width'} = '100px';
40              
41             # Process params.
42 10         17 set_params($self, @{$object_params_ar});
  10         34  
43              
44 10         145 check_css_border($self, 'border');
45              
46 10         173 check_css_class($self, 'css_class');
47              
48 8         167 check_css_unit($self, 'dd_left_padding');
49 5         450 check_css_unit($self, 'dt_width');
50              
51             # Object.
52 2         174 return $self;
53             }
54              
55             sub _cleanup {
56 0     0     my $self = shift;
57              
58 0           delete $self->{'_definition_list'};
59              
60 0           return;
61             }
62              
63             sub _init {
64 0     0     my ($self, $definition_list_ar) = @_;
65              
66 0           return $self->_set_dl($definition_list_ar);
67             }
68              
69             sub _prepare {
70 0     0     my ($self, $definition_list_ar) = @_;
71              
72 0           return $self->_set_dl($definition_list_ar);
73             }
74              
75             # Process 'Tags'.
76             sub _process {
77 0     0     my $self = shift;
78              
79 0 0         if (! exists $self->{'_definition_list'}) {
80 0           return;
81             }
82              
83             $self->{'tags'}->put(
84             ['b', 'dl'],
85 0           ['a', 'class', $self->{'css_class'}],
86             );
87 0           foreach my $item_ar (@{$self->{'_definition_list'}}) {
  0            
88 0           $self->{'tags'}->put(
89             ['b', 'dt'],
90             ['d', $item_ar->[0]],
91             ['e', 'dt'],
92             ['b', 'dd'],
93             ['d', $item_ar->[1]],
94             ['e', 'dd'],
95             );
96             }
97 0           $self->{'tags'}->put(
98             ['e', 'dl'],
99             );
100              
101 0           return;
102             }
103              
104             sub _process_css {
105 0     0     my $self = shift;
106              
107             $self->{'css'}->put(
108             ['s', '.'.$self->{'css_class'}],
109             defined $self->{'border'} ? (
110             ['d', 'border', $self->{'border'}],
111             ) : (),
112             ['d', 'padding', '0.5em'],
113             ['e'],
114              
115             ['s', '.'.$self->{'css_class'}.' dt'],
116             ['d', 'float', 'left'],
117             ['d', 'clear', 'left'],
118             ['d', 'width', $self->{'dt_width'}],
119             ['d', 'text-align', 'right'],
120             ['d', 'font-weight', 'bold'],
121             ['d', 'color', $self->{'color'}],
122             ['e'],
123              
124             ['s', '.'.$self->{'css_class'}.' dt:after'],
125             ['d', 'content', '"'.$self->{'dt_sep'}.'"'],
126             ['e'],
127              
128             ['s', '.'.$self->{'css_class'}.' dd'],
129 0 0         ['d', 'margin', '0 0 0 '.$self->{'dd_left_padding'}],
130             ['d', 'padding', '0 0 0.5em 0'],
131             ['e'],
132             );
133              
134 0           return;
135             }
136              
137             sub _set_dl {
138 0     0     my ($self, $definition_list_ar) = @_;
139              
140 0 0         if (! defined $definition_list_ar) {
141 0           return;
142             }
143 0 0         if (ref $definition_list_ar ne 'ARRAY') {
144 0           err 'Definition list must be a reference to array.';
145             }
146              
147 0           $self->{'_definition_list'} = $definition_list_ar;
148              
149 0           return;
150             }
151              
152             1;
153              
154             __END__