Board/Blank.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
« Board.pm ↑ Summary
1 package Tags::HTML::Message::Board::Blank;
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 0 ▶use Class::Utils 0.06 qw(set_params split_params);
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Data::HTML::Element::Button;
9 use Data::HTML::Element::Textarea;
10 use Error::Pure qw(err);
11 use Mo::utils 0.01 qw(check_required);
12 use Mo::utils::CSS 0.02 qw(check_css_class);
13 use Mo::utils::Language 0.05 qw(check_language_639_2);
14 use Readonly;
15 use Tags::HTML::Element::Button;
16 use Tags::HTML::Element::Textarea;
17  
18 Readonly::Array our @TEXT_KEYS => qw(add_message_board save);
19 Readonly::Scalar our $CSS_CLASS_ADD_COMMENT => 'add-comment';
20  
21 our $VERSION = 0.05;
22  
23 # Constructor.
24 sub new {
25 my ($class, @params) = @_;
26  
27 # Create object.
28 my ($object_params_ar, $other_params_ar) = split_params(
29 ['css_class', 'lang', 'text'], @params);
30 my $self = $class->SUPER::new(@{$other_params_ar});
31  
32 # CSS class.
33 $self->{'css_class'} = 'message-board-blank';
34  
35 # Language.
36 $self->{'lang'} = 'eng';
37  
38 # Language texts.
39 $self->{'text'} = {
40 'eng' => {
41 'add_message_board' => 'Add message board',
42 'save' => 'Save',
43 },
44 };
45  
46 # Process params.
47 set_params($self, @{$object_params_ar});
48  
49 # Check 'css_class'.
50 check_required($self, 'css_class');
51 check_css_class($self, 'css_class');
52  
53 # Check lang.
54 check_language_639_2($self, 'lang');
55  
56 # Check text.
57 if (! defined $self->{'text'}) {
58 err "Parameter 'text' is required.";
59 }
60 if (ref $self->{'text'} ne 'HASH') {
61 err "Parameter 'text' must be a hash with language texts.";
62 }
63 if (! exists $self->{'text'}->{$self->{'lang'}}) {
64 err "Texts for language '$self->{'lang'}' doesn't exist.";
65 }
66 if (@TEXT_KEYS != keys %{$self->{'text'}->{$self->{'lang'}}}) {
67 err "Number of texts isn't same as expected.";
68 }
69 foreach my $req_text_key (@TEXT_KEYS) {
70 if (! exists $self->{'text'}->{$self->{'lang'}}->{$req_text_key}) {
71 err "Text for lang '$self->{'lang'}' and key '$req_text_key' doesn't exist.";
72 }
73 }
74  
75 my %c = (
76 'css' => $self->{'css'},
77 'tags' => $self->{'tags'},
78 );
79 $self->{'_tags_textarea'} = Tags::HTML::Element::Textarea->new(%c);
80 my $data_textarea = Data::HTML::Element::Textarea->new(
81 'autofocus' => 1,
82 'id' => 'message_board_message',
83 'name' => 'message_board_message',
84 'rows' => 6,
85 );
86 $self->{'_tags_textarea'}->init($data_textarea);
87  
88 $self->{'_tags_button'} = Tags::HTML::Element::Button->new(%c);
89 my $data_button = Data::HTML::Element::Button->new(
90 'data' => [
91 $self->_text('save'),
92 ],
93 'name' => 'action',
94 'type' => 'submit',
95 'value' => 'add_message_board',
96 );
97 $self->{'_tags_button'}->init($data_button);
98  
99 # Object.
100 return $self;
101 }
102  
103 sub _process {
104 my $self = shift;
105  
106 $self->{'tags'}->put(
107 ['b', 'div'],
108 ['a', 'class', $self->{'css_class'}],
109 ['b', 'div'],
110 ['a', 'class', 'new-message-board'],
111 ['b', 'div'],
112 ['a', 'class', 'title'],
113 ['d', $self->_text('add_message_board')],
114 ['e', 'div'],
115 ['b', 'form'],
116 ['a', 'method', 'post'],
117 );
118 $self->{'_tags_textarea'}->process;
119 $self->{'_tags_button'}->process;
120 $self->{'tags'}->put(
121 ['e', 'form'],
122 ['e', 'div'],
123 ['e', 'div'],
124 );
125  
126 return;
127 }
128  
129 sub _process_css {
130 my $self = shift;
131  
132 $self->{'_tags_textarea'}->process_css;
133 $self->{'_tags_button'}->process_css;
134 $self->{'css'}->put(
135 ['s', '.'.$self->{'css_class'}],
136 ['d', 'margin', '1em'],
137 ['e'],
138  
139 ['s', '.'.$self->{'css_class'}.' .new-message-board'],
140 ['d', 'font-family', 'Arial, Helvetica, sans-serif'],
141 ['d', 'max-width', '600px'],
142 ['d', 'margin', 'auto'],
143 ['e'],
144  
145 ['s', '.'.$self->{'css_class'}.' .title'],
146 ['d', 'margin-top', '20px'],
147 ['d', 'font-weight', 'bold'],
148 ['d', 'font-size', '1.2em'],
149 ['e'],
150  
151 # Rewrite default Tags::HTML::Element::Button CSS.
152 ['s', 'button'],
153 ['d', 'margin', 0],
154 ['e'],
155 );
156  
157 return;
158 }
159  
160 sub _text {
161 my ($self, $key) = @_;
162  
163 return $self->{'text'}->{$self->{'lang'}}->{$key};
164 }
165  
166 1;
167  
168 __END__
« Board.pm ↑ Summary