Quiq/Html/Widget/RadioButton.pm

filter: Statementstmt 93.3% 28 / 30 Branchbran 70.0% 7 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 90.5% 48 / 53 CC 7 SCAR 15.5
CC
7
Cov
88%
html
7.3
BEGIN
1.0
BEGIN
1.0
CRAP 4.7
« Quiq/File/Audio.pm ↑ Summary Quiq/UrlObj.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::Widget::RadioButton - Radio Button
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.
20  
21 =item disabled => $bool (Default: 0)
22  
23 Keine Eingabe möglich.
24  
25 =item hidden => $bool (Default: 0)
26  
27 Nicht sichtbar.
28  
29 =item id => $id (Default: undef)
30  
31 CSS-Id.
32  
33 =item label => $html (Default: '')
34  
35 Label rechts neben dem Radio-Button.
36  
37 =item name => $name (Default: undef)
38  
39 Name, unter dem der Button kommuniziert wird.
40  
41 =item onClick => $js (Default: undef)
42  
43 OnClick-Handler.
44  
45 =item option => $value (Default: undef)
46  
47 Wert, der gesendet wird, wenn der Radio-Button ausgewählt ist.
48  
49 =item style => $style (Default: undef)
50  
51 CSS Definition (inline).
52  
53 =item title => $str (Default: undef)
54  
55 Tooltip-Text.
56  
57 =item undefIf => $bool (Default: 0)
58  
59 Wenn wahr, liefere C<undef> als Widget-Code.
60  
61 =item value => $value (Default: undef)
62  
63 Aktueller Wert. Stimmt dieser mit dem Wert des Attributs option
64 überein, wird der Radio-Button aktiviert.
65  
66 =back
67  
68 =cut
69  
70 # -----------------------------------------------------------------------------
71  
72 package Quiq::Html::Widget::RadioButton;
73 2 ▶use base qw/Quiq::Html::Widget/;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 2 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 2 our $VERSION = '1.240';
80  
81 # -----------------------------------------------------------------------------
82  
83 =head1 METHODS
84  
85 =head2 Konstruktor
86  
87 =head3 new() - Konstruktor
88  
89 =head4 Synopsis
90  
91 $e = $class->new(@keyVal);
92  
93 =head4 Description
94  
95 Instantiiere ein RadioButton-Objekt und liefere eine Referenz auf
96 dieses Objekt zurück.
97  
98 =cut
99  
100 # -----------------------------------------------------------------------------
101  
102 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
103 4 my $class = shift;
104 # @_: @keyVal
105  
106 # Defaultwerte
107  
108 4 my $self = $class->SUPER::new(
109 class => undef,
110 disabled => 0,
111 hidden => 0,
112 id => undef,
113 label => '',
114 name => undef,
115 onClick => undef,
116 option => undef,
117 style => undef,
118 title => undef,
119 undefIf => 0,
120 value => undef,
121 );
122 4 $self->set(@_);
123  
124 4 return $self;
125 }
126  
127 # -----------------------------------------------------------------------------
128  
129 =head2 Objektmethoden
130  
131 =head3 html() - Generiere HTML
132  
133 =head4 Synopsis
134  
135 $html = $e->html($h);
136 $html = $class->html($h,@keyVal);
137  
138 =head4 Description
139  
140 Generiere den HTML-Code des RadioButton-Objekts und liefere
141 diesen zurück. Als Klassenmethode gerufen, wird das Objekt intern
142 erzeugt und mit den Attributen @keyVal instantiiert.
143  
144 =cut
145  
146 # -----------------------------------------------------------------------------
147  
148 4 ▶sub html {
Subroutine html: called CC=7 SCAR=19.9
Pod documented
149 4 my $this = shift;
150 4 my $h = shift;
151  
152 4 ▶ my $self = ref $this? $this: $this->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 4 4
153  
154 # Attribute
155  
156 4 my ($class,$disabled,$hidden,$id,$label,$name,$onClick,$option,
157 $style,$title,$undefIf,$value) = $self->get(qw/class disabled hidden
158 id label name onClick option style title undefIf value/);
159  
160 # Generierung
161  
162 4 ▶ if ($undefIf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($undefIf) 0 4 4
163 0 return undef;
164 }
165  
166 4 ▶ if ($hidden) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hidden) 0 4 4
167 0 return '';
168 }
169  
170 4 ▶ my $html .= $h->tag('input',
Branch: 1 branch
BranchTrueFalseTotal
defined $value && $value eq $option ? : 1 3 4
Condition100%3/3
defined $value and $value eq $option
!ll&&!rl&&r
121
MC/DC100%2/2
defined $value and $value eq $option
defined $value $value eq $option
Truth table100%3/3
A and B
A= defined $valueB= $value eq $option
ABresult
0X0
100
111
171 -nl => 0,
172 type => 'radio',
173 id => $id,
174 name => $name,
175 class => $class,
176 style => $style,
177 disabled => $disabled,
178 value => $option,
179 checked => defined($value) && $value eq $option? 1: 0,
180 title => $title,
181 onclick => $onClick,
182 );
183 4 ▶ if ($label ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($label ne "") 2 2 4
184 2 $html .= $label;
185 }
186 4 $html .= "\n";
187  
188 4 return $html;
189 }
190  
191 # -----------------------------------------------------------------------------
192  
193 =head1 VERSION
194  
195 1.240
196  
197 =head1 AUTHOR
198  
199 Frank Seitz, L<http://fseitz.de/>
200  
201 =head1 COPYRIGHT
202  
203 Copyright (C) 2026 Frank Seitz
204  
205 =head1 LICENSE
206  
207 This code is free software; you can redistribute it and/or modify
208 it under the same terms as Perl itself.
209  
210 =cut
211  
212 # -----------------------------------------------------------------------------
213  
214 2 1;
215  
216 # eof
« Quiq/File/Audio.pm ↑ Summary Quiq/UrlObj.pm »