File Coverage

blib/lib/Tags/HTML/SendMessage.pm
Criterion Covered Total %
statement 44 44 100.0
branch 9 14 64.2
condition 6 6 100.0
subroutine 9 9 100.0
pod 2 2 100.0
total 70 75 93.3


line stmt bran cond sub pod time code
1             package Tags::HTML::SendMessage;
2              
3 4     4   154166 use strict;
  4         11  
  4         150  
4 4     4   17 use warnings;
  4         10  
  4         278  
5              
6 4     4   1586 use Class::Utils qw(set_params);
  4         31440  
  4         137  
7 4     4   259 use Error::Pure qw(err);
  4         12  
  4         213  
8 4     4   22 use Readonly;
  4         8  
  4         3302  
9              
10             # Constants.
11             Readonly::Hash my %LANG => (
12             'title' => 'Leave us a message',
13             'name-and-surname' => 'Name and surname',
14             'email' => 'Email',
15             'subject' => 'Subject of you question',
16             'your-message' => 'Your message',
17             'send' => 'Send question',
18             );
19              
20             our $VERSION = 0.10;
21              
22             # Constructor.
23             sub new {
24 5     5 1 658341 my ($class, @params) = @_;
25              
26             # Create object.
27 5         12 my $self = bless {}, $class;
28              
29             # 'CSS::Struct' object.
30 5         16 $self->{'css'} = undef;
31              
32             # Languages.
33 5         13 $self->{'lang'} = \%LANG;
34              
35             # 'Tags' object.
36 5         10 $self->{'tags'} = undef;
37              
38             # Process params.
39 5         19 set_params($self, @params);
40              
41             # Check to 'Tags' object.
42 5 100 100     103 if (! $self->{'tags'} || ! $self->{'tags'}->isa('Tags::Output')) {
43 2         40 err "Parameter 'tags' must be a 'Tags::Output::*' class.";
44             }
45              
46             # Check to 'CSS::Struct' object.
47 3 100 100     24 if ($self->{'css'} && ! $self->{'css'}->isa('CSS::Struct::Output')) {
48 1         83 err "Parameter 'css' must be a 'CSS::Struct::Output::*' class.";
49             }
50              
51             # Object.
52 2         6 return $self;
53             }
54              
55             # Process 'Tags'.
56             sub process {
57 1     1 1 4 my $self = shift;
58              
59             # Begin of page.
60             $self->{'tags'}->put(
61             ['b', 'div'],
62             ['a', 'id', 'send-message'],
63              
64             ['b', 'form'],
65             ['a', 'action', ''],
66              
67             ['b', 'fieldset'],
68              
69             ['b', 'legend'],
70 1         12 ['d', $self->{'lang'}->{'title'}],
71             ['e', 'legend'],
72             );
73 1         184 $self->_tags_form_input('name-and-surname', 1, { 'size' => 30 });
74 1         3 $self->_tags_form_input('email', 1, { 'size' => 30 });
75 1         4 $self->_tags_form_input('subject', 1, { 'size' => 72 });
76 1         5 $self->_tags_form_textarea('your-message', 1, { 'cols' => 75, 'rows' => 10 });
77             $self->{'tags'}->put(
78              
79             ['b', 'input'],
80             ['a', 'type', 'submit'],
81 1         4 ['a', 'value', $self->{'lang'}->{'send'}],
82             ['e', 'input'],
83              
84             ['e', 'fieldset'],
85             ['e', 'form'],
86             ['e', 'div'],
87             );
88              
89 1         129 return;
90             }
91              
92             sub _tags_form_input {
93 3     3   5 my ($self, $id, $br, $input_opts_hr) = @_;
94              
95             $self->{'tags'}->put(
96             ['b', 'label'],
97             ['a', 'for', $id],
98             ['d', $self->{'lang'}->{$id}.':'],
99             ['e', 'label'],
100              
101             ['b', 'br'],
102             ['e', 'br'],
103              
104             ['b', 'input'],
105             ['a', 'id', $id],
106             ['a', 'name', $id],
107             exists $input_opts_hr->{'size'} ? (
108 3 50       11 ['a', 'size', $input_opts_hr->{'size'}],
109             ) : (),
110             ['e', 'input'],
111             );
112 3 50       622 if ($br) {
113 3         8 $self->{'tags'}->put(
114             ['b', 'br'],
115             ['e', 'br'],
116             );
117             }
118              
119 3         126 return;
120             }
121              
122             sub _tags_form_textarea {
123 1     1   3 my ($self, $id, $br, $textarea_opts_hr) = @_;
124              
125             $self->{'tags'}->put(
126             ['b', 'label'],
127             ['a', 'for', $id],
128             ['d', $self->{'lang'}->{$id}.':'],
129             ['e', 'label'],
130              
131             ['b', 'br'],
132             ['e', 'br'],
133              
134             ['b', 'textarea'],
135             ['a', 'id', $id],
136             ['a', 'name', $id],
137             exists $textarea_opts_hr->{'cols'} ? (
138             ['a', 'cols', $textarea_opts_hr->{'cols'}],
139             ) : (),
140             exists $textarea_opts_hr->{'rows'} ? (
141 1 50       4 ['a', 'rows', $textarea_opts_hr->{'rows'}],
    50          
142             ) : (),
143             ['e', 'textarea'],
144             );
145 1 50       225 if ($br) {
146 1         3 $self->{'tags'}->put(
147             ['b', 'br'],
148             ['e', 'br'],
149             );
150             }
151              
152 1         40 return;
153             }
154              
155             1;
156              
157             __END__