Quiq/Html/Widget/TextField.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 94.0% 47 / 50 CC 7 SCAR 15.1
CC
7
Cov
93%
html
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.5
« Quiq/Table.pm ↑ Summary Quiq/Html/Table/Simple.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::Widget::TextField - Einzeiliges Textfeld
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Html::Widget>
12  
13 =head1 ATTRIBUTES
14  
15 =over 4
16  
17 =item id => $id (Default: undef)
18  
19 Id des Textfelds.
20  
21 =item class => $class (Default: undef)
22  
23 CSS Klasse des Textfelds.
24  
25 =item style => $style (Default: undef)
26  
27 CSS Definition (inline).
28  
29 =item disabled => $bool (Default: 0)
30  
31 Widget kann nicht editiert werden.
32  
33 =item hidden => $bool (Default: 0)
34  
35 Widget ist (aktuell) unsichtbar.
36  
37 =item maxLength => $n (Default: Wert von "size")
38  
39 Maximale Länge des Eingabewerts in Zeichen. Ein Wert von "0" beutet
40 keine Eingabebegrenzung.
41  
42 =item name => $name (Default: undef)
43  
44 Name des Textfelds.
45  
46 =item onKeyUp => $js (Default: undef)
47  
48 JavaScript-Handler.
49  
50 =item password => $bool (Default: 0)
51  
52 Wenn gesetzt, wird der Eingawert verschleiert.
53  
54 =item readonly => $bool (Default: 0)
55  
56 Zeige das Feld und seinen Wert unveränderbar an.
57  
58 =item size => $n (Default: undef)
59  
60 Breite des Feldes in Zeichen.
61  
62 =item title => $text (Default: undef)
63  
64 Text Tooltip.
65  
66 =item undefIf => $bool (Default: 0)
67  
68 Wenn wahr, liefere C<undef> als Widget-Code.
69  
70 =item value => $str (Default: undef)
71  
72 Anfänglicher Wert des Textfelds.
73  
74 =back
75  
76 =cut
77  
78 # -----------------------------------------------------------------------------
79  
80 package Quiq::Html::Widget::TextField;
81 6 ▶use base qw/Quiq::Html::Widget/;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 6 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 6 our $VERSION = '1.240';
88  
89 # -----------------------------------------------------------------------------
90  
91 =head1 METHODS
92  
93 =head2 Konstruktor
94  
95 =head3 new() - Konstruktor
96  
97 =head4 Synopsis
98  
99 $e = $class->new(@keyVal);
100  
101 =cut
102  
103 # -----------------------------------------------------------------------------
104  
105 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
106 7 my $class = shift;
107 # @_: @keyVal
108  
109 # Defaultwerte
110  
111 7 my $self = $class->SUPER::new(
112 class => undef,
113 disabled => 0,
114 hidden => 0,
115 id => undef,
116 maxLength => undef,
117 name => undef,
118 onKeyUp => undef,
119 password => 0,
120 readonly => 0,
121 size => undef,
122 style => undef,
123 title => undef,
124 undefIf => 0,
125 value => undef,
126 );
127  
128 # Werte Konstruktoraufruf
129 7 $self->set(@_);
130  
131 7 return $self;
132 }
133  
134 # -----------------------------------------------------------------------------
135  
136 =head2 Objektmethoden
137  
138 =head3 html() - Generiere HTML-Code
139  
140 =head4 Synopsis
141  
142 $html = $e->html($h);
143 $html = $class->html($h,@keyVal);
144  
145 =cut
146  
147 # -----------------------------------------------------------------------------
148  
149 9 ▶sub html {
Subroutine html: called CC=7 SCAR=19.6
Pod documented
150 9 my $this = shift;
151 9 my $h = shift;
152 # @_: @keyVal
153  
154 9 ▶ my $self = ref $this? $this: $this->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 5 4 9
155  
156 # Attribute
157  
158 9 my ($class,$disabled,$id,$maxLength,$name,$onKeyUp,$password,
159 $readonly,$size,$style, $title,$undefIf,$value) =
160 $self->get(qw/class disabled id maxLength name onKeyUp password
161 readonly size style title undefIf value/);
162  
163 9 ▶ if (!defined $maxLength) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $maxLength) { } 5 4 9
elsif ($maxLength == 0) { } 1 3 4
164 5 $maxLength = $size;
165 }
166 elsif ($maxLength == 0) {
167 1 $maxLength = undef;
168 }
169  
170 # Whitespace entfernen
171  
172 9 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 8 1 9
173 8 $value =~ s/^\s+//;
174 8 $value =~ s/\s+$//;
175 }
176  
177 # Generierung
178  
179 9 ▶ if ($undefIf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($undefIf) 0 9 9
180 0 return undef;
181 }
182  
183 9 ▶ return $h->tag('input',
Branch: 1 branch
BranchTrueFalseTotal
$password ? : 0 9 9
184 type => $password? 'password': 'text',
185 id => $id,
186 class => $class,
187 style => $style,
188 name => $name,
189 readonly => $readonly,
190 disabled => $disabled,
191 onkeyup => $onKeyUp,
192 size => $size,
193 maxlength => $maxLength,
194 value => $value,
195 title => $title,
196 );
197 }
198  
199 # -----------------------------------------------------------------------------
200  
201 =head1 VERSION
202  
203 1.240
204  
205 =head1 AUTHOR
206  
207 Frank Seitz, L<http://fseitz.de/>
208  
209 =head1 COPYRIGHT
210  
211 Copyright (C) 2026 Frank Seitz
212  
213 =head1 LICENSE
214  
215 This code is free software; you can redistribute it and/or modify
216 it under the same terms as Perl itself.
217  
218 =cut
219  
220 # -----------------------------------------------------------------------------
221  
222 6 1;
223  
224 # eof
« Quiq/Table.pm ↑ Summary Quiq/Html/Table/Simple.pm »