File Coverage

blib/lib/Data/HTML/Element/Textarea.pm
Criterion Covered Total %
statement 32 32 100.0
branch 8 8 100.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 46 47 97.8


line stmt bran cond sub pod time code
1             package Data::HTML::Element::Textarea;
2              
3 16     16   227453 use strict;
  16         52  
  16         733  
4 16     16   108 use warnings;
  16         45  
  16         1045  
5              
6 16     16   10597 use Mo qw(build is);
  16         13761  
  16         116  
7 16     16   40146 use Mo::utils 0.26 qw(check_bool check_number);
  16         285807  
  16         396  
8 16     16   12547 use Mo::utils::CSS 0.02 qw(check_css_class);
  16         190509  
  16         411  
9              
10             our $VERSION = 0.17;
11              
12             has autofocus => (
13             is => 'ro',
14             );
15              
16             has cols => (
17             is => 'ro',
18             );
19              
20             has css_class => (
21             is => 'ro',
22             );
23              
24             has disabled => (
25             is => 'ro',
26             );
27              
28             has form => (
29             is => 'ro',
30             );
31              
32             has id => (
33             is => 'ro',
34             );
35              
36             has label => (
37             is => 'ro',
38             );
39              
40             has name => (
41             is => 'ro',
42             );
43              
44             has placeholder => (
45             is => 'ro',
46             );
47              
48             has readonly => (
49             is => 'ro',
50             );
51              
52             has required => (
53             is => 'ro',
54             );
55              
56             has rows => (
57             is => 'ro',
58             );
59              
60             has value => (
61             is => 'ro',
62             );
63              
64             sub BUILD {
65 31     31 0 4820601 my $self = shift;
66              
67             # Check autofocus.
68 31 100       216 if (! defined $self->{'autofocus'}) {
69 28         87 $self->{'autofocus'} = 0;
70             }
71 31         197 check_bool($self, 'autofocus');
72              
73             # Check css_class.
74 30         859 check_css_class($self, 'css_class');
75              
76             # Check cols.
77 30         467 check_number($self, 'cols');
78              
79             # Check disabled.
80 30 100       374 if (! defined $self->{'disabled'}) {
81 27         79 $self->{'disabled'} = 0;
82             }
83 30         89 check_bool($self, 'disabled');
84              
85             # Check readonly.
86 29 100       422 if (! defined $self->{'readonly'}) {
87 26         70 $self->{'readonly'} = 0;
88             }
89 29         85 check_bool($self, 'readonly');
90              
91             # Check required.
92 28 100       447 if (! defined $self->{'required'}) {
93 26         124 $self->{'required'} = 0;
94             }
95 28         80 check_bool($self, 'required');
96              
97             # Check rows.
98 28         366 check_number($self, 'rows');
99              
100 28         275 return;
101             }
102              
103             1;
104              
105             __END__
106              
107             =pod
108              
109             =encoding utf8
110              
111             =head1 NAME
112              
113             Data::HTML::Element::Textarea - Data object for HTML textarea element.
114              
115             =head1 SYNOPSIS
116              
117             use Data::HTML::Element::Textarea;
118              
119             my $obj = Data::HTML::Element::Textarea->new(%params);
120             my $autofocus = $obj->autofocus;
121             my $cols = $obj->cols;
122             my $css_class = $obj->css_class;
123             my $disabled = $obj->disabled;
124             my $form = $obj->form;
125             my $id = $obj->id;
126             my $label = $obj->label;
127             my $name = $obj->name;
128             my $placeholder = $obj->placeholder;
129             my $readonly = $obj->readonly;
130             my $required = $obj->required;
131             my $rows = $obj->rows;
132             my $value = $obj->value;
133              
134             =head1 METHODS
135              
136             =head2 C<new>
137              
138             my $obj = Data::HTML::Element::Textarea->new(%params);
139              
140             Constructor.
141              
142             =over 8
143              
144             =item * C<autofocus>
145              
146             Textarea autofocus flag.
147              
148             Default value is 0.
149              
150             =item * C<cols>
151              
152             Textarea columns number.
153              
154             Default value is undef.
155              
156             =item * C<css_class>
157              
158             Textarea CSS class.
159              
160             Default value is undef.
161              
162             =item * C<disabled>
163              
164             Textarea disabled flag.
165              
166             Default value is 0.
167              
168             =item * C<form>
169              
170             Textarea form id.
171              
172             Default value is undef.
173              
174             =item * C<id>
175              
176             Form identifier.
177              
178             Default value is undef.
179              
180             =item * C<label>
181              
182             Form label.
183              
184             Default value is undef.
185              
186             =item * C<name>
187              
188             Form name.
189              
190             Default value is undef.
191              
192             =item * C<placeholder>
193              
194             Form placeholder.
195              
196             Default value is undef.
197              
198             =item * C<readonly>
199              
200             Textarea readonly flag.
201              
202             Default value is 0.
203              
204             =item * C<required>
205              
206             Textarea required flag.
207              
208             Default value is 0.
209              
210             =item * C<rows>
211              
212             Textarea rows number.
213              
214             Default value is undef.
215              
216             =item * C<value>
217              
218             Textarea value.
219              
220             Default value is undef.
221              
222             =back
223              
224             Returns instance of object.
225              
226             =head2 C<autofocus>
227              
228             my $autofocus = $obj->autofocus;
229              
230             Get autofocus boolean flag for textarea.
231              
232             Returns 0/1.
233              
234             =head2 C<cols>
235              
236             my $cols = $obj->cols;
237              
238             Get textarea column number.
239              
240             Returns number.
241              
242             =head2 C<css_class>
243              
244             my $css_class = $obj->css_class;
245              
246             Get CSS class for textarea.
247              
248             Returns string.
249              
250             =head2 C<disabled>
251              
252             my $disabled = $obj->disabled;
253              
254             Get disabled boolean flag for textarea.
255              
256             Returns 0/1.
257              
258             =head2 C<form>
259              
260             my $form = $obj->form;
261              
262             Get form id for textarea.
263              
264             Returns string.
265              
266             =head2 C<id>
267              
268             my $id = $obj->id;
269              
270             Get textarea identifier.
271              
272             Returns string.
273              
274             =head2 C<label>
275              
276             my $label = $obj->label;
277              
278             Get textarea label.
279              
280             Returns string.
281              
282             =head2 C<name>
283              
284             my $name = $obj->name;
285              
286             Get textarea name.
287              
288             Returns string.
289              
290             =head2 C<placeholder>
291              
292             my $placeholder = $obj->placeholder;
293              
294             Get textarea placeholder.
295              
296             Returns string.
297              
298             =head2 C<readonly>
299              
300             my $readonly = $obj->readonly;
301              
302             Get readonly boolean flag for textarea.
303              
304             Returns 0/1.
305              
306             =head2 C<required>
307              
308             my $required = $obj->required;
309              
310             Get required boolean flag for textarea.
311              
312             Returns 0/1.
313              
314             =head2 C<rows>
315              
316             my $rows = $obj->rows;
317              
318             Get textarea rows number.
319              
320             Returns number.
321              
322             =head2 C<value>
323              
324             my $value = $obj->value;
325              
326             Get textarea value.
327              
328             Returns string.
329              
330             =head1 ERRORS
331              
332             new():
333             Parameter 'autofocus' must be a bool (0/1).
334             Value: %s
335             Parameter 'cols' must be a number.
336             Value: %s
337             Parameter 'css_class' has bad CSS class name.
338             Value: %s
339             Parameter 'css_class' has bad CSS class name (number on begin).
340             Value: %s
341             Parameter 'disabled' must be a bool (0/1).
342             Value: %s
343             Parameter 'readonly' must be a bool (0/1).
344             Value: %s
345             Parameter 'required' must be a bool (0/1).
346             Value: %s
347             Parameter 'rows' must be a number.
348             Value: %s
349              
350             =head1 EXAMPLE
351              
352             =for comment filename=textarea.pl
353              
354             use strict;
355             use warnings;
356              
357             use Data::HTML::Element::Textarea;
358              
359             my $obj = Data::HTML::Element::Textarea->new(
360             'autofocus' => 1,
361             'css_class' => 'textarea',
362             'id' => 'textarea-id',
363             'label' => 'Textarea label',
364             'value' => 'Textarea value',
365             );
366              
367             # Print out.
368             print 'Autofocus: '.$obj->autofocus."\n";
369             print 'CSS class: '.$obj->css_class."\n";
370             print 'Disabled: '.$obj->disabled."\n";
371             print 'Id: '.$obj->id."\n";
372             print 'Label: '.$obj->label."\n";
373             print 'Readonly: '.$obj->readonly."\n";
374             print 'Required: '.$obj->required."\n";
375             print 'Value: '.$obj->value."\n";
376              
377             # Output:
378             # Autofocus: 1
379             # CSS class: textarea
380             # Disabled: 0
381             # Id: textarea-id
382             # Label: Textarea label
383             # Readonly: 0
384             # Required: 0
385             # Value: Textarea value
386              
387             =head1 DEPENDENCIES
388              
389             L<Mo>,
390             L<Mo::utils>,
391             L<Mo::utils::CSS>.
392              
393             =head1 REPOSITORY
394              
395             L<https://github.com/michal-josef-spacek/Data-HTML-Textarea>
396              
397             =head1 AUTHOR
398              
399             Michal Josef Špaček L<mailto:skim@cpan.org>
400              
401             L<http://skim.cz>
402              
403             =head1 LICENSE AND COPYRIGHT
404              
405             © 2022-2024 Michal Josef Špaček
406              
407             BSD 2-Clause License
408              
409             =head1 VERSION
410              
411             0.17
412              
413             =cut