Quiq/Html/Component/Bundle.pm

filter: Statementstmt 88.6% 39 / 44 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.8% 13 / 14 Podpod 100% 10 / 10 totaltotal 89.1% 66 / 74 CC 8 SCAR 7.2
CC
8
Cov
86%
resources
3.1
getValue
3.1
component
3.0
CRAP 2.0
« Quiq/Database/Row/Array.pm ↑ Summary Quiq.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::Component::Bundle - Bündel von HTML-Komponenten
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::List>
12  
13 =head1 SYNOPSIS
14  
15 use Quiq::Html::Component::Bundle;
16
17 # Instantiiere Objekt
18 $b = Quiq::Html::Component::Bundle->new(\@components);
19
20 # Liste aller Komponenten
21 @components | $componentA = $b->components;
22
23 # Lookup einer Komponente
24 $c = $b->component($name);
25
26 # Zusammenfassung der Bestandteile der Komponenten
27
28 @resources | $resourceA = $b->resources;
29 @css | $css = $b->css;
30 @html | $html = $b->html;
31 @js | $js = $b->js;
32 @ready | $ready = $b->ready;
33
34 # Platzhalter-Liste für HTML
35 @keyVal = $b->htmlPlaceholders;
36  
37 =head1 DESCRIPTION
38  
39 Ein Objekt der Klasse speichert mehrere HTML-Komponenten
40 vom Typ Quiq::Html::Component und stellt Methoden zur Verfügung,
41 deren Bestandteile abzufragen.
42  
43 =head1 SEE ALSO
44  
45 =over 2
46  
47 =item *
48  
49 Quiq::Html::Component
50  
51 =back
52  
53 =cut
54  
55 # -----------------------------------------------------------------------------
56  
57 package Quiq::Html::Component::Bundle;
58 7 ▶use base qw/Quiq::List/;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 7 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 7 our $VERSION = '1.240';
65  
66 # -----------------------------------------------------------------------------
67  
68 =head1 METHODS
69  
70 =head2 Konstruktor
71  
72 =head3 new() - Instantiiere Objekt
73  
74 =head4 Synopsis
75  
76 $b = $class->new;
77 $b = $class->new(\@components);
78  
79 =head4 Arguments
80  
81 =over 4
82  
83 =item @components
84  
85 Liste der HTML-Komponenten
86  
87 =back
88  
89 =head4 Returns
90  
91 Objekt
92  
93 =head4 Description
94  
95 Instantiiere ein Objekt der Klasse und liefere eine Referenz auf
96 dieses Objekt zurück.
97  
98 =cut
99  
100 # -----------------------------------------------------------------------------
101  
102 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
103 5 my ($class,$componentA) = @_;
104 5 return $class->SUPER::new($componentA);
105 }
106  
107 # -----------------------------------------------------------------------------
108  
109 =head3 component() - Liefere HTML-Komponente
110  
111 =head4 Synopsis
112  
113 $c = $b->component($name);
114  
115 =head4 Arguments
116  
117 =over 4
118  
119 =item $name
120  
121 Name der HTML-Komponente
122  
123 =back
124  
125 =head4 Returns
126  
127 HTML-Komponente (Object)
128  
129 =head4 Description
130  
131 Liefere die HTML-Komponente mit dem Namen $name.
132  
133 =cut
134  
135 # -----------------------------------------------------------------------------
136  
137 1 ▶sub component {
Subroutine component: called CC=3 SCAR=11.0
Pod documented
138 1 my ($self,$name) = @_;
139  
140 1 for my $c (@{$self->elements}) {
141 2 ▶ if ($c->name eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->name eq $name) 1 1 2
142 1 return $c;
143 }
144 }
145  
146 $self->throw(
147 0 'BUNDLE-00001: Component not found',
148 Name => $name,
149 );
150 }
151  
152 # -----------------------------------------------------------------------------
153  
154 =head3 components() - Liste der HTML-Komponenten
155  
156 =head4 Synopsis
157  
158 @components | $componentA = $b->components;
159  
160 =head4 Returns
161  
162 Liste von HTML-Komponenten. Im Skalarkontext eine Referenz auf die Liste.
163  
164 =head4 Description
165  
166 Liefere die Liste der HTML-Komponenten.
167  
168 =cut
169  
170 # -----------------------------------------------------------------------------
171  
172 14 ▶sub components {
Subroutine components: called CC=1 SCAR=0.0
Pod documented
173 14 return shift->elements;
174 }
175  
176 # -----------------------------------------------------------------------------
177  
178 =head3 css() - CSS-Code der Komponenten
179  
180 =head4 Synopsis
181  
182 $css | @css = $c->css;
183  
184 =head4 Description
185  
186 Liefere den CSS-Code der Komponenten. Im Arraykontext die Liste der
187 Array-Elemente, im Skalarkontext deren Konkatenation.
188  
189 =cut
190  
191 # -----------------------------------------------------------------------------
192  
193 4 ▶sub css {
Subroutine css: called CC=1 SCAR=0.0
Pod documented
194 4 return shift->getValue('css');
195 }
196  
197 # -----------------------------------------------------------------------------
198  
199 =head3 html() - HTML-Code der Komponenten
200  
201 =head4 Synopsis
202  
203 $html | @html = $c->html;
204  
205 =head4 Description
206  
207 Liefere den HTML-Code der Komponenten. Im Arraykontext die Liste der
208 Array-Elemente, im Skalarkontext deren Konkatenation.
209  
210 =cut
211  
212 # -----------------------------------------------------------------------------
213  
214 0 ▶sub html {
Subroutine html: not called CC=1 SCAR=6.9
Pod documented
215 0 return shift->getValue('html');
216 }
217  
218 # -----------------------------------------------------------------------------
219  
220 =head3 htmlPlaceholders() - Platzhalterliste für HTML
221  
222 =head4 Synopsis
223  
224 @keyVal = $c->htmlPlaceholders;
225  
226 =head4 Returns
227  
228 Liste von Schlüssel/Wert-Paaren
229  
230 =head4 Description
231  
232 Liefere die Liste von Schlüssel/Wert-Paaren für eine
233 HTML-Platzhalterersetzung.
234  
235 =cut
236  
237 # -----------------------------------------------------------------------------
238  
239 4 ▶sub htmlPlaceholders {
Subroutine htmlPlaceholders: called CC=2 SCAR=7.0
Pod documented
240 4 my $self = shift;
241  
242 4 my @arr;
243 4 for my $c (@{$self->elements}) {
244 0 push @arr,'__'.uc($c->name).'__'=>scalar $c->html;
245 }
246  
247 4 return @arr;
248 }
249  
250 # -----------------------------------------------------------------------------
251  
252 =head3 js() - JavaScript-Code der Komponenten
253  
254 =head4 Synopsis
255  
256 $js | @js = $c->js;
257  
258 =head4 Description
259  
260 Liefere den JavaScript-Code der Komponenten. Im Arraykontext die Liste der
261 Array-Elemente, im Skalarkontext deren Konkatenation.
262  
263 =cut
264  
265 # -----------------------------------------------------------------------------
266  
267 4 ▶sub js {
Subroutine js: called CC=1 SCAR=0.0
Pod documented
268 4 return shift->getValue('js');
269 }
270  
271 # -----------------------------------------------------------------------------
272  
273 =head3 ready() - Ready-Handler der Komponenten
274  
275 =head4 Synopsis
276  
277 $ready | @ready = $c->ready;
278  
279 =head4 Description
280  
281 Liefere den/die Ready-Handler der Komponenten. Im Arraykontext die
282 Liste der Array-Elemente, im Skalarkontext deren Konkatenation.
283  
284 =cut
285  
286 # -----------------------------------------------------------------------------
287  
288 4 ▶sub ready {
Subroutine ready: called CC=1 SCAR=0.0
Pod documented
289 4 return shift->getValue('ready');
290 }
291  
292 # -----------------------------------------------------------------------------
293  
294 =head3 resources() - Resourcen aller Komponenten
295  
296 =head4 Synopsis
297  
298 @resources | $resourceA = $c->resources;
299  
300 =head4 Returns
301  
302 Liste von Resource-URLs. Im Skalarkontext eine Referenz auf die Liste.
303  
304 =head4 Description
305  
306 Liefere die Liste der Resource-URLs aller Komponenten. Mehrfachnennungen
307 werden gefiltert.
308  
309 =cut
310  
311 # -----------------------------------------------------------------------------
312  
313 4 ▶sub resources {
Subroutine resources: called CC=3 SCAR=11.4
Pod documented
314 4 my $self = shift;
315  
316 4 my @arr;
317 4 for my $c (@{$self->elements}) {
318 0 push @arr,$c->resources;
319 }
320  
321 4 ▶ return wantarray? @arr: \@arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 0 4
322 }
323  
324 # -----------------------------------------------------------------------------
325  
326 =head2 Private Methoden
327  
328 =head3 getValue() - Liefere Attributwert
329  
330 =head4 Synopsis
331  
332 $str | @arr = $obj->getValue($key);
333  
334 =head4 Description
335  
336 Liefere den Wert des Attributs $key. Im Arraykontext die Liste der
337 Array-Elemente, im Skalarkontext deren Konkatenation.
338  
339 =cut
340  
341 # -----------------------------------------------------------------------------
342  
343 12 ▶sub getValue {
Subroutine getValue: called CC=3 SCAR=11.4
Pod documented
344 12 my ($self,$key) = @_;
345  
346 12 my @arr;
347 12 for my $c (@{$self->components}) {
348 0 push @arr,$c->$key;
349 }
350  
351 12 ▶ return wantarray? @arr: join '',@arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 0 12
352 }
353  
354 # -----------------------------------------------------------------------------
355  
356 =head1 VERSION
357  
358 1.240
359  
360 =head1 AUTHOR
361  
362 Frank Seitz, L<http://fseitz.de/>
363  
364 =head1 COPYRIGHT
365  
366 Copyright (C) 2026 Frank Seitz
367  
368 =head1 LICENSE
369  
370 This code is free software; you can redistribute it and/or modify
371 it under the same terms as Perl itself.
372  
373 =cut
374  
375 # -----------------------------------------------------------------------------
376  
377 7 1;
378  
379 # eof
« Quiq/Database/Row/Array.pm ↑ Summary Quiq.pm »