Element/Input.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
« Element/Form.pm ↑ Summary Element/Option.pm »
1 package Tags::HTML::Element::Input;
2  
3 2 ▶use base qw(Tags::HTML);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Scalar::Util qw(blessed);
9 use Tags::HTML::Element::Utils qw(tags_boolean tags_label tags_value);
10  
11 our $VERSION = 0.15;
12  
13 sub _cleanup {
14 my $self = shift;
15  
16 delete $self->{'_input'};
17  
18 return;
19 }
20  
21 sub _init {
22 my ($self, $input) = @_;
23  
24 # Check input.
25 if (! defined $input
26 || ! blessed($input)
27 || ! $input->isa('Data::HTML::Element::Input')) {
28  
29 err "Input object must be a 'Data::HTML::Element::Input' instance.";
30 }
31  
32 $self->{'_input'} = $input;
33  
34 return;
35 }
36  
37 # Process 'Tags'.
38 sub _process {
39 my $self = shift;
40  
41 if (! $self->{'_input'}) {
42 return;
43 }
44  
45 $self->{'tags'}->put(
46 tags_label($self, $self->{'_input'}),
47 ['b', 'input'],
48 tags_boolean($self, $self->{'_input'}, 'autofocus'),
49 tags_value($self, $self->{'_input'}, 'css_class', 'class'),
50 tags_value($self, $self->{'_input'}, 'type'),
51 tags_value($self, $self->{'_input'}, 'id'),
52 tags_value($self, $self->{'_input'}, 'name'),
53 tags_value($self, $self->{'_input'}, 'value'),
54 tags_boolean($self, $self->{'_input'}, 'checked'),
55 tags_value($self, $self->{'_input'}, 'placeholder'),
56 tags_value($self, $self->{'_input'}, 'size'),
57 tags_boolean($self, $self->{'_input'}, 'readonly'),
58 tags_boolean($self, $self->{'_input'}, 'disabled'),
59 tags_value($self, $self->{'_input'}, 'min'),
60 tags_value($self, $self->{'_input'}, 'max'),
61 tags_value($self, $self->{'_input'}, 'step'),
62 tags_value($self, $self->{'_input'}, 'onclick'),
63 ['e', 'input'],
64 );
65  
66 return;
67 }
68  
69 sub _process_css {
70 my $self = shift;
71  
72 if (! $self->{'_input'}) {
73 return;
74 }
75  
76 my $css_class = '';
77 my $css_required = '.';
78 if (defined $self->{'_input'}->css_class) {
79 $css_class = '.'.$self->{'_input'}->css_class;
80 $css_required .= $self->{'_input'}->css_class.'-';
81 }
82 $css_required .= 'required';
83  
84 $self->{'css'}->put(
85 ['s', 'input'.$css_class.'[type=submit]:hover'],
86 ['d', 'background-color', '#45a049'],
87 ['e'],
88  
89 ['s', 'input'.$css_class.'[type=submit]'],
90 ['d', 'width', '100%'],
91 ['d', 'background-color', '#4CAF50'],
92 ['d', 'color', 'white'],
93 ['d', 'padding', '14px 20px'],
94 ['d', 'margin', '8px 0'],
95 ['d', 'border', 'none'],
96 ['d', 'border-radius', '4px'],
97 ['d', 'cursor', 'pointer'],
98 ['e'],
99  
100 ['s', 'input'.$css_class.'[type=submit][disabled=disabled]'],
101 ['d', 'background-color', '#888888'],
102 ['e'],
103  
104 ['s', 'input'.$css_class.'[type=text]'],
105 ['s', 'input'.$css_class.'[type=date]'],
106 ['s', 'input'.$css_class.'[type=number]'],
107 ['s', 'input'.$css_class.'[type=email]'],
108 ['s', 'input'.$css_class.'[type=checkbox]'],
109 ['d', 'width', '100%'],
110 ['d', 'padding', '12px 20px'],
111 ['d', 'margin', '8px 0'],
112 ['d', 'display', 'inline-block'],
113 ['d', 'border', '1px solid #ccc'],
114 ['d', 'border-radius', '4px'],
115 ['d', 'box-sizing', 'border-box'],
116 ['e'],
117  
118 ['s', 'input'.$css_class.'[type=button]'],
119 ['d', 'width', '100%'],
120 ['d', 'background-color', '#4CAF50'],
121 ['d', 'color', 'white'],
122 ['d', 'padding', '14px 20px'],
123 ['d', 'margin', '8px 0'],
124 ['d', 'border', 'none'],
125 ['d', 'border-radius', '4px'],
126 ['d', 'cursor', 'pointer'],
127 ['e'],
128  
129 ['s', 'input'.$css_class.'[type=button]:hover'],
130 ['d', 'background-color', '#45a049'],
131 ['e'],
132  
133 ['s', $css_required],
134 ['d', 'color', 'red'],
135 ['e'],
136 );
137  
138 return;
139 }
140  
141 1;
142  
143 __END__
« Element/Form.pm ↑ Summary Element/Option.pm »