Quiq/Html/Form/Matrix.pm

filter: Statementstmt 96.0% 48 / 50 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 92.6% 63 / 68 CC 7 SCAR 13.0
CC
7
Cov
93%
html
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.7
« Quiq/PlotlyJs/TimeSeries.pm ↑ Summary Quiq/ClassConfig.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::Form::Matrix - HTML-Formular mit Matrix-Layout
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Die Klasse erzeugt ein HTML-Formular mit Matrix-Layout,
16 d.h. es besteht aus mehreren Zeilen gleichartiger Widgets.
17  
18 =head1 ATTRIBUTES
19  
20 =over 4
21  
22 =item border => $bool (Default: 0)
23  
24 Umrande die Felder der zugrundeliegenden Tabelle.
25  
26 =item initialize => $sub (Default: sub {})
27  
28 Subroutine zur Initialisierung der Widgets. Beispiel:
29  
30 sub {
31 my ($w,$name,$i) = @_;
32
33 my $val = $self->param($name."_$i");
34 $w->value($val);
35 }
36  
37 =item name => $name (Default: 'formMatrix')
38  
39 Name der Formular-Matrix.
40  
41 =item names => \@names (Default: [])
42  
43 Liste der Widgetnamen. Zum diesen Widgetnamen wird jeweils "_$i"
44 mit der Nummer $i der Zeile hinzugefügt, beginnend mit 1 für die
45 erste Zeile.
46  
47 =item rows => $n (Default: 1)
48  
49 Anzahl der Zeilen.
50  
51 =item titles => \@titles (Default: [])
52  
53 Liste der Kolumnentitel.
54  
55 =item widgets => \@widgets (Default: [])
56  
57 Widgets einer Matrix-Zeile.
58  
59 =back
60  
61 =cut
62  
63 # -----------------------------------------------------------------------------
64  
65 package Quiq::Html::Form::Matrix;
66 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 1 our $VERSION = '1.240';
73  
74 1 ▶use Quiq::Html::Widget::Hidden;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 ▶use Quiq::Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 1 ▶use Quiq::Html::Table::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 # -----------------------------------------------------------------------------
79  
80 =head1 METHODS
81  
82 =head2 Konstruktor
83  
84 =head3 new() - Instantiiere Objekt
85  
86 =head4 Synopsis
87  
88 $e = $class->new(@keyVal);
89  
90 =head4 Description
91  
92 Instantiiere ein Formular-Objekt mit den Eigenschaften @keyVal und
93 liefere eine Referenz auf dieses Objekt zurück.
94  
95 =cut
96  
97 # -----------------------------------------------------------------------------
98  
99 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
100 2 my $class = shift;
101 # @_: @keyVal
102  
103 my $self = $class->SUPER::new(
104 border => 0,
105 0 ▶ initialize => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
106 2 name => 'formMatrix',
107 names => [],
108 rows => 1,
109 titles => [],
110 widgets => [],
111 );
112 2 $self->set(@_);
113  
114 2 return $self;
115 }
116  
117 # -----------------------------------------------------------------------------
118  
119 =head2 Objektmethoden
120  
121 =head3 html() - Generiere HTML
122  
123 =head4 Synopsis
124  
125 $html = $e->html($h);
126 $html = $class->html($h,@keyVal);
127  
128 =head4 Description
129  
130 Generiere den HTML-Code der Formular-Matrix und liefere diesen
131 zurück. Als Klassenmethode gerufen, wird das Objekt intern erzeugt
132 und mit den Attributen @keyVal instantiiert.
133  
134 =cut
135  
136 # -----------------------------------------------------------------------------
137  
138 2 ▶sub html {
Subroutine html: called CC=7 SCAR=19.6
Pod documented
139 2 my $this = shift;
140 2 my $h = shift;
141  
142 2 ▶ my $self = ref $this? $this: $this->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 2 0 2
143  
144 2 my ($border,$initializeSub,$name,$rows,$titleA,$widgetA) =
145 $self->get(qw/border initialize name rows titles widgets/);
146  
147 2 ▶ if (!@$widgetA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$widgetA) 1 1 2
148 1 return '';
149 }
150  
151 1 my @rows;
152  
153 my @row;
154 1 for my $title (@$titleA) {
155 1 push @row,[$title];
156 }
157 1 push @rows,\@row;
158  
159 1 my $hidden = Quiq::Html::Widget::Hidden->html($h,
160 name => $name.'Size',
161 value => $rows
162 );
163  
164 1 for my $i (1 .. $rows) {
165 3 my @row;
166 3 for (@$widgetA) {
167 3 my $w = Quiq::Storable->clone($_);
168 3 my $name = $w->name;
169 3 $w->name($name."_$i");
170 3 $initializeSub->($w,$name,$i);
171 3 ▶ if ($w->hidden) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w->hidden) 0 3 3
172 0 $hidden .= $w->html($h);
173 0 next;
174 }
175 3 push @row,[$w->html($h)];
176 }
177 3 push @rows,\@row;
178 }
179  
180 1 return $hidden.
181 Quiq::Html::Table::Simple->html($h,
182 border => $border,
183 rows => \@rows,
184 )
185 ;
186 }
187  
188 # -----------------------------------------------------------------------------
189  
190 =head1 VERSION
191  
192 1.240
193  
194 =head1 AUTHOR
195  
196 Frank Seitz, L<http://fseitz.de/>
197  
198 =head1 COPYRIGHT
199  
200 Copyright (C) 2026 Frank Seitz
201  
202 =head1 LICENSE
203  
204 This code is free software; you can redistribute it and/or modify
205 it under the same terms as Perl itself.
206  
207 =cut
208  
209 # -----------------------------------------------------------------------------
210  
211 1 1;
212  
213 # eof
« Quiq/PlotlyJs/TimeSeries.pm ↑ Summary Quiq/ClassConfig.pm »