Element/Input.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Element/Form.pm ↑ Summary Element/Option.pm »
1 package Data::HTML::Element::Input;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use List::Util 1.33 qw(none);
8 use Mo qw(build is);
9 use Mo::utils 0.26 qw(check_bool check_number);
10 use Mo::utils::CSS 0.02 qw(check_css_class);
11 use Readonly;
12 use Scalar::Util qw(looks_like_number);
13  
14 Readonly::Array our @TYPES => qw(button checkbox color date datetime-local
15 email file hidden image month number password radio range reset search
16 submit tel text time url week);
17 Readonly::Array our @STEP_TYPES => qw(date datetime-local month number range time week);
18  
19 our $VERSION = 0.17;
20  
21 has autofocus => (
22 is => 'ro',
23 );
24  
25 has checked => (
26 is => 'ro',
27 );
28  
29 has css_class => (
30 is => 'ro',
31 );
32  
33 has disabled => (
34 is => 'ro',
35 );
36  
37 has id => (
38 is => 'ro',
39 );
40  
41 has label => (
42 is => 'ro',
43 );
44  
45 has max => (
46 is => 'ro',
47 );
48  
49 has min => (
50 is => 'ro',
51 );
52  
53 has name => (
54 is => 'ro',
55 );
56  
57 has onclick => (
58 is => 'ro',
59 );
60  
61 has placeholder => (
62 is => 'ro',
63 );
64  
65 has readonly => (
66 is => 'ro',
67 );
68  
69 has required => (
70 is => 'ro',
71 );
72  
73 has size => (
74 is => 'ro',
75 );
76  
77 has step => (
78 is => 'ro',
79 );
80  
81 has value => (
82 is => 'ro',
83 );
84  
85 has type => (
86 is => 'ro',
87 );
88  
89 sub BUILD {
90 my $self = shift;
91  
92 # Check autofocus.
93 if (! defined $self->{'autofocus'}) {
94 $self->{'autofocus'} = 0;
95 }
96 check_bool($self, 'autofocus');
97  
98 # Check checked.
99 if (! defined $self->{'checked'}) {
100 $self->{'checked'} = 0;
101 }
102 check_bool($self, 'checked');
103  
104 # Check CSS class.
105 check_css_class($self, 'css_class');
106  
107 # Check disabled.
108 if (! defined $self->{'disabled'}) {
109 $self->{'disabled'} = 0;
110 }
111 check_bool($self, 'disabled');
112  
113 # Check max.
114 check_number($self, 'max');
115  
116 # Check min.
117 check_number($self, 'min');
118  
119 # Check readonly.
120 if (! defined $self->{'readonly'}) {
121 $self->{'readonly'} = 0;
122 }
123 check_bool($self, 'readonly');
124  
125 # Check required.
126 if (! defined $self->{'required'}) {
127 $self->{'required'} = 0;
128 }
129 check_bool($self, 'required');
130  
131 # Check size.
132 check_number($self, 'size');
133  
134 # Check step.
135 if (defined $self->{'step'}) {
136 # Value 'any' is valid in step.
137 if ($self->{'step'} ne 'any') {
138 if (! looks_like_number($self->{'step'})) {
139 err "Parameter 'step' must be a number or 'any' string.",
140 'Value', $self->{'step'},
141 ;
142 }
143 }
144 }
145  
146 # Check type.
147 if (! defined $self->{'type'}) {
148 $self->{'type'} = 'text';
149 }
150 if (none { $self->{'type'} eq $_ } @TYPES) {
151 err "Parameter 'type' has bad value.";
152 }
153  
154 # Check step and type.
155 if (defined $self->{'step'}) {
156 if (none { $self->type eq $_ } @STEP_TYPES) {
157 err "Parameter 'step' is not valid for defined type.",
158 'Type', $self->type,
159 ;
160 }
161 }
162  
163 return;
164 }
165  
166 1;
167  
168 __END__
« Element/Form.pm ↑ Summary Element/Option.pm »