Quiq/Html/Widget/RadioButtonBar.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 71.4% 10 / 14 Conditioncond 38.8% 7 / 18 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 70.0% 63 / 90 CC 14 SCAR 27.8
CC
14
Cov
75%
html
22.6
BEGIN
1.0
BEGIN
1.0
CRAP 16.1
« Quiq/Ssh.pm ↑ Summary Quiq/Time/RFC822.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::Widget::RadioButtonBar - Zeile von Radio Buttons
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Html::Widget>
12  
13 =head1 ATTRIBUTES
14  
15 =over 4
16  
17 =item class => $class (Default: undef)
18  
19 CSS Klasse des Konstruktes.
20  
21 =item default => $default (Default: keiner)
22  
23 Wert, der angenommen wird, wenn value ein Leerstring oder C<undef> ist.
24  
25 =item disabled => $bool (Default: 0)
26  
27 Das gesamte Konstrukt ist disabled. Keine Auswahl möglich.
28  
29 =item hidden => $bool (Default: 0)
30  
31 Das gesamte Konstrukt ist nicht sichtbar.
32  
33 =item id => $id (Default: undef)
34  
35 CSS-Id des Konstruktes.
36  
37 =item labels => \@labels (Default: [])
38  
39 Liste der Label rechts neben den Radio-Buttons.
40  
41 =item name => $name (Default: undef)
42  
43 Name, unter dem der ausgewählte Button kommuniziert wird.
44  
45 =item onClick => \@onClick (Default: [])
46  
47 Liste der OnClick-Handler.
48  
49 =item options => \@options (Default: [])
50  
51 Liste der Radio-Button-Werte. Der Wert des ausgewählten Radio Button
52 wird gesendet.
53  
54 =item orientation => 'h'|'v' (Default: 'h')
55  
56 Horizentale oder vertikale Ausrichtung der Radio-Buttons.
57  
58 =item buttonClass => $class (Default: undef)
59  
60 CSS Klasse der Radio Buttons.
61  
62 =item style => $style (Default: undef)
63  
64 CSS Definition des Konstruktes (inline).
65  
66 =item titles => \@titles (Default: [])
67  
68 Tooltip-Texte der Radio Buttons.
69  
70 =item undefIf => $bool (Default: 0)
71  
72 Wenn wahr, liefere C<undef> als Widget-Code.
73  
74 =item value => $value (Default: undef)
75  
76 Aktueller Wert. Stimmt dieser mit dem Wert (s. Attribut option)
77 eines der Radio Buttons überein, wird dieser Radio-Button
78 aktiviert.
79  
80 =back
81  
82 =cut
83  
84 # -----------------------------------------------------------------------------
85  
86 package Quiq::Html::Widget::RadioButtonBar;
87 1 ▶use base qw/Quiq::Html::Widget/;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 1 our $VERSION = '1.240';
94  
95 1 ▶use Quiq::Html::Widget::RadioButton;
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 # -----------------------------------------------------------------------------
98  
99 =head1 METHODS
100  
101 =head2 Konstruktor
102  
103 =head3 new() - Konstruktor
104  
105 =head4 Synopsis
106  
107 $e = $class->new(@keyVal);
108  
109 =head4 Description
110  
111 Instantiiere ein RadioButtonBar-Objekt und liefere eine Referenz
112 auf dieses Objekt zurück.
113  
114 =cut
115  
116 # -----------------------------------------------------------------------------
117  
118 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
119 2 my $class = shift;
120 # @_: @keyVal
121  
122 # Defaultwerte
123  
124 2 my $self = $class->SUPER::new(
125 class => undef,
126 default => undef,
127 disabled => 0,
128 hidden => 0,
129 id => undef,
130 labels => [],
131 name => undef,
132 onClick => [],
133 options => [],
134 orientation => 'h',
135 buttonClass => undef,
136 style => undef,
137 titles => [],
138 undefIf => 0,
139 value => undef,
140 );
141 2 $self->set(@_);
142  
143 2 return $self;
144 }
145  
146 # -----------------------------------------------------------------------------
147  
148 =head2 Objektmethoden
149  
150 =head3 html() - Generiere HTML
151  
152 =head4 Synopsis
153  
154 $html = $e->html($h);
155 $html = $class->html($h,@keyVal);
156  
157 =head4 Description
158  
159 Generiere den HTML-Code des RadioButtonBar-Objekts und liefere
160 diesen zurück. Als Klassenmethode gerufen, wird das Objekt intern
161 erzeugt und mit den Attributen @keyVal instantiiert.
162  
163 =cut
164  
165 # -----------------------------------------------------------------------------
166  
167 2 ▶sub html {
Subroutine html: called CC=14 SCAR=31.2
Pod documented
168 2 my $this = shift;
169 2 my $h = shift;
170  
171 2 ▶ my $self = ref $this? $this: $this->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 2 2
172  
173 # Attribute
174  
175 2 my ($class,$default,$disabled,$hidden,$id,$labelA,$name,$onClickA,
176 $optionA,$orientation,$buttonClass,$style,$titleA,$undefIf,$value) =
177 $self->get(qw/class default disabled hidden id labels name onClick
178 options orientation buttonClass style titles undefIf value/);
179  
180 # Generierung
181  
182 2 ▶ if ($undefIf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($undefIf) 0 2 2
183 0 return undef;
184 }
185  
186 2 ▶ if ($hidden || !@$optionA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hidden or not @$optionA) 1 1 2
Condition66%2/3
$hidden or not @$optionA
l!l&&r!l&&!r
011
MC/DC50%1/2
$hidden or not @$optionA
$hidden not @$optionA
Truth table66%2/3
A or not(B)
A= $hiddenB= not @$optionA
ABresult
1X1
011
000
187 1 return '';
188 }
189  
190 0 ▶ if (!defined($value) || $value eq '' && !grep {$_ eq ''} @$optionA) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value eq "" and not grep({$_ eq "";} @$optionA)) 0 1 1
Condition33%2/6
not defined $value or $value eq "" and not grep({$_ eq "";} @$optionA)
l!l&&r!l&&!r
001
$value eq "" and not grep({$_ eq "";} @$optionA)
!ll&&!rl&&r
100
MC/DC0%0/3
not defined $value or $value eq "" and not grep({$_ eq "";} @$optionA)
not defined $value $value eq "" not grep({$_ eq "";} @$optionA)
Truth table25%1/4
not(A) or B and not(C)
A= not defined $valueB= $value eq ""C= not grep({$_ eq "";} @$optionA)
ABCresult
1XX1
0111
00X0
0100
191 0 $value = $default;
192 }
193  
194 return $h->tag('span',
195 -fmt => 'v', # generierten Code einzeilig belassen
196 -ignoreTagIf => !$id && !$class && !$style,
197 id => $id,
198 class => $class,
199 style => $style,
200 1 ▶ do {
Condition33%2/6
$id || $class || $style
l!l&&r!l&&!r
001
$id or $class
l!l&&r!l&&!r
001
MC/DC0%0/3
$id || $class || $style
$id $class $style
Truth table25%1/4
A or B || C
A= $idB= $classC= $style
ABCresult
1XX1
01X1
0011
0000
201 1 my $html;
202 1 ▶ for (my $i = 0; $i < @$optionA; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$optionA) 2 1 3
203 2 ▶ if ($html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html) 1 1 2
204 1 ▶ $html .= $orientation eq 'v'? $h->tag('br',-nl=>0): ' ';
Branch: 1 branch
BranchTrueFalseTotal
$orientation eq 'v' ? : 0 1 1
205 }
206 2 ▶ $html .= Quiq::Html::Widget::RadioButton->html($h,
Condition33%1/3
$labelA->[$i] // $optionA->[$i]
l!l&&r!l&&!r
200
MC/DC0%0/2
$labelA->[$i] // $optionA->[$i]
$labelA->[$i] $optionA->[$i]
Truth table33%1/3
A // B
A= $labelA->[$i]B= $optionA->[$i]
ABresult
1X1
011
000
207 class => $buttonClass,
208 disabled => $disabled,
209 label => $labelA->[$i] // $optionA->[$i],
210 name => $name,
211 onClick => $onClickA->[$i],
212 option => $optionA->[$i],
213 title => $titleA->[$i],
214 value => $value,
215 );
216 2 chomp $html;
217 }
218 1 $html;
219 }
220 );
221 }
222  
223 # -----------------------------------------------------------------------------
224  
225 =head1 VERSION
226  
227 1.240
228  
229 =head1 AUTHOR
230  
231 Frank Seitz, L<http://fseitz.de/>
232  
233 =head1 COPYRIGHT
234  
235 Copyright (C) 2026 Frank Seitz
236  
237 =head1 LICENSE
238  
239 This code is free software; you can redistribute it and/or modify
240 it under the same terms as Perl itself.
241  
242 =cut
243  
244 # -----------------------------------------------------------------------------
245  
246 1 1;
247  
248 # eof
« Quiq/Ssh.pm ↑ Summary Quiq/Time/RFC822.pm »