Quiq/Html/Tag.pm

filter: Statementstmt 79.0% 301 / 381 Branchbran 69.4% 186 / 268 Conditioncond 71.1% 74 / 104 MC/DCmcdc 46.8% 30 / 64 Subroutinesub 92.3% 24 / 26 Podpod 100% 11 / 11 totaltotal 73.3% 626 / 854 CC 172 SCAR 55.0
CC
172
Cov
75%
tag
409.9
cat
21.7
doctype
18.6
CRAP 245.7
« Quiq/Gd/Component/Axis.pm ↑ Summary Quiq/LaTeX/Document.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::Tag - Generierung von HTML-Tags
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 =head2 Zweck der Klasse
16  
17 Die Klasse generiert HTML-Code. Sie implementiert zwei Methoden -
18 tag() und cat() - mit denen HTML-Code beliebiger Komplexität
19 erzeugt werden kann.
20  
21 =head2 Methode new()
22  
23 Ein Objekt der Klasse wird instantiiert durch
24  
25 my $h = Quiq::Html::Tag->new;
26  
27 Die Methoden dieses Objekts generieren (X)HTML.
28  
29 =head2 Methode tag()
30  
31 Die Methode tag() generiert einen Tag. Sie kennt
32 alle Element-Typen des W3C HTML/XHTML Standard und liefert bei Aufruf
33 eine formatierte Tag-Repräsentation des betreffenden Element-Typs
34 und seiner Attribute. Beispiel:
35  
36 $str = $h->tag('img',src=>'URL');
37  
38 ergibt
39  
40 <img src="URL" alt="" />
41  
42 Das Beispiel verdeutlicht, dass der Methode tag() die
43 Element-Typen "kennt". In diesem Fall "weiß" die Methode, dass
44 Elemente des Typs 'img' leer sind und diese ein Pflicht-Attribut
45 'alt' besitzen (wird es nicht gesetzt, erhält es den Wert "").
46  
47 Die Methode tag() hat die Signatur:
48  
49 $str = $h->tag($elem,@keyVal,$content);
50  
51 Hierbei ist $elem der Element-Typ, @keyVal die Liste der
52 Attribut/Wert-Paare und Optionen (siehe unten) und $content
53 ist der Inhalt des Tag.
54  
55 Da die Argumente der Methode die gleiche Abfolge haben wie die
56 Bestandteile eines Tag in HTML, können die Methodenaufrufe in Perl
57 analog geschachtelt werden wie die Tags in HTML. Beispiel:
58  
59 $h->tag('a',href=>'URL1',
60 $h->tag('img',src=>'URL2'),
61 );
62  
63 ergibt
64  
65 <a href="URL1"><img src="URL2" alt="" /></a>
66  
67 =head2 Methode cat()
68  
69 Die Elemente eines HTML-Dokuments können syntaktisch natürlich
70 nicht nur geschachtelt auftreten, sie können auch
71 aufeinanderfolgen. Die Methode cat() fügt aufeinanderfolgende
72 HTML-Elemente zusammen.
73  
74 Die Methode cat() hat folgende Signatur:
75  
76 $str = $h->cat(@args);
77  
78 Hierbei ist @args die Liste der HTML-Elemente, die zusammengefügt
79 werden sollen.
80  
81 Beispiel:
82  
83 $h->cat(
84 $h->tag('li','Orange'),
85 $h->tag('li','Zitrone'),
86 $h->tag('li','Ananas'),
87 );
88  
89 ergibt
90  
91 <li>Orange</li>
92 <li>Zitrone</li>
93 <li>Ananas</li>
94  
95 Die Methode cat() wird von der Methode tag() intern gerufen, um
96 den Content des Tag zu konstruieren. Erstreckt sich der Content
97 über mehrere Argumente, statt nur einem Argument (dem letzten), muss der
98 Methode tag() das Ende der @keyVal Argumente angezeigt werden.
99 Dies geschieht durch Setzen des Arguments '-' vor die
100 Content-Argumente.
101  
102 $h->tag('ul','-',
103 $h->tag('li','Orange'),
104 $h->tag('li','Zitrone'),
105 $h->tag('li','Ananas'),
106 );
107  
108 ergibt
109  
110 <ul>
111 <li>Orange</li>
112 <li>Zitrone</li>
113 <li>Ananas</li>
114 </ul>
115  
116 Der Inhalt eines Tag kann nicht nur aus HTML-Elementen bestehen,
117 sondern auch einfachen Text enthalten oder aus einer Mischung
118 aus Text und Elementen bestehen. Beispiel:
119  
120 $h->tag('p','-',
121 'Auf ',$h->tag('a',href=>'http://cpan.org','CPAN'),
122 ' sind ',$h->tag('b','viele'),' Module!',
123 );
124  
125 ergibt
126  
127 <p>
128 Auf <a href="http://cpan.org">CPAN</a> sind <b>viele</b> Module!
129 </p>
130  
131 =head2 Komplexere HTML-Strukturen
132  
133 Mit der Methode tag() lassen sich beliebig komplexe HTML-Strukturen
134 generieren. Der folgende Code produziert ein einfaches, bis auf
135 die fehlende Dokumenttyp-Deklaration vollständiges HTML-Dokument.
136  
137 $h->tag('html','-',
138 $h->tag('head',
139 $h->tag('title','Test'),
140 ),
141 $h->tag('body',
142 $h->tag('p',q|
143 Hallo
144 Welt!
145 |),
146 ),
147 );
148  
149 liefert
150  
151 <html xmlns="http://www.w3.org/1999/xhtml">
152 <head>
153 <title>Test</title>
154 </head>
155 <body>
156 <p>
157 Hallo
158 Welt!
159 </p>
160 </body>
161 </html>
162  
163 =head2 Formatierung
164  
165 Wer die obigen Beispiele genau betrachtet, bemerkt, dass die Tags
166 nicht alle mit der gleichen Formatierung generiert werden.
167 Der a-Tag umschließt seinen Inhalt unmittelbar
168  
169 <a ...>INHALT</a>
170  
171 wohingegen der p-Tag seinen Inhalt um zwei Leerzeichen einrückt
172 und der Begin- und End-Tag auf einer eignenen Zeile stehen
173  
174 <p>
175 INHALT
176 </p>
177  
178 Dies sind zwei der Formatierungsvarianten, die die Methode
179 tag() kennt.
180  
181 Für jeden HTML Element-Typ ist eine Default-Formatierung definiert,
182 welche bestimmt, wie die Tags des Element-Typs formatiert werden.
183 Jedes Format wird mit einem Buchstaben bezeichnet: e, E, i, m, M, p, v.
184  
185 e=empty mit Zeilenumbruch
186  
187 Der Tag hat keinen Inhalt und steht auf einer eigenen Zeile (d.h.
188 er wird mit \n abgeschlossen):
189  
190 <br />\n
191  
192 E=empty ohne Zeilenumbruch
193  
194 Wie e, nur dass der Tag nicht auf einer eigenen Zeile steht (also
195 nicht mit \n abgeschlossen wird):
196  
197 <img ... />
198  
199 i=inline
200  
201 Der Tag umschließt seinen Inhalt unmittelbar, es wird
202 kein \n angehängt:
203  
204 <a ...>IRGENDEIN\n
205 INHALT</a>
206  
207 m=multiline mit Einrückung
208  
209 Der Inhalt wird um zwei Leerzeichen eingerückt, der Tag umschließt
210 diesen auf getrennten Zeilen. Das Konstrukt endet mit einem \n:
211  
212 <p ...>\n
213 IRGENDEIN\n
214 INHALT\n
215 </p>\n
216  
217 M=multiline ohne Einrückung
218  
219 Wie m, nur dass der Inhalt nicht eingerückt wird:
220  
221 <html ...>\n
222 HEAD\n
223 BODY\n
224 </html>\n
225  
226 p=protected
227  
228 Der Inhalt wird einzeilig gemacht, indem LF- und CR-Zeichen durch
229 die Entities &#10; und &#13; ersetzt werden und vom Tag
230 unmittelbar umschlossen werden.
231  
232 <pre ...>IRGENDEIN&#10;INHALT</pre>\n
233  
234 Diese Formatierung schützt den Tag-Inhalt davor, dass er
235 durch eine Einrückung äußerer Tags verändert wird. Sie wird
236 bei Tags angewendet, bei deren Inhalt Whitespace signifikant ist.
237  
238 v=variable
239  
240 Enthält der Inhalt keine Zeilenumbrüche, wird er einzeilig ausgelegt:
241  
242 <title>INHALT</title>\n
243  
244 Enthält der Inhalt Zeilenumbrüche, wird er mehrzeilig ausgelegt:
245  
246 <title>
247 EIN
248 TITEL
249 </title>
250  
251 =head2 Setzen von data-* Attributen
252  
253 Die Methode tag() unterstützt data-* Attribute auf zwei Weisen:
254  
255 =over 4
256  
257 =item 1.
258  
259 Einzelne Attribute:
260  
261 $h->tag('form',
262 'data-x' => 'a',
263 'data-y' => 'b',
264 'data-z' => 'c',
265 ...
266 );
267  
268 =item 2.
269  
270 Liste von Attributen:
271  
272 $h->tag('form',
273 data => [
274 x => 'a',
275 y => 'b',
276 z => 'c',
277 ],
278 ...
279 );
280  
281 =back
282  
283 Das Resultat in beiden Fällen:
284  
285 <form data-z="c" data-y="b" data-x="a" ...></form>
286  
287 =head2 HTML Element-Typen
288  
289 Die Methode tag() kennt alle Element-Typen des W3C-Standards. Die
290 folgende Liste gibt den Element-Typ, die Default-Formatierung und
291 die Default-Attribute an:
292  
293 Element Format Default-Attribute
294
295 a i
296 abbr i
297 acronym i
298 address v
299 area e
300 b i
301 base e
302 bdo i
303 big i
304 blockquote m
305 body M
306 br e
307 button v
308 caption v
309 cite i
310 code i
311 col e
312 colgroup m
313 dd v
314 del i
315 dfn i
316 div m
317 dl m
318 dt v
319 em i
320 fieldset m
321 form M
322 frame e
323 frameset m
324 h1 v
325 h2 v
326 h3 v
327 h4 v
328 h5 v
329 h6 v
330 head m
331 hr e
332 html M xmlns=>'http://www.w3.org/1999/xhtml' (nur XHTML)
333 i i
334 iframe v
335 img E alt=>''
336 input e
337 ins i
338 kbd i
339 label v
340 legend v
341 li v
342 link e
343 map m
344 meta e
345 noframes m
346 noscript m
347 object m
348 ol m
349 optgroup m
350 option v
351 p m
352 param e
353 pre p
354 q i
355 samp i
356 script m type=>'text/javascript'
357 select v
358 small i
359 span i
360 strong i
361 style m type=>'text/css'
362 sub i
363 sup i
364 table M
365 tbody m
366 td v
367 textarea p
368 tfoot m
369 th v
370 thead m
371 title v
372 tr m
373 tt i
374 ul m
375 var i
376  
377 Das Default-Format kann mit der Option -fmt=>$val bei Aufruf
378 der Methode tag() überschrieben werden.
379  
380 =head2 Zeilenumbruch
381  
382 Bei allen Formaten außer i (inline) endet der generierte Tag Code per
383 Default mit einem Zeilenumbruch. Die Zahl der angehängten Zeilenumbrüche
384 kann unabhängig davon mit der Option -nl=>$n gesetzt werden.
385 Bei -nl=>0 wird kein Zeilenumbruch angehängt.
386  
387 =head2 HTML statt XHTML
388  
389 Per Default wird XHTML-Code generiert. Um klassischen HTML-Code
390 zu generieren, wird die HTML-Version gesetzt:
391  
392 Quiq::Html::Tag->setDefault(htmlVersion=>'html-4.01');
393  
394 Ab diesem Aufruf instantiieren die nachfolgenden Konstruktor-Aufrufe
395 (sofern sie die htmlVersion nicht selbst setzen) Objekte zur Generierung
396 von klassischem HTML.
397  
398 Der generierte Code sieht bei klassischem HTML folgendermaßen aus:
399  
400 <a href="URL1"><img src="URL2" alt=""></a>
401  
402 Man beachte, dass der img-Tag nun mit '>', nicht mit ' />'
403 abgeschlossen ist.
404  
405 =head2 HTML mit Großschreibung
406  
407 HTML-Code mit großgeschriebenen Element- und Attributnamen wird
408 nach folgender Setzung erzeugt:
409  
410 Quiq::Html::Tag->setDefault(htmlVersion=>'html-4.01',uppercase=>1);
411  
412 Der generierte Code sieht dann so aus:
413  
414 <A HREF="URL1"><IMG SRC="URL2" ALT=""></A>
415  
416 Ist XHTML ('xhtml-1.0') eingestellt, hat die Option uppercase=>1
417 keinen Einfluss.
418  
419 =head1 ATTRIBUTES
420  
421 =over 4
422  
423 =item checkLevel => 0|1|2 (Default: 1)
424  
425 Umfang der Element/Attribut-Prüfung.
426  
427 =over 4
428  
429 =item Z<>0
430  
431 keine Prüfung
432  
433 =item Z<>1
434  
435 prüfe Element-Typ
436  
437 =item Z<>2
438  
439 prüfe Element-Typ und Attributnamen
440  
441 =back
442  
443 Wird ein Fehler festgestellt, wird eine Exception geworfen.
444  
445 =item compact => $bool (Default: 0)
446  
447 Generiere den HTML-Code einzeilig mit so wenig Whitespace wie möglich.
448  
449 =item embedImages => $bool (Default: 0)
450  
451 Füge Bilddaten direkt in HTML ein.
452  
453 =item htmlVersion => 'html-4.01'|'html-5'|'xhtml-1.0' (Default: 'xhtml-1.0')
454  
455 HTML-Version. Beginnt die Versionsangabe mit 'xhtml' wird das
456 HTML gemäß den Regeln für XHTML generiert, andernfalls für
457 klassisches HTML. Die Versionsnummer wird bei der Generierung
458 des DOCTYPE herangezogen.
459  
460 =item indentation => $n (Default: undef)
461  
462 Forciere eine Content-Einrückung um $n Leerzeichen. Bei indentation=>0
463 wird nicht eingerückt. Ist indentation nicht gesetzt, gilt die
464 Einrückung, die als Argument bei der Tag-Methode angegeben ist bzw.
465 die in der Methode tag() als Default vorgegeben ist.
466  
467 =item uppercase => $bool (Default: 0)
468  
469 Erzeuge Tag- und Attribut-Namen in Großschreibung. Diese Setzung
470 wird nur bei klassischem HTML - nicht bei XHTML - beachtet.
471  
472 =back
473  
474 =cut
475  
476 # -----------------------------------------------------------------------------
477  
478 package Quiq::Html::Tag;
479 36 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
480  
481 36 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
482 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
483 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
484 36 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
485  
486 36 our $VERSION = '1.240';
487  
488 36 ▶use Quiq::Css;
Subroutine BEGIN: called CC=1 SCAR=0.0
489 36 ▶use Quiq::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
490 36 ▶use Quiq::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
491 36 ▶use Quiq::JavaScript;
Subroutine BEGIN: called CC=1 SCAR=0.0
492 36 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
493 36 ▶use Quiq::Image;
Subroutine BEGIN: called CC=1 SCAR=0.0
494 36 ▶use Quiq::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
495 36 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
496  
497 # -----------------------------------------------------------------------------
498  
499 # Attribute und Defaultwerte bei der Instantiierung. Werden die
500 # Werte anders gesetzt, gelten sie für die gesamte Applikation.
501  
502 36 my %Default = (
503 checkLevel => 1, # Umfang der Element- und Attribut-Prüfungen
504 compact => 0, # Einzeilig, Whitespace komprimiert
505 embedImages => 0, # Einbettung von Bildern
506 # htmlVersion => 'xhtml-1.0', # XHTML vs. HTML, Versionsnr. für DOCTYPE
507 htmlVersion => 'html-5', # XHTML vs. HTML, Versionsnr. für DOCTYPE
508 indentation => undef, # forcierte Einrückung
509 oneLineCss => 0, # <style>-Content stets einzeilig
510 oneLineJs => 0, # <script>-Content stets einzeilig
511 uppercase => 0, # wandele Elem.- und Att.-Namen in Großschr.
512 );
513 36 Hash::Util::lock_keys(%Default);
514  
515 # Liste der vom W3C definierten (X)HTML-DTD- und Frameset-DTD-Elemente
516 # und ihre Default-Formatierung
517  
518 36 my %Element = (
519 a => 'i', # Link, Anker
520 abbr => 'i', # Text ist Abkürzung
521 acronym => 'i', # Text ist Akronym
522 address => 'v', # Text ist Adressangabe
523 area => 'e', # Bereich in einer clientseitigen Image-Map
524 b => 'i', # Fettschrift
525 base => 'e', # Basis-Pfadname für alle relativen URLs
526 bdo => 'i', # Text mit anderer Laufrichtung
527 big => 'i', # Großschrift
528 blockquote => 'm', # Zitatabschnitt
529 body => 'm', # Rumpf HTML-Seite
530 br => 'e', # Zeilenumbruch
531 button => 'v', # Schaltfläche
532 caption => 'v', # Beschriftung zu einer Tabelle
533 canvas => 'm', # HTML 5, Fläche zum Zeichnen
534 cite => 'i', # Text ist Hinweis auf Literaturstelle
535 code => 'i', # Codebeispiel
536 col => 'e', # Eigenschaften einer Tabellenspalte
537 colgroup => 'm', # Definition einer Spaltengruppe
538 dd => 'v', # Text Definitionsliste
539 del => 'i', # gelöschter Text
540 details => 'm', # Details, die aufklappbar sind
541 dfn => 'i', # Text ist Definition
542 div => 'm', # allgemeines Block-Element
543 dl => 'm', # Definitionsliste
544 dt => 'v', # Terminus Definitionsliste
545 em => 'i', # hervorgehobener Text
546 fieldset => 'm', # Gruppe von Feldern eines Formulars
547 form => 'm', # Formular
548 frame => 'e', # (Frameset-DTD) Frame eines Frameset
549 frameset => 'm', # (Frameset-DTD) Frameset
550 h1 => 'v', # Überschrift
551 h2 => 'v', # Überschrift
552 h3 => 'v', # Überschrift
553 h4 => 'v', # Überschrift
554 h5 => 'v', # Überschrift
555 h6 => 'v', # Überschrift
556 head => 'm', # Kopf HTML-Seite
557 hr => 'e', # Trennbalken
558 html => 'M', # HTML-Seite
559 i => 'i', # kursiver Text
560 iframe => 'v', # (Frameset-DTD) Inline-Frame
561 img => 'E', # Bild
562 input => 'e', # Formular-Eingabeelement
563 ins => 'i', # eingefügter Text
564 kbd => 'i', # Text stellt Benutzereingabe dar
565 label => 'v', # Label zu Formular-Eingabeelement
566 legend => 'v', # Beschriftung zu Fieldset
567 li => 'v', # Listenelement
568 link => 'e', # Definiert Beziehung zu anderem Dokument
569 map => 'm', # Definition clientseitige Image-Map
570 meta => 'e', # Information zum Dokument
571 noframes => 'm', # (Frameset-DTD) Inhalt für nicht-framefähige Browser
572 noscript => 'm', # Inhalt für nicht-skriptfähige Browser
573 object => 'm', # einbettetes Objekt
574 ol => 'm', # nummerierte Liste
575 optgroup => 'm', # Gruppe von Optionen einer Selectliste
576 option => 'v', # Option einer Selectliste
577 p => 'm', # Absatz
578 param => 'e', # Parameter eines Object
579 pre => 'p', # Leerraum und Zeilenumbrüche erhalten
580 q => 'i', # Kurzzitat
581 samp => 'i', # Text stellt Ausgabe eines Programms dar
582 script => 'c', # Code, der vom Browser ausgeführt wird
583 select => 'v', # Auswahlmenü
584 small => 'i', # Kleinschrift
585 span => 'i', # allgemeines Inline-Element
586 strong => 'i', # stark hervorgehobener Text
587 style => 'v', # Stylesheet-Regeln
588 sub => 'i', # tiefgestellter Text
589 summary => 'm', # Kurzbeschreibung zu Details (<details>)
590 sup => 'i', # hochgestellter Text
591 table => 'M', # Tabelle
592 tbody => 'm', # Rumpf Tabelle
593 td => 'v', # Tabellenzelle
594 textarea => 'p', # Text-Eingabefeld
595 tfoot => 'm', # Fuß Tabelle (identisch zu tbody)
596 th => 'v', # Tabellenkopfzelle (identisch zu td)
597 thead => 'm', # Kopf Tabelle (identisch zu tbody)
598 title => 'v', # Titel HTML-Dokument
599 tr => 'm', # Tabellenzeile
600 tt => 'i', # Schreibmaschinenschrift
601 ul => 'm', # Ungeordnete Liste
602 var => 'i', # Text ist Variablenname
603 );
604  
605 # Default-Optionen
606  
607 36 my %DefaultOptions = (
608 p => [-ignoreIfNull=>1],
609 span => [-ignoreIfNull=>1],
610 );
611  
612 # Default-Attribute von Elementen allgemein
613  
614 36 my %DefaultAttributes = (
615 # form => [method=>'post',enctype=>'multipart/form-data'],
616 img => [alt=>''],
617 script => [type=>'text/javascript'],
618 style => [type=>'text/css'],
619 );
620  
621 # Default-Attribute, nur XHTML
622  
623 36 my %DefaultAttributesXhtml = (
624 html => [xmlns=>'http://www.w3.org/1999/xhtml'],
625 );
626  
627 # Liste aller Attribute und ihrer Domänen.
628 # FIXME: anhand DTD überprüfen
629  
630 36 my %Attribute = (
631 'accept-charset' => 'charsets', # form
632 'http-equiv' => 'cdata', # meta
633 'xml:lang' => 'languageCode', # I18N (XHTML)
634 'xml:space' => 'space', # ENUM pre,script,style(XHTML)
635 abbr => 'text', # Cell
636 accept => 'contentTypes', # form,input
637 accesskey => 'character', # Focus,legend
638 action => 'uri', # form
639 align => 'cellAlign', # ENUM CellAlign
640 alt => 'cdata', # input(cdata);area,img(text)
641 archive => 'uriList', # object
642 axis => 'cdata', # Cell
643 border => 'pixels', # table
644 cellpadding => 'length', # table
645 cellspacing => 'length', # table
646 char => 'character', # CellAlign
647 charoff => 'length', # CellAlign
648 charset => 'charset', # a,link,script
649 checked => 'bool', # input
650 cite => 'uri', # blockquote,del,ins,q
651 class => 'class', # Core
652 classid => 'uri', # object
653 codebase => 'uri', # object
654 codetype => 'contentType', # object
655 cols => 'multiLengths', # frameset(multiLengths),textarea(number)
656 colspan => 'number', # Cell
657 content => 'cdata', # meta
658 coords => 'coords', # a, area
659 data => 'uri', # object
660 datetime => 'datetime', # del, ins
661 declare => 'bool', # object
662 defer => 'bool', # script
663 dir => 'dir', # ENUM I18N
664 disabled => 'bool', # button,input,optgroup,option,select,
665 # textarea
666 download => 'filename', # a
667 enctype => 'contentType', # form
668 frame => 'tframe', # ENUM table
669 frameborder => 'frameBorder', # ENUM frame, iframe
670 headers => 'idrefs', # Cell
671 height => 'length', # iframe,img,object
672 href => 'uri', # a,area,base,link
673 hreflang => 'languageCode', # a,link
674 id => 'id', # Core
675 ismap => 'bool', # img,input
676 label => 'text', # optgroup,option
677 lang => 'languageCode', # I18N
678 longdesc => 'uri', # frame,iframe,img
679 marginheight => 'pixels', # frame,iframe
680 marginwidth => 'pixels', # frame,iframe
681 maxlength => 'number', # input
682 media => 'mediaDesc', # ENUM link,style
683 method => 'method', # ENUM form
684 multiple => 'bool', # select
685 name => 'nmtoken', # button,input,meta,param,select,textarea,
686 # object;form,frame,map(HTML)
687 nohref => 'bool', # area
688 noresize => 'bool', # frame
689 onblur => 'script', # Focus,select
690 onchange => 'script', # input,select,textarea
691 onclick => 'script', # Event
692 ondblclick => 'script', # Event
693 onfocus => 'script', # Focus,select
694 onkeydown => 'script', # Event
695 onkeypress => 'script', # Event
696 onkeyup => 'script', # Event
697 onload => 'script', # body,frameset
698 onmousedown => 'script', # Event
699 onmousemove => 'script', # Event
700 onmouseout => 'script', # Event
701 onmouseover => 'script', # Event
702 onmouseup => 'script', # Event
703 onreset => 'script', # form
704 onselect => 'script', # input,textarea
705 onsubmit => 'script', # form
706 onunload => 'script', # body,frameset
707 profile => 'uri', # head
708 readonly => 'bool', # input,textarea
709 rel => 'linkTypes', # ENUM a,link
710 rev => 'linkTypes', # ENUM a,link
711 rows => 'multiLengths', # frameset(multiLengths);textarea(number)
712 rowspan => 'number', # Cell
713 rules => 'trules', # ENUM table
714 scheme => 'cdata', # meta
715 scope => 'scope', # ENUM Cell
716 scoped => 'bool', # style
717 scrolling => 'scrolling', # ENUM frame,iframe
718 selected => 'bool', # option
719 shape => 'shape', # ENUM a,area
720 size => 'number', # input,select
721 span => 'number', # col,colgroup
722 src => 'uri', # frame,iframe,img,input,script
723 standby => 'text', # object
724 style => 'styleSheet', # Core
725 summary => 'text', # table
726 tabindex => 'number', # Focus,object,select
727 target => 'frameTarget', # a,area,base,form,link
728 title => 'text', # Core,style
729 type => 'ContentType', # button(ENUM);a,link,object,param,script,
730 # style;input(ENUM)
731 usemap => 'uri', # img,input,object
732 valign => 'cellValign', # ENUM CellAlign
733 value => 'cdata', # button,input,option,param
734 valuetype => 'valueType', # ENUM param
735 width => 'length', # iframe,img,object,table(length);
736 # col,colgroup(multiLength)
737 xmlns => 'uri', # html (XHTML)
738 );
739  
740 # Attribut-Domänen (werden aktuell nicht geprüft)
741  
742 36 my %Domain = (
743 bool => 1,
744 buttonType => [qw/button reset submit/],
745 cdata => 1,
746 cellAlign => [qw/center char justify left right/],
747 cellValign => [qw/baseline bottom middle top/],
748 character => 1,
749 charset => 1,
750 charsets => 1,
751 class => 1,
752 contentType => 1,
753 contentTypes => 1,
754 coords => 1,
755 datetime => 1,
756 dir => [qw/ltr rtl/],
757 frameBorder => [0,1],
758 frameTarget => 1,
759 id => 1,
760 idrefs => 1,
761 inputType => [qw/checkbox file hidden password radio reset submit text/],
762 languageCode => 1,
763 length => 1,
764 linkTypes => [qw/stylesheet next prev copyright index glossary/], # unv.
765 mediaDesc => [qw/all aural braille handheld print projection screen
766 tty tv/],
767 method => [qw/get post/],
768 multiLength => 1,
769 multiLengths => 1,
770 nmtoken => 1,
771 number => 1,
772 pixels => 1,
773 scope => [qw/col colgroup row rowgroup/],
774 script => 1,
775 scrolling => [qw/no yes auto/],
776 shape => [qw/circle default poly rect/],
777 space => ['preserve'],
778 styleSheet => 1,
779 text => 1,
780 tframe => [qw/above below border box hsides lhs rhs void vsides/],
781 trules => [qw/all cols groups none rows/],
782 uri => 1,
783 uriList => 1,
784 valueType => [qw/data object ref/],
785 );
786  
787 # # den Platzbdearf der Hashes ausgeben
788 #
789 # use Devel::Size;
790 # my @arr = (
791 # Default => \%Default,
792 # Element => \%Element,
793 # Attribute => \%Attribute,
794 # DefaultAttributes => \%DefaultAttributes,
795 # DefaultAttributesXhtml => \%DefaultAttributesXhtml,
796 # );
797 # my $bytes = 0;
798 # my $str = '';
799 # while (@arr) {
800 # my $name = shift @arr;
801 # my $ref = shift @arr;
802 # my $n = Devel::Size::total_size($ref);
803 # $bytes += $n;
804 # $str .= ', ' if $str;
805 # $str .= "%$name: $n";
806 # }
807 # warn "$str, Gesamt: $bytes Bytes\n";
808  
809 # -----------------------------------------------------------------------------
810  
811 =head1 METHODS
812  
813 =head2 Klassenmethoden
814  
815 =head3 new() - Konstruktor
816  
817 =head4 Synopsis
818  
819 $h = $class->new(@keyVal);
820 $h = $class->new($htmlVersion,@keyVal);
821  
822 =head4 Description
823  
824 Instantiiere ein Objekt zur Generierung von HTML-Code und liefere eine
825 Referenz auf dieses Objekt zurück.
826  
827 =cut
828  
829 # -----------------------------------------------------------------------------
830  
831 58 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
832 58 my $class = shift;
833  
834 58 my $self = $class->SUPER::new(%Default);
835 58 ▶ if (@_%2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 8 50 58
836 # Wenn ungerade Anzahl Argumente, interpretieren wir
837 # das erste Argument als HTML-Version.
838 8 unshift @_,'htmlVersion';
839 }
840 58 $self->set(@_);
841  
842 58 return $self;
843 }
844  
845 # -----------------------------------------------------------------------------
846  
847 =head3 setDefault() - Setze Objekt-Defaults
848  
849 =head4 Synopsis
850  
851 $class->setDefault(@keyVal);
852  
853 =head4 Arguments
854  
855 =over 4
856  
857 =item @keyVal
858  
859 Liste der Schlüssel/Wert-Paare, die gesetzt werden sollen.
860  
861 =back
862  
863 =head4 Example
864  
865 Definiere, dass applikationsweit jeglicher CSS- und JavaScript-Code
866 in HTML einzeilig dargestellt wird:
867  
868 Quiq::Html::Tag->setDefault(
869 oneLineCss => 1,
870 oneLineJs => 1,
871 );
872  
873 =cut
874  
875 # -----------------------------------------------------------------------------
876  
877 0 ▶sub setDefault {
Subroutine setDefault: not called CC=3 SCAR=24.8
Pod documented
878 0 my $class = shift;
879 # @_: @keyVal
880  
881 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
882 0 my $key = shift;
883 0 ▶ if (!exists $Default{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Default{$key}) 0 0 0
884 0 $class->throw(
885 'HTML-00099: Unkown attribute',
886 Attribute => $key,
887 );
888 }
889 0 $Default{$key} = shift;
890 }
891  
892 0 return;
893 }
894  
895 # -----------------------------------------------------------------------------
896  
897 =head2 Objektmethoden
898  
899 =head3 tag() - Generiere HTML-Tag
900  
901 =head4 Synopsis
902  
903 $html = $h->tag($elem,@keyVal); # [1]
904 $html = $h->tag($elem,@keyVal,$content); # [2]
905 $html = $h->tag($elem,@keyVal,'-',@content); # [3]
906  
907 =head4 Options
908  
909 =over 4
910  
911 =item - (Dash)
912  
913 Ende der Attribut/Wert-Liste. Die restlichen Argumente werden
914 zum Inhalt konkateniert.
915  
916 $h->tag('p',class=>'p1','-',
917 'Ein ',$h->tag('b','kurzer'),' Text.'
918 );
919  
920 Man beachte die Kommata zwischen den Argumenten.
921  
922 Ohne '-' wird allein das letzte Argument als Inhalt aufgefasst.
923 Besteht der Inhalt aus mehreren Teilen, müssen die Teile
924 dann konkateniert werden:
925  
926 $h->tag('p',class => 'p1',
927 'Ein '.$h->tag('b','kurzer').' Text.'
928 );
929  
930 =item -checkLevel => 0|1|2 (Default: 1)
931  
932 Umfang der Element-Typ und Attribut-Prüfung.
933  
934 =item -compact => $bool (Default: Wert des Attributs compact)
935  
936 Generiere den HTML-Code einzeilig mit so wenig Whitespace wie möglich.
937 Soll sämtlicher HTML-Code einzeilig erzeugt werden,
938 genügt es, beim Konstruktor das Attribut compact zu setzen:
939  
940 $h = Quiq::Html::Tag->new(...,compact=>1);
941  
942 =item -contentInd => $n (Default: undef)
943  
944 Reduziere die Content-Einrückung auf $n, wenn möglich. Im Falle
945 von undef wird an der Content-Einrückung nichts geändert. Diese
946 Option ist nützlich, wenn der Content eingerückter Code ist (Tags
947 <style> und <script>) und dieser auf bei der Seitengenerierung auf
948 eine geringere Einrücktiefe gebracht werden soll (z.B. von 4 auf 2).
949  
950 =item -embedImage => $bool (Default: 0)
951  
952 Bette im Falle eines <img>-Tag das Bild in den HTML-Code ein.
953  
954 =item -endTagOnly => $bool (Default: 0)
955  
956 Erzeuge nur den Content und den End-Tag. Diese Option ist nützlich,
957 wenn der HTML-Code inkrementell geschrieben wird und z.B. im Fehlerfall
958 nur der Rest mit schließenden Tags generiert werden soll.
959  
960 my $html = $h->tag('html',
961 -endTagOnly => 1,
962 $h->tag('body',
963 -endTagOnly => 1,
964 '-',
965 $h->tag('h1','Fatal Error'),
966 $h->tag('pre',$msg),
967 )
968 );
969 $http->append($html);
970  
971 =item -fmt => 'c'|'e'|'E'|'m'|'M'|'p'|'P'|'v'|'i' (Default: gemäß $elem)
972  
973 Art der Content-Formatierung.
974  
975 =over 4
976  
977 =item 'e' (empty)
978  
979 Element hat keinen Content (br, hr, ...)
980  
981 <TAG ... />\n
982  
983 =item 'E' (empty, kein NEWLINE)
984  
985 Wie 'e', nur ohne NEWLINE am Ende (img, input, ...)
986  
987 <TAG ... />
988  
989 =item 'm' (multiline)
990  
991 Content wird auf eigene Zeile(n) zwischen Begin- und End-Tag
992 gesetzt und um -ind=>$n Leerzeichen eingerückt. Ist der Content
993 leer, wird der End-Tag direkt hinter den Begin-Tag gesetzt.
994 (html, head, body, form, p, div, script, style, ...)
995  
996 <TAG ...>
997 CONTENT
998 </TAG>\n
999  
1000 Ist der Content leer:
1001  
1002 <TAG ...></TAG>
1003  
1004 =item 'M' (multiline, ohne Einrückung)
1005  
1006 Wie 'm', nur ohne Einrückung (html, ...)
1007  
1008 <TAG ...>
1009 CONTENT
1010 </TAG>\n
1011  
1012 =item 'c' (cdata)
1013  
1014 Wie 'm', nur dass der Content in CDATA eingefasst wird:
1015  
1016 <TAG ...>
1017 // <![CDATA[
1018 CONTENT
1019 // ]]>
1020 </TAG>
1021  
1022 Der W3 HTML Validator bemängelt die Zeichen & und > dann nicht
1023 im Content. (script)
1024  
1025 =item 'p' (protect)
1026  
1027 Der Content wird geschützt, indem dieser einzeilig gemacht
1028 (LF und CR werden durch &#10; und &#13; ersetzt) und unmittelbar
1029 zwischen Begin- und End-Tag gesetzt wird (pre, textarea, ...).
1030  
1031 <TAG ...>CONTENT</TAG>\n
1032  
1033 =item 'P' (protect, Einrückung entfernen)
1034  
1035 Wie 'p', nur dass die Einrückung des Content entfernt wird.
1036  
1037 =item 'v' (variable)
1038  
1039 Ist der Content einzeilig, wird er unmittelbar zwischen Begin-
1040 und End-Tag gesetzt:
1041  
1042 <TAG ...>CONTENT</TAG>\n
1043  
1044 Ist der Content mehrzeilig, wird er eingerückt:
1045  
1046 <TAG ...>
1047 CONTENT
1048 </TAG>\n
1049  
1050 (title, h1-h6, ...)
1051  
1052 =item 'i' (inline)
1053  
1054 Der Content wird belassen wie er ist. Dies ist der Default für Tags,
1055 die in Fließtext eingesetzt werden. Ein NEWLINE wird nicht angehängt.
1056  
1057 Text Text <TAG ...>Text Text
1058 Text</TAG> Text Text
1059  
1060 (a, b, span, ...)
1061  
1062 =back
1063  
1064 Bei Wert 0 generiere keinen End-Tag bei leerem Content, sondern
1065  
1066 <TAG .../>
1067  
1068 =item -ignoreIf => $bool (Default: 0)
1069  
1070 Liefere Leerstring, wenn Bedingung $bool erfüllt ist.
1071  
1072 =item -ignoreIfNull => $bool (Default: 0)
1073  
1074 Liefere Leerstring, wenn $content null (Leerstring oder undef)
1075 ist. Für verschiedene Tags ist C<< -ignoreIfNull=>1 >> der
1076 Default. Siehe Hash C<%DefaultOptions>. MEMO: Dieser Hash ist
1077 nicht vollständig erstellt und kann (soll) nach Bedarf ergänzt
1078 werden, insbesondere hinsichtlich der Option C<-ignoreIfNull>.
1079 Für zahlreiche weitere Tags dürfte dies ein sinnvoller Default
1080 sein (aber nicht für alle).
1081  
1082 =item -ignoreTagIf => $bool (Default: 0)
1083  
1084 Liefere $content (ohne Tag), wenn $bool erfüllt ist.
1085  
1086 =item -ind => $n (Default: 2)
1087  
1088 Rücke $content um $n Leerzeichen ein.
1089  
1090 =item -indPos => $n (Default: 0)
1091  
1092 Rücke bis auf die erste Zeile den Tag um $n Leerzeichen ein
1093 und entferne Zeilenumbrüche am Ende. Diese Option ist nützlich, wenn
1094 der Tag für einen Platzhalter mit der Einrücktiefe $n
1095 in bestehenden HTML-Code eingesetzt wird.
1096  
1097 =item -indTag => $n (Default: 0)
1098  
1099 Rücke den Tag um $n Leerzeichen ein.
1100  
1101 =item -nl => $n (Default: 1)
1102  
1103 Anzahl NEWLINEs am Ende.
1104  
1105 -nl => 0 (kein NEWLINE):
1106  
1107 <TAG>CONTENT</TAG>
1108  
1109 -nl => 1 (ein NEWLINE):
1110  
1111 <TAG>CONTENT</TAG>\n
1112  
1113 -nl => 2 (zwei NEWLINEs):
1114  
1115 <TAG>CONTENT</TAG>\n\n
1116
1117 usw.
1118  
1119 =item -placeholders => \@keyVal (Default: undef)
1120  
1121 Ersetze im generierten HTML-Code die angegebenen Platzhalter durch
1122 ihre Werte.
1123  
1124 =item -remComments => $bool (Default: 0)
1125  
1126 Entferne Kommentare aus dem Content. Die Option berücksichtigt,
1127 ob es sich um HTML-, CSS- oder JavaScript-Content handelt.
1128  
1129 =item -remNl => $bool (Default: 0)
1130  
1131 Entferne Leerzeilen aus dem Content.
1132  
1133 =item -tag => $tag (Default: erstes Argument des Methodenaufrufs)
1134  
1135 Mit dieser Option kann der Tag verändert werden. Anwendungsfall:
1136 statt eigentlich beim Aufruf angegebenen td soll ein th-Tag
1137 gesetzt werden. Beispiel:
1138  
1139 $h->tag('td',
1140 -tag => 'th',
1141 ...
1142 );
1143  
1144 Siehe: Quiq::Html::Table::Simple
1145  
1146 =item -tagWrap => $n (Default: 0)
1147  
1148 Brich eine Tag-Zeile um, wenn sie $n Zeichen überschreitet. Wenn 0,
1149 findet kein Umbruch statt. Diese Option ist nützlich, wenn ein Tag lange
1150 Attribute haben kann und dies stört (siehe <embed> in
1151 R1::YouTube::Player).
1152  
1153 =item -text => $bool (Default: 0)
1154  
1155 Behandele den Content als Text, d.h. schütze &, < und >.
1156  
1157 =back
1158  
1159 =head4 Description
1160  
1161 Generiere HTML-Tag $tag gemäß den Optionen und Attributen @keyVal
1162 und dem Inhalt $content und liefere das Resultat zurück [2].
1163 Der Inhalt kann auch fehlen [1] oder sich über mehrere Argumente
1164 erstrecken [3].
1165  
1166 B<Attribut style>
1167  
1168 Als Wert des Attributs C<style> kann eine Array-Referenz mit
1169 CSS-Regeln angegeben werden. Diese werden von der
1170 Methode Quiq::Css->rules() aufgelöst.
1171  
1172 B<Boolsche Attribute>
1173  
1174 Boolsche Attribute werden in HTML ohne Wert und in XHTML mit sich
1175 selbst als Wert generiert.
1176  
1177 HTML
1178  
1179 <TAG ... ATTRIBUTE ...>
1180  
1181 XHTML
1182  
1183 <TAG ... ATTRIBUTE="ATTRIBUTE" ...>
1184  
1185 Boolsche Attribute sind:
1186  
1187 checked
1188 declare
1189 defer
1190 disabled
1191 ismap
1192 multiple
1193 nohref
1194 noresize
1195 readonly
1196 selected
1197  
1198 B<Default-Attribute>
1199  
1200 Für einige Elemente sind Default-Attribute vereinbart, die nicht
1201 explizit gesetzt werden müssen.
1202  
1203 Element Attribute
1204
1205 form method => 'post', enctype => 'multipart/form-data'
1206 script type => 'text/javascript'
1207 style type => 'text/css'
1208  
1209 =cut
1210  
1211 # -----------------------------------------------------------------------------
1212  
1213 # Setze Formatiereigenschaften
1214 # FIXME: Das Bündel *aller* Eigenschaften setzen, da eine Umschaltung
1215 # zwischen beliebigen Status vorkommen kann.
1216  
1217 268 ▶my $setFmtDefaults = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
1218 268 my ($fmt,$fmtR,$indR,$endTagR,$nlR) = @_;
1219  
1220 268 $$fmtR = $fmt;
1221 268 ▶ if ($fmt eq 'i') {
Branch: 5 branches
BranchTrueFalseTotal
if ($fmt eq 'i') { } 12 256 268
elsif ($fmt eq 'e') { } 41 215 256
elsif ($fmt eq 'E') { } 1 214 215
elsif ($fmt eq 'M') { } 18 196 214
elsif ($fmt eq 'v') { } 93 103 196
1222 12 $$nlR = 0;
1223 }
1224 elsif ($fmt eq 'e') {
1225 41 $$endTagR = 0;
1226 41 $$nlR = 1;
1227 }
1228 elsif ($fmt eq 'E') {
1229 1 $$fmtR = 'e';
1230 1 $$endTagR = 0;
1231 1 $$nlR = 0;
1232 }
1233 elsif ($fmt eq 'M') {
1234 18 $$fmtR = 'm';
1235 18 $$indR = 0;
1236 }
1237 elsif ($fmt eq 'v') {
1238 93 $$nlR = 1;
1239 }
1240  
1241 268 return;
1242 36 };
1243  
1244 261 ▶sub tag {
Subroutine tag: called CC=116 SCAR=60.2
Pod documented
1245 261 my $self = shift;
1246 261 my $tag = shift;
1247  
1248 # Defaults
1249  
1250 261 my ($xhtml,$html5);
1251 261 my $htmlVersion = $self->{'htmlVersion'};
1252 261 ▶ if ($htmlVersion =~ /^html-5/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($htmlVersion =~ /^html-5/) { } 217 44 261
elsif ($htmlVersion =~ /^xhtml/) { } 16 28 44
1253 217 $html5 = 1;
1254 }
1255 elsif ($htmlVersion =~ /^xhtml/) {
1256 16 $xhtml = 1;
1257 }
1258  
1259 261 ▶ my $uppercase = $self->{'uppercase'} && !($xhtml || $html5);
Condition16%1/6
$self->{'uppercase'} && !($xhtml || $html5)
!ll&&!rl&&r
26100
$xhtml || $html5
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{'uppercase'} && !($xhtml || $html5)
$self->{'uppercase'} $xhtml $html5
Truth table25%1/4
A && not(B || C)
A= $self->{'uppercase'}B= $xhtmlC= $html5
ABCresult
0XX0
11X0
1010
1001
1260 261 my $embedImage = $self->{'embedImages'};
1261 261 my $checkLevel = $self->{'checkLevel'};
1262 261 my $compact = $self->{'compact'};
1263 261 my $oneLineJs = $self->{'oneLineJs'};
1264 261 my $oneLineCss = $self->{'oneLineCss'};
1265 261 my $contentInd = undef;
1266 261 my $fmt = 'm';
1267 261 my $nl = 1;
1268 261 my $ind = 2;
1269 261 my $indPos = 0;
1270 261 my $indTag = 0;
1271 261 my $endTag = 1;
1272 261 my $endTagOnly = 0;
1273 261 my $ignoreIfNull = 0;
1274 261 my $ignoreTagIf = 0;
1275 261 my $oneLine = 0;
1276 261 my $tagWrap = 0;
1277 261 my $remComments = 0;
1278 261 my $remNl = 0;
1279 261 my $text = 0;
1280 261 my $placeholders = undef;
1281  
1282 # Tag-spezifische Defaults
1283  
1284 261 ▶ if ($tag eq 'style' || $tag eq 'script') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "style" or $tag eq "script") 32 229 261
Condition100%3/3
$tag eq "style" or $tag eq "script"
l!l&&r!l&&!r
1616229
MC/DC100%2/2
$tag eq "style" or $tag eq "script"
$tag eq "style" $tag eq "script"
Truth table100%3/3
A or B
A= $tag eq "style"B= $tag eq "script"
ABresult
1X1
011
000
1285 32 $remComments = 1;
1286 32 $remNl = 1;
1287 32 $contentInd = 2;
1288 }
1289
1290 # Element-Lookup -> elementspezifische Defaults
1291 # Bei -checkLevel=>0 muss $tag nicht existieren
1292  
1293 261 my $e = $Element{$tag};
1294 261 ▶ if ($e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 256 5 261
1295 256 $setFmtDefaults->($e,\$fmt,\$ind,\$endTag,\$nl);
1296 }
1297  
1298 # Default-Attribute ermitteln (z.B. type="text/css" bei style)
1299  
1300 261 my (@defAttr,%seenAttr);
1301 261 ▶ if (my $arr = $DefaultAttributes{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arr = $DefaultAttributes{$tag}) 33 228 261
1302 33 push @defAttr,@$arr;
1303 }
1304 261 ▶ if ($xhtml && (my $arr = $DefaultAttributesXhtml{$tag})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xhtml and my $arr = $DefaultAttributesXhtml{$tag}) 2 259 261
Condition100%3/3
$xhtml and my $arr = $DefaultAttributesXhtml{$tag}
!ll&&!rl&&r
245142
MC/DC100%2/2
$xhtml and my $arr = $DefaultAttributesXhtml{$tag}
$xhtml my $arr = $DefaultAttributesXhtml{$tag}
Truth table100%3/3
A and B
A= $xhtmlB= my $arr = $DefaultAttributesXhtml{$tag}
ABresult
0X0
100
111
1305 2 push @defAttr,@$arr;
1306 }
1307  
1308 # BUG: funktioniert nicht, da spezifizierte Defaultattribute dann
1309 # mehrfach auftreten
1310 # if (my $arr = $DefaultAttributes{$tag}) {
1311 # unshift @_,@$arr;
1312 # }
1313 # if ($xhtml && (my $arr = $DefaultAttributesXhtml{$tag})) {
1314 # unshift @_,@$arr;
1315 # }
1316  
1317 # Tagbezeichner wandeln
1318 261 ▶ my $tagStr = $uppercase? uc $tag: $tag;
Branch: 1 branch
BranchTrueFalseTotal
$uppercase ? : 0 261 261
1319  
1320 # Tag generieren
1321  
1322 261 my $str = '';
1323  
1324 # Optionen und Attribute verarbeiten
1325  
1326 261 ▶ if (my $arr = $DefaultOptions{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arr = $DefaultOptions{$tag}) 16 245 261
1327 16 unshift @_,@$arr;
1328 }
1329  
1330 261 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 821 55 876
1331 821 ▶ if (@_ == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1) { } 161 660 821
elsif (defined $_[0] and $_[0] eq '-') { } 39 621 660
elsif (ref $_[0]) { } 3 618 621
1332 # Letztes Argument ist Content. Dieser Test muss als erstes
1333 # kommen, damit '-' als Content nicht unter den Tisch fällt.
1334 161 last;
1335 }
1336 ▶ elsif (defined $_[0] && $_[0] eq '-') {
Condition66%2/3
defined $_[0] and $_[0] eq "-"
!ll&&!rl&&r
062139
MC/DC50%1/2
defined $_[0] and $_[0] eq "-"
defined $_[0] $_[0] eq "-"
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] eq "-"
ABresult
0X0
100
111
1337 # explizites Ende der Options- und Attributliste
1338 39 shift; # '-' konsumieren
1339 39 last;
1340 }
1341 elsif (ref $_[0]) {
1342 # Argument ist (Array-)Referenz
1343 3 last;
1344 }
1345  
1346 618 my $key = shift;
1347 618 my $val = shift;
1348  
1349 618 ▶ if (substr($key,0,1) eq '-') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($key, 0, 1) eq '-') { } 123 495 618
elsif ($key eq 'data' and builtin::reftype($val)) { } 7 976 983
1350 # FIXME: Fallunterscheidungen durch Hash-Lookup ersetzen
1351
1352 123 ▶ if ($key eq '-nl') {
Branch: 19 branches
BranchTrueFalseTotal
if ($key eq '-nl') { } 20 103 123
elsif ($key eq '-fmt') { } 12 91 103
elsif ($key eq '-ind') { } 8 83 91
elsif ($key eq '-indTag') { } 0 83 83
elsif ($key eq '-indPos') { } 3 80 83
elsif ($key eq '-ignoreIf') { } 8 72 80
elsif ($key eq '-ignoreIfNull') { } 33 39 72
elsif ($key eq '-ignoreTagIf') { } 13 26 39
elsif ($key eq '-checkLevel') { } 5 21 26
elsif ($key eq '-tagWrap') { } 0 21 21
elsif ($key eq '-text') { } 21 0 21
elsif ($key eq '-endTagOnly') { } 0 0 0
elsif ($key eq '-embedImage') { } 0 0 0
elsif ($key eq '-contentInd') { } 0 0 0
elsif ($key eq '-remComments') { } 0 0 0
elsif ($key eq '-remNl') { } 0 0 0
elsif ($key eq '-compact') { } 0 0 0
elsif ($key eq '-placeholders') { } 0 0 0
elsif ($key eq '-tag') { } 0 0 0
1353 20 $nl = $val;
1354 }
1355 elsif ($key eq '-fmt') {
1356 12 $setFmtDefaults->($val,\$fmt,\$ind,\$endTag,\$nl);
1357 }
1358 elsif ($key eq '-ind') {
1359 8 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 8 0 8
1360 8 $ind = $val;
1361 }
1362 }
1363 elsif ($key eq '-indTag') {
1364 0 $indTag = $val;
1365 }
1366 elsif ($key eq '-indPos') {
1367 3 $indPos = $val;
1368 }
1369 elsif ($key eq '-ignoreIf') {
1370 # sofortiger Abbruch
1371 8 ▶ return '' if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 3 5 8
1372 }
1373 elsif ($key eq '-ignoreIfNull') {
1374 33 $ignoreIfNull = $val;
1375 }
1376 elsif ($key eq '-ignoreTagIf') {
1377 13 $ignoreTagIf = $val;
1378 }
1379 elsif ($key eq '-checkLevel') {
1380 5 $checkLevel = $val;
1381 }
1382 elsif ($key eq '-tagWrap') {
1383 0 $tagWrap = $val;
1384 }
1385 elsif ($key eq '-text') {
1386 21 $text = $val;
1387 }
1388 elsif ($key eq '-endTagOnly') {
1389 0 $endTagOnly = $val;
1390 }
1391 elsif ($key eq '-embedImage') {
1392 0 $embedImage = $val;
1393 }
1394 elsif ($key eq '-contentInd') {
1395 0 $contentInd = $val;
1396 }
1397 elsif ($key eq '-remComments') {
1398 0 $remComments = $val;
1399 }
1400 elsif ($key eq '-remNl') {
1401 0 $remNl = $val;
1402 }
1403 elsif ($key eq '-compact') {
1404 0 $compact = $val;
1405 }
1406 elsif ($key eq '-placeholders') {
1407 0 $placeholders = $val;
1408 }
1409 elsif ($key eq '-tag') {
1410 0 ▶ if (defined($val) && $val ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val ne "") 0 0 0
Condition0%0/3
defined $val and $val ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val ne ""
defined $val $val ne ""
Truth table0%0/3
A and B
A= defined $valB= $val ne ""
ABresult
0X0
100
111
1411 0 $tag = $val;
1412 0 ▶ $tagStr = $uppercase? uc $tag: $tag;
Branch: 1 branch
BranchTrueFalseTotal
$uppercase ? : 0 0 0
1413 }
1414 }
1415 else {
1416 0 $self->throw(
1417 'HTML-00001: Unbekannte Option',
1418 Option => $key,
1419 Value => $val,
1420 );
1421 }
1422 120 next;
1423 }
1424 ▶ elsif ($key eq 'data' && Scalar::Util::reftype($val)) {
Condition66%2/3
$key eq "data" and builtin::reftype($val)
!ll&&!rl&&r
48807
MC/DC50%1/2
$key eq "data" and builtin::reftype($val)
$key eq "data" builtin::reftype($val)
Truth table66%2/3
A and B
A= $key eq "data"B= builtin::reftype($val)
ABresult
0X0
100
111
1425 # data-* Attribute als Liste data=>\@keyVal
1426
1427 7 my @keyVal;
1428 7 ▶ for (my $i = @$val-2; $i >= 0; $i -= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 4 7 11
1429 4 unshift @_,'data-'.$val->[$i],$val->[$i+1];
1430 }
1431 7 next;
1432 }
1433
1434 488 ▶ if ($endTagOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($endTagOnly) 0 488 488
1435 0 $self->throw(
1436 'HTML-00004: Attribute bei Option -endTagOnly nicht erlaubt',
1437 Tag => $tag,
1438 Attribute => $key,
1439 Value => $val,
1440 );
1441 }
1442  
1443 # Attribut-Lookup. Attribut data-* ist generell erlaubt.
1444  
1445 488 ▶ my $dom = $Attribute{$key} || '';
Condition100%2/2
$Attribute{$key} || ''
l!l
4817
MC/DC100%1/1
$Attribute{$key} || ''
$Attribute{$key}
Truth table100%2/2
A
A= $Attribute{$key}
Aresult
11
00
1446 488 ▶ if (!$dom && $checkLevel && $key !~ /^data-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dom and $checkLevel and not $key =~ /^data-/) 0 488 488
Condition66%4/6
not $dom and $checkLevel and not $key =~ /^data-/
!ll&&!rl&&r
48170
not $dom and $checkLevel
!ll&&!rl&&r
48107
MC/DC0%0/3
not $dom and $checkLevel and not $key =~ /^data-/
not $dom $checkLevel not $key =~ /^data-/
Truth table50%2/4
not(A) and B and not(C)
A= not $domB= $checkLevelC= not $key =~ /^data-/
ABCresult
0XX0
10X0
1100
1111
1447 0 $self->throw(
1448 'HTML-00003: Unbekanntes Attribut',
1449 Tag => $tag,
1450 Attribute => $key,
1451 Value => $val,
1452 );
1453 }
1454  
1455 # Attribut/Wert-Paar
1456  
1457 488 ▶ if ($key eq 'style' && ref($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "style" and ref $val) 1 487 488
Condition100%3/3
$key eq "style" and ref $val
!ll&&!rl&&r
445421
MC/DC100%2/2
$key eq "style" and ref $val
$key eq "style" ref $val
Truth table100%3/3
A and B
A= $key eq "style"B= ref $val
ABresult
0X0
100
111
1458 # liefert undef, wenn Array leer ist
1459 1 $val = Quiq::Css->properties(@$val);
1460 }
1461 488 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 265 223 488
1462 265 ▶ if ($checkLevel >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checkLevel >= 2) 0 265 265
1463 0 $self->checkValue($dom,$val);
1464 }
1465  
1466 265 ▶ if ($tag eq 'img' && $key eq 'src') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'img' and $key eq 'src') { } 1 264 265
Condition100%3/3
$tag eq "img" and $key eq "src"
!ll&&!rl&&r
26221
MC/DC100%2/2
$tag eq "img" and $key eq "src"
$tag eq "img" $key eq "src"
Truth table100%3/3
A and B
A= $tag eq "img"B= $key eq "src"
ABresult
0X0
100
111
1467 1 $val = $self->imgSrcValue($val,$embedImage);
1468 }
1469 else {
1470 264 $val =~ s/"/&quot;/g; # FIXME: auf best. Domänen einschränken
1471 }
1472  
1473 265 ▶ $key = uc $key if $uppercase;
Branch: 1 branch
BranchTrueFalseTotal
if $uppercase 0 265 265
1474  
1475 265 ▶ if ($dom eq 'bool') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dom eq 'bool') { } 52 213 265
1476 52 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 3 49 52
1477 3 ▶ $str .= $xhtml || $html5? qq| $key="$key"|: " $key";
Branch: 1 branch
BranchTrueFalseTotal
$xhtml || $html5 ? : 0 3 3
Condition33%1/3
$xhtml or $html5
l!l&&r!l&&!r
003
MC/DC0%0/2
$xhtml or $html5
$xhtml $html5
Truth table33%1/3
A or B
A= $xhtmlB= $html5
ABresult
1X1
011
000
1478 }
1479 }
1480 else {
1481 213 $str .= qq| $key="$val"|;
1482 }
1483  
1484 # Gesetzte Attribute merken, falls wir Defaultattribute haben
1485  
1486 265 ▶ if (@defAttr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@defAttr) 17 248 265
1487 17 $seenAttr{$key}++;
1488 }
1489 }
1490 }
1491  
1492 # Defaultattribute hinzufügen, die nicht gesetzt wurden
1493  
1494 258 ▶ if (@defAttr && !$endTagOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if (@defAttr and not $endTagOnly) 35 223 258
Condition66%2/3
@defAttr and not $endTagOnly
!ll&&!rl&&r
223035
MC/DC50%1/2
@defAttr and not $endTagOnly
@defAttr not $endTagOnly
Truth table66%2/3
A and not(B)
A= @defAttrB= not $endTagOnly
ABresult
0X0
100
111
1495 35 ▶ for (my $i = 0; $i < @defAttr; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @defAttr) 35 35 70
1496 35 ▶ if (!$seenAttr{$defAttr[$i]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seenAttr{$defAttr[$i]}) 29 6 35
1497 29 $str .= sprintf ' %s="%s"',$defAttr[$i],$defAttr[$i+1];
1498 }
1499 }
1500 }
1501  
1502 # Attribute für kompakte Darstellung einstellen
1503  
1504 258 ▶ if ($compact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compact) 0 258 258
1505 0 ▶ if (lc($fmt) ne 'p') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $fmt ne "p") 0 0 0
1506 0 $fmt = 'i';
1507 }
1508 0 $ind = 0;
1509 0 $nl = 0;
1510 0 $remComments = 1;
1511 }
1512  
1513 258 ▶ if (!$endTagOnly) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($endTagOnly) 258 0 258
1514 258 $str = "<$tagStr$str";
1515 }
1516  
1517 # Tag umbrechen
1518  
1519 258 ▶ if ($tagWrap && length($str) > $tagWrap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagWrap and length $str > $tagWrap) 0 258 258
Condition33%1/3
$tagWrap and length $str > $tagWrap
!ll&&!rl&&r
25800
MC/DC0%0/2
$tagWrap and length $str > $tagWrap
$tagWrap length $str > $tagWrap
Truth table33%1/3
A and B
A= $tagWrapB= length $str > $tagWrap
ABresult
0X0
100
111
1520 0 $str = $self->wrapTag($tagWrap,$str);
1521 }
1522  
1523 # Element prüfen
1524  
1525 258 ▶ if (!$e && $checkLevel) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $e and $checkLevel) 0 258 258
Condition66%2/3
not $e and $checkLevel
!ll&&!rl&&r
25350
MC/DC0%0/2
not $e and $checkLevel
not $e $checkLevel
Truth table66%2/3
not(A) and B
A= not $eB= $checkLevel
ABresult
0X0
100
111
1526 0 $self->throw('HTML-00002: Unbekanntes Element',Element=>$tag);
1527 }
1528  
1529 # Content bestimmen
1530 258 my $content = $self->cat(@_);
1531  
1532 # Klauseln auswerten, die auf den Content Bezug nehmen
1533  
1534 258 ▶ if ($ignoreIfNull && (!defined $content || $content eq '')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ignoreIfNull and !defined($content) || $content eq "") 14 244 258
Condition83%5/6
$ignoreIfNull and !defined($content) || $content eq ""
!ll&&!rl&&r
2251914
not defined $content or $content eq ""
l!l&&r!l&&!r
01419
MC/DC66%2/3
$ignoreIfNull and !defined($content) || $content eq ""
$ignoreIfNull not defined $content $content eq ""
Truth table75%3/4
A and not(B) or C
A= $ignoreIfNullB= not defined $contentC= $content eq ""
ABCresult
0XX0
1000
11X1
1011
1535 14 return '';
1536 }
1537  
1538 244 ▶ if ($placeholders) {
Branch: 1 branch
BranchTrueFalseTotal
if ($placeholders) 0 244 244
1539 # Platzhalter ersetzen
1540  
1541 0 my $tpl = Quiq::Template->new('text',\$content);
1542 0 $tpl->replace(@$placeholders);
1543 0 $content = $tpl->asStringNL;
1544 }
1545 244 ▶ if ($text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text) 19 225 244
1546 # Content ist Text, wir schützen &, <, >
1547  
1548 19 $content =~ s/&/&amp;/g;
1549 19 $content =~ s/</&lt;/g;
1550 19 $content =~ s/>/&gt;/g;
1551 }
1552 244 ▶ if ($remNl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remNl) 22 222 244
1553 22 $content =~ s/^(\s*)\n//mg;
1554 }
1555 244 ▶ if ($remComments) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remComments) 22 222 244
1556 22 ▶ if ($tag eq 'script') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'script') { } 15 7 22
elsif ($tag eq 'style') { } 7 0 7
1557 15 $content = Quiq::String->removeComments($content,'//');
1558 }
1559 elsif ($tag eq 'style') {
1560 7 $content = Quiq::String->removeComments($content,'/*','*/');
1561 }
1562 else { # HTML
1563 0 $content = Quiq::String->removeComments($content,'<!--','-->');
1564 }
1565 }
1566 244 ▶ if ($compact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compact) 0 244 244
1567 0 $content =~ s/^\s+//g;
1568 0 $content =~ s/\s+$//g;
1569  
1570 0 ▶ if ($tag eq 'script') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'script') { } 0 0 0
elsif ($tag eq 'style') { } 0 0 0
1571 0 $content =~ s/\n\s*/ /g; # Whitespace nur zwischen Zeilen kompr.
1572 }
1573 elsif ($tag eq 'style') {
1574 0 $content =~ s/\s+/ /g;
1575 }
1576 else { # HTML
1577 0 $content =~ s/\s+/ /g;
1578 }
1579 }
1580  
1581 244 ▶ if ($ignoreTagIf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ignoreTagIf) 11 233 244
1582 11 return $content;
1583 }
1584  
1585 # Content bearbeiten
1586  
1587 233 ▶ if ($fmt eq 'p' || $fmt eq 'P') {
Branch: 5 branches
BranchTrueFalseTotal
if ($fmt eq 'p' or $fmt eq 'P') { } 3 230 233
elsif ($fmt eq 's') { } 0 230 230
elsif ($fmt eq 'e' or $fmt eq 'E') { } 41 189 230
elsif ($fmt eq 'v' and not $content =~ /\n/ or $fmt eq 'i') { } 68 121 189
elsif ($fmt eq 'v' or $fmt eq 'm' or $fmt eq 'c') { } 121 0 121
Condition66%2/3
$fmt eq "p" or $fmt eq "P"
l!l&&r!l&&!r
30230
MC/DC50%1/2
$fmt eq "p" or $fmt eq "P"
$fmt eq "p" $fmt eq "P"
Truth table66%2/3
A or B
A= $fmt eq "p"B= $fmt eq "P"
ABresult
1X1
011
000
1588 3 ▶ Quiq::String->removeIndentation(\$content) if $fmt eq 'P';
Branch: 1 branch
BranchTrueFalseTotal
if $fmt eq "P" 0 3 3
1589 3 $content =~ s/\x0a/&#10;/g;
1590 3 $content =~ s/\x0d/&#13;/g;
1591 }
1592 elsif ($fmt eq 's') {
1593 # Inhalt einzeilig machen durch Whitespace-Manipulation
1594 0 $self->throw('Not implemented');
1595 }
1596 ▶ elsif ($fmt eq 'e' || $fmt eq 'E') {
Condition66%2/3
$fmt eq "e" or $fmt eq "E"
l!l&&r!l&&!r
410189
MC/DC50%1/2
$fmt eq "e" or $fmt eq "E"
$fmt eq "e" $fmt eq "E"
Truth table66%2/3
A or B
A= $fmt eq "e"B= $fmt eq "E"
ABresult
1X1
011
000
1597 41 ▶ if (length $content) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $content) 0 41 41
1598 0 $self->throw('HTML-00003: Kein Content erwartet');
1599 }
1600 }
1601 ▶ elsif ($fmt eq 'v' && $content !~ /\n/ || $fmt eq 'i') {
Condition100%6/6
$fmt eq "v" and not $content =~ /\n/ or $fmt eq "i"
l!l&&r!l&&!r
626121
$fmt eq "v" and not $content =~ /\n/
!ll&&!rl&&r
1111662
MC/DC100%3/3
$fmt eq "v" and not $content =~ /\n/ or $fmt eq "i"
$fmt eq "v" not $content =~ /\n/ $fmt eq "i"
Truth table80%4/5
A and not(B) or C
A= $fmt eq "v"B= not $content =~ /\n/C= $fmt eq "i"
ABCresult
11X1
0X11
1011
0X00
1000
1602 # nichts tun
1603 }
1604 ▶ elsif ($fmt eq 'v' || $fmt eq 'm' || $fmt eq 'c') {
Condition83%5/6
$fmt eq "v" or $fmt eq "m" or $fmt eq "c"
l!l&&r!l&&!r
106150
$fmt eq "v" or $fmt eq "m"
l!l&&r!l&&!r
169015
MC/DC0%0/3
$fmt eq "v" or $fmt eq "m" or $fmt eq "c"
$fmt eq "v" $fmt eq "m" $fmt eq "c"
Truth table75%3/4
A or B or C
A= $fmt eq "v"B= $fmt eq "m"C= $fmt eq "c"
ABCresult
1XX1
01X1
0011
0000
1605 121 Quiq::String->removeIndentation(\$content);
1606 121 ▶ if ($contentInd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contentInd) 22 99 121
1607 # Bringe Einrückung des Content auf Tiefe $contendInd
1608 22 Quiq::String->reduceIndentation($contentInd,\$content);
1609 }
1610 121 ▶ if ($fmt eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if ($fmt eq 'c') { } 15 106 121
elsif ($tag eq 'style' and $oneLineCss) { } 0 205 205
1611 15 ▶ if ($oneLineJs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oneLineJs) 0 15 15
1612 # mache JavaScript-Code einzeilig
1613 0 $content = Quiq::JavaScript->line($content);
1614 }
1615 15 ▶ if ($content =~ tr/&<>//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ tr/&<>//) 0 15 15
1616 # Script-Code in CDATA einfassen, wenn &, < oder > enthalten
1617 0 $content = "// <![CDATA[\n$content\n// ]]>";
1618 # Folgendes geht nicht!
1619 # $content =~ s/&/&amp;/g;
1620 # $content =~ s/</&lt;/g;
1621 }
1622 }
1623 ▶ elsif ($tag eq 'style' && $oneLineCss) {
Condition66%2/3
$tag eq "style" and $oneLineCss
!ll&&!rl&&r
9970
MC/DC0%0/2
$tag eq "style" and $oneLineCss
$tag eq "style" $oneLineCss
Truth table66%2/3
A and B
A= $tag eq "style"B= $oneLineCss
ABresult
0X0
100
111
1624 # mache CSS-Code einzeilig
1625 0 $content = Quiq::Css->oneLine($content);
1626 }
1627 121 ▶ if (defined(my $forceIndent = $self->{'indentation'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $forceIndent = $self->{"indentation"})) 8 113 121
1628 8 $ind = $forceIndent;
1629 }
1630 121 ▶ if ($ind) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ind) 102 19 121
1631 102 my $space = ' ' x $ind;
1632 102 $content =~ s/^(?!$)/$space/gm; # Nicht-Leerzeilen einrücken
1633 }
1634 # MEMO: Test auf 'c', damit 'script' mit src nicht mehrzeilig wird
1635 121 ▶ $content = $content? "\n$content\n": ''; # $fmt eq 'c'? '': "\n";
Branch: 1 branch
BranchTrueFalseTotal
$content ? : 102 19 121
1636 }
1637 else {
1638 0 $self->throw(
1639 'HTML-00002: Unerlaubter Wert für Option -fmt',
1640 Value => $fmt,
1641 );
1642 }
1643  
1644 # End-Tag
1645  
1646 233 ▶ if ($endTag || $content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($endTag or $content) { } 192 41 233
Condition66%2/3
$endTag or $content
l!l&&r!l&&!r
192041
MC/DC50%1/2
$endTag or $content
$endTag $content
Truth table66%2/3
A or B
A= $endTagB= $content
ABresult
1X1
011
000
1647 192 ▶ if ($endTagOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($endTagOnly) { } 0 192 192
1648 0 $content =~ s/^\n+//;
1649 } else {
1650 192 $str .= '>';
1651 }
1652 192 $str .= "$content</$tagStr>";
1653 }
1654 else {
1655 41 ▶ $str .= $xhtml || $html5? ' />': '>';
Branch: 1 branch
BranchTrueFalseTotal
$xhtml || $html5 ? : 31 10 41
Condition66%2/3
$xhtml or $html5
l!l&&r!l&&!r
03110
MC/DC50%1/2
$xhtml or $html5
$xhtml $html5
Truth table66%2/3
A or B
A= $xhtmlB= $html5
ABresult
1X1
011
000
1656 }
1657  
1658 233 ▶ if ($indPos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indPos) { } 0 233 233
1659 # Einrückung erzeugen
1660 0 my $space = ' ' x $indPos;
1661 0 $str =~ s/^(?!$)/$space/gm; # Nicht-Leerzeilen einrücken
1662 # Einrückung erste Zeile entfernen
1663 0 $str =~ s/^$space//;
1664 }
1665 else {
1666 # NEWLINE
1667 233 $str .= "\n" x $nl;
1668 }
1669  
1670 233 ▶ if ($indTag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indTag) 0 233 233
1671 # Einrückung erzeugen
1672 0 my $space = ' ' x $indTag;
1673 0 $str =~ s/^(?!$)/$space/gm; # Nicht-Leerzeilen einrücken
1674 }
1675  
1676 233 return $str;
1677 }
1678  
1679 # -----------------------------------------------------------------------------
1680  
1681 =head3 wrapTag() - Umbreche langen Tag-String
1682  
1683 =head4 Synopsis
1684  
1685 $str = $this->wrapTag($maxWidth,$str);
1686  
1687 =cut
1688  
1689 # -----------------------------------------------------------------------------
1690  
1691 1 ▶sub wrapTag {
Subroutine wrapTag: called CC=6 SCAR=17.9
Pod documented
1692 1 my ($this,$max,$tag) = @_;
1693  
1694 1 my $str = '';
1695 1 my $tmp = '';
1696 1 for my $val (split / (?=\w+=".*?")/,$tag) {
1697 7 my $l = length $val;
1698 7 ▶ if (length($tmp)+length($val) <= $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($tmp) + length($val) <= $max) { } 5 2 7
1699 5 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 4 1 5
1700 4 $tmp .= ' ';
1701 }
1702 5 $tmp .= $val;
1703 }
1704 else {
1705 2 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 1 1 2
1706 1 $str .= "\n ";
1707 }
1708 2 $str .= $tmp;
1709 2 $tmp = $val;
1710 }
1711 }
1712 1 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 1 0 1
1713 1 $str .= "\n $tmp";
1714 }
1715  
1716 1 return $str;
1717 }
1718  
1719 # -----------------------------------------------------------------------------
1720  
1721 =head3 cat() - Füge HTML-Fragmente zusammen
1722  
1723 =head4 Synopsis
1724  
1725 $html = $h->cat(@opt,@args);
1726  
1727 =head4 Options
1728  
1729 =over 4
1730  
1731 =item -join => $str (Default: '')
1732  
1733 Verwende $str als Trenner zwischen den Fragmenten. Diese Option
1734 ist praktisch, wenn die Fragmente optional sind und die
1735 auftretenden Elemente durch eine Zeichenkette voneinander getrennt
1736 werden sollen. Beispiel: Eine Icon-Leiste, deren Zusammensetzung
1737 nicht festgelegt ist und die nicht direkt aneinander stoßen
1738 sollen, sondern durch Leerzeichen getrennt werden.
1739  
1740 =item -placeholders => \@keyVal (Default: undef)
1741  
1742 Ersetze im generierten HTML-Code die angegebenen Platzhalter durch
1743 ihre Werte.
1744  
1745 =back
1746  
1747 =head4 Description
1748  
1749 Füge die HTML-Fragmente @args zusammen und liefere den
1750 resultierenden HTML-Code zurück.
1751  
1752 @args ist eine Abfolge von Array-Referenzen und/oder Zeichenketten.
1753  
1754 Der Aufruf
1755  
1756 $h->cat(
1757 ['doctype'],
1758 ['comment',-nl=>2,'Copyright Lieschen Müller'],
1759 ['HTML',
1760 ['HEAD',
1761 ['TITLE','Meine Homepage'],
1762 ['STYLE',q|
1763 .text { color: red; }
1764 |],
1765 ],
1766 ['BODY',
1767 ['H1','Hallo Welt!'],
1768 ['P',class=>'text',q|
1769 Ich heiße Lieschen Müller und dies
1770 ist meine Homepage.
1771 |],
1772 ],
1773 ]
1774 );
1775  
1776 ist äquivalent zu
1777  
1778 $h->cat(
1779 $h->doctype,
1780 $h->comment(-nl=>2,'Copyright Lieschen Müller'),
1781 $h->tag('html','-',
1782 $h->tag('head','-',
1783 $h->tag('title','Meine Homepage'),
1784 $h->tag('style',q|
1785 .text { color: red; }
1786 |),
1787 ),
1788 $h->tag('body','-',
1789 $h->tag('h1','Hallo Welt!'),
1790 $h->tag('p',class=>'text',q|
1791 Ich heiße Lieschen Müller und dies
1792 ist meine Homepage.
1793 |),
1794 ),
1795 ),
1796 );
1797  
1798 Beide liefern
1799  
1800 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
1801 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1802
1803 <!-- Copyright Lieschen Müller -->
1804
1805 <html xmlns="http://www.w3.org/1999/xhtml">
1806 <head>
1807 <title>Meine Homepage</title>
1808 <style type="text/css">
1809 .text { color: red; }
1810 </style>
1811 </head>
1812 <body>
1813 <h1>Hallo Welt!</h1>
1814 <p class="text">
1815 Ich heiße Lieschen Müller und dies
1816 ist meine Homepage.
1817 </p>
1818 </body>
1819 </html>
1820  
1821 =cut
1822  
1823 # -----------------------------------------------------------------------------
1824  
1825 290 ▶sub cat {
Subroutine cat: called CC=13 SCAR=30.8
Pod documented
1826 290 my $self = shift;
1827  
1828 # Optionen
1829  
1830 290 my $join = '';
1831 290 my $placeholders = undef;
1832  
1833 290 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 234 56 290
1834 234 ▶ if (!defined($_[0]) || substr($_[0],0,1) ne '-') {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $_[0] or substr($_[0], 0, 1) ne '-') { } 234 0 234
elsif ($_[0] eq '-') { } 0 0 0
elsif ($_[0] eq '-join') { } 0 0 0
elsif ($_[0] eq '-placeholders') { } 0 0 0
Condition66%2/3
not defined $_[0] or substr($_[0], 0, 1) ne "-"
l!l&&r!l&&!r
72270
MC/DC0%0/2
not defined $_[0] or substr($_[0], 0, 1) ne "-"
not defined $_[0] substr($_[0], 0, 1) ne "-"
Truth table66%2/3
not(A) or B
A= not defined $_[0]B= substr($_[0], 0, 1) ne "-"
ABresult
1X1
011
000
1835 # Ende der Optionen
1836 234 last;
1837 }
1838 elsif ($_[0] eq '-') {
1839 # explizites Ende der Options-Liste
1840 0 shift; # '-' konsumieren
1841 0 last;
1842 }
1843 elsif ($_[0] eq '-join') {
1844 0 $join = splice @_,0,2;
1845 0 next;
1846 }
1847 elsif ($_[0] eq '-placeholders') {
1848 0 $placeholders = splice @_,0,2;
1849 0 next;
1850 }
1851 #else {
1852 # $self->throw(
1853 # 'HTML-00002: Unbekannte Option',
1854 # Option=>$_[0],
1855 # );
1856 #}
1857 0 last;
1858 }
1859  
1860 # Werte ermitteln und konkatenieren
1861  
1862 290 my @arr;
1863 290 for my $e (@_) {
1864 317 ▶ if (ref $e) { # Argument ist (Array-)Referenz
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e) { } 9 308 317
1865 9 ▶ if ($e->[0] =~ /^[[:upper:]]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->[0] =~ /^[[:upper:]]/) { } 7 2 9
1866 # Namen beginnt mit Großbuchstaben -> Tag
1867 7 push @arr,$self->tag(lc $e->[0],@$e[1..$#$e]);
1868 }
1869 else {
1870 # Kleinbuchstabe -> Methode
1871 2 my $meth = $e->[0];
1872 2 push @arr,$self->$meth(@$e[1..$#$e]);
1873 }
1874 }
1875 else {
1876 308 ▶ push @arr,defined($e) && $e ne ''? $e: ();
Branch: 1 branch
BranchTrueFalseTotal
defined $e && $e ne '' ? : 235 73 308
Condition100%3/3
defined $e and $e ne ""
!ll&&!rl&&r
1063235
MC/DC100%2/2
defined $e and $e ne ""
defined $e $e ne ""
Truth table100%3/3
A and B
A= defined $eB= $e ne ""
ABresult
0X0
100
111
1877 }
1878 }
1879 290 my $html = join $join,@arr;
1880  
1881 # Platzhalter ersetzen
1882  
1883 290 ▶ if ($placeholders) {
Branch: 1 branch
BranchTrueFalseTotal
if ($placeholders) 0 290 290
1884 0 my $tpl = Quiq::Template->new('text',\$html);
1885 0 $tpl->replace(@$placeholders);
1886 0 $html = $tpl->asStringNL;
1887 }
1888  
1889 290 return $html;
1890 }
1891  
1892 # -----------------------------------------------------------------------------
1893  
1894 =head3 doctype() - <!DOCTYPE>-Tag
1895  
1896 =head4 Synopsis
1897  
1898 $str = $h->doctype(@opt);
1899  
1900 =head4 Options
1901  
1902 =over 4
1903  
1904 =item -frameset => $bool (Default: 0)
1905  
1906 Liefere Frameset-Doctype.
1907  
1908 =item -nl => $n (Default: 2)
1909  
1910 Ergänze Doctype um $n Zeilenumbrüche.
1911  
1912 =back
1913  
1914 =head4 Description
1915  
1916 Liefere <!DOCTYPE>-Tag:
1917  
1918 <!DOCTYPE ...>
1919  
1920 Der Tag ergibt sich aus der eingestellten HTML-Variante.
1921  
1922 =cut
1923  
1924 # -----------------------------------------------------------------------------
1925  
1926 12 ▶sub doctype {
Subroutine doctype: called CC=16 SCAR=29.2
Pod documented
1927 12 my $self = shift;
1928  
1929 12 my $compact = $self->{'compact'};
1930 12 my $frameset = 0;
1931 12 my $nl = 2;
1932  
1933 12 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 12 13
1934 1 my $key = shift;
1935  
1936 1 ▶ if ($key eq '-compact') {
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq '-compact') { } 0 1 1
elsif ($key eq '-frameset') { } 1 0 1
elsif ($key eq '-nl') { } 0 0 0
1937 0 $compact = shift;
1938 }
1939 elsif ($key eq '-frameset') {
1940 1 $frameset = shift;
1941 }
1942 elsif ($key eq '-nl') {
1943 0 $nl = shift;
1944 }
1945 else {
1946 0 $self->throw(
1947 'HTML-00001: Unbekannte Option',
1948 Option => $key,
1949 Value => shift,
1950 );
1951 }
1952 }
1953  
1954 12 ▶ if ($compact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compact) 0 12 12
1955 0 $nl = 0;
1956 }
1957  
1958 12 my $version = $self->{'htmlVersion'};
1959  
1960 12 my $str;
1961 12 ▶ if ($version eq 'xhtml-1.0' && !$frameset) {
Branch: 4 branches
BranchTrueFalseTotal
if ($version eq 'xhtml-1.0' and not $frameset) { } 3 9 12
elsif ($version eq 'xhtml-1.0' and $frameset) { } 1 8 9
elsif ($version eq 'html-4.01' and not $frameset) { } 1 7 8
elsif ($version eq 'html-5') { } 6 1 7
Condition100%3/3
$version eq "xhtml-1.0" and not $frameset
!ll&&!rl&&r
813
MC/DC100%2/2
$version eq "xhtml-1.0" and not $frameset
$version eq "xhtml-1.0" not $frameset
Truth table100%3/3
A and not(B)
A= $version eq "xhtml-1.0"B= not $frameset
ABresult
0X0
100
111
1962 3 $str = q|<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"|;
1963 3 ▶ if (!$compact) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compact) 3 0 3
1964 3 $str .= "\n ";
1965 }
1966 3 $str .= q| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">|;
1967 }
1968 ▶ elsif ($version eq 'xhtml-1.0' && $frameset) {
Condition66%2/3
$version eq "xhtml-1.0" and $frameset
!ll&&!rl&&r
801
MC/DC50%1/2
$version eq "xhtml-1.0" and $frameset
$version eq "xhtml-1.0" $frameset
Truth table66%2/3
A and B
A= $version eq "xhtml-1.0"B= $frameset
ABresult
0X0
100
111
1969 1 $str = q|<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"|;
1970 1 ▶ if (!$compact) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compact) 1 0 1
1971 1 $str .= "\n ";
1972 }
1973 1 $str .= q| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">|;
1974 }
1975 ▶ elsif ($version eq 'html-4.01' && !$frameset) {
Condition66%2/3
$version eq "html-4.01" and not $frameset
!ll&&!rl&&r
701
MC/DC50%1/2
$version eq "html-4.01" and not $frameset
$version eq "html-4.01" not $frameset
Truth table66%2/3
A and not(B)
A= $version eq "html-4.01"B= not $frameset
ABresult
0X0
100
111
1976 1 $str = q|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01|;
1977 1 ▶ if (!$compact) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compact) 1 0 1
1978 1 $str .= "\n ";
1979 }
1980 1 $str .= q| Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">|;
1981 }
1982 elsif ($version eq 'html-5') { # && !$frameset) {
1983 6 $str = q|<!DOCTYPE html>|;
1984 }
1985 else {
1986 1 $self->throw(
1987 'HTML-00002: Unbekannte HTML-Version',
1988 Version => "'$version'",
1989 );
1990 }
1991  
1992 11 $str .= "\n" x $nl;
1993
1994 11 return $str;
1995 }
1996  
1997 # -----------------------------------------------------------------------------
1998  
1999 =head3 comment() - Kommentar-Tag
2000  
2001 =head4 Synopsis
2002  
2003 $html = $h->comment(@keyVal,$content);
2004  
2005 =head4 Options
2006  
2007 Wie Methode tag()
2008  
2009 =head4 Description
2010  
2011 Liefere HTML Kommentar-Tag:
2012  
2013 <!-- TEXT -->
2014  
2015 bzw.
2016  
2017 <!--
2018 TEXT
2019 -->
2020  
2021 wenn TEXT mehrzeilig ist.
2022  
2023 =cut
2024  
2025 # -----------------------------------------------------------------------------
2026  
2027 10 ▶sub comment {
Subroutine comment: called CC=5 SCAR=16.1
Pod documented
2028 10 my $self = shift;
2029 10 ▶ return '' if !defined $_[-1] || $_[-1] eq ''; # kein Kommentar, wenn leer
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[-1] or $_[-1] eq "" 5 5 10
Condition66%2/3
not defined $_[-1] or $_[-1] eq ""
l!l&&r!l&&!r
505
MC/DC50%1/2
not defined $_[-1] or $_[-1] eq ""
not defined $_[-1] $_[-1] eq ""
Truth table66%2/3
not(A) or B
A= not defined $_[-1]B= $_[-1] eq ""
ABresult
1X1
011
000
2030 5 my $str = $self->tag('COMMENT',-checkLevel=>0,-fmt=>'v',@_);
2031 5 ▶ $str =~ s|^<COMMENT[^>]*>(\s?)|'<!--'.($1? $1: ' ')|e;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 1 4 5
2032 5 ▶ $str =~ s|(\s?)</COMMENT>|($1? $1: ' ').'-->'|e;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 1 4 5
2033 5 return $str;
2034 }
2035  
2036 # -----------------------------------------------------------------------------
2037  
2038 =head3 protect() - Schütze HTML Metazeichen
2039  
2040 =head4 Synopsis
2041  
2042 $html = $h->protect($text);
2043  
2044 =head4 Description
2045  
2046 Schütze alle Metazeichen in Text $text, so dass das Resultat
2047 gefahrlos in den Content eines HTML-Tag eingesetzt werden kann.
2048  
2049 =cut
2050  
2051 # -----------------------------------------------------------------------------
2052  
2053 4 ▶sub protect {
Subroutine protect: called CC=2 SCAR=6.9
Pod documented
2054 4 my ($self,$text) = @_;
2055  
2056 4 ▶ if (defined $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 3 1 4
2057 3 $text =~ s/&/&amp;/g;
2058 3 $text =~ s/</&lt;/g;
2059 3 $text =~ s/>/&gt;/g;
2060 }
2061
2062 4 return $text;
2063 }
2064  
2065 # -----------------------------------------------------------------------------
2066  
2067 =head3 optional() - Optional-Klammer: <!--optional-->...<!--/optional-->
2068  
2069 =head4 Synopsis
2070  
2071 $html = $h->optional(@keyVal,$content);
2072  
2073 =head4 Description
2074  
2075 Liefere optional-Klammer:
2076  
2077 <!--optional-->...<!--/optional-->
2078  
2079 bzw.
2080  
2081 <!--optional-->
2082 ...
2083 <!--/optional-->
2084  
2085 wenn $content mehrzeilig ist.
2086  
2087 =cut
2088  
2089 # -----------------------------------------------------------------------------
2090  
2091 4 ▶sub optional {
Subroutine optional: called CC=8 SCAR=23.4
Pod documented
2092 4 my $self = shift;
2093 4 my $content = pop;
2094 # @_: @keyVal
2095  
2096 # Optionen
2097  
2098 4 my $nl = 0;
2099 4 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 4 4
2100 0 my $key = shift;
2101 0 my $val = shift;
2102
2103 0 ▶ if ($key eq '-nl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq '-nl') { } 0 0 0
2104 0 $nl = $val;
2105 }
2106 else {
2107 0 $self->throw(
2108 'HTML--0001: Unbekannte Option',
2109 Option => $key,
2110 Value => $val,
2111 );
2112 }
2113 }
2114  
2115 # Generieren
2116  
2117 4 my $str;
2118 4 ▶ if (!defined($content) || $content eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $content or $content eq '') { } 2 2 4
elsif (not $content =~ tr/\n//) { } 1 1 2
Condition100%3/3
not defined $content or $content eq ""
l!l&&r!l&&!r
112
MC/DC100%2/2
not defined $content or $content eq ""
not defined $content $content eq ""
Truth table100%3/3
not(A) or B
A= not defined $contentB= $content eq ""
ABresult
1X1
011
000
2119 # kein Content
2120 2 $str = '';
2121 }
2122 elsif ($content !~ tr/\n//) {
2123 # Content ist einzeilig
2124 1 $str = "<!--optional-->$content<!--/optional-->";
2125 }
2126 else {
2127 # Content ist mehrzeilig
2128 1 $str = "<!--optional-->\n$content<!--/optional-->\n";
2129 }
2130  
2131 4 ▶ if ($str && $nl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str and $nl) 0 4 4
Condition66%2/3
$str and $nl
!ll&&!rl&&r
220
MC/DC0%0/2
$str and $nl
$str $nl
Truth table66%2/3
A and B
A= $strB= $nl
ABresult
0X0
100
111
2132 0 $str .= "\n" x $nl;
2133 }
2134
2135 4 return $str;
2136 }
2137  
2138 # -----------------------------------------------------------------------------
2139  
2140 =head3 checkValue() - Prüfe Attributwert
2141  
2142 =head4 Synopsis
2143  
2144 $h->checkValue($dom,$val);
2145  
2146 =head4 Description
2147  
2148 Prüfe, ob der Attributwert $val für Domäne $dom korrekt ist.
2149 Fällt die Prüfung negativ aus, löse eine Exception aus.
2150 Die Methode liefert keinen Wert zurück.
2151  
2152 =cut
2153  
2154 # -----------------------------------------------------------------------------
2155  
2156 0 ▶sub checkValue {
Subroutine checkValue: not called CC=1 SCAR=6.9
Pod documented
2157 0 my ($self,$dom,$val) = @_;
2158  
2159 # FIXME: Wertprüfungen implementieren
2160  
2161 0 return;
2162 }
2163  
2164 # -----------------------------------------------------------------------------
2165  
2166 =head3 imgSrcValue() - Liefere Wert für scr-Attribut eines Bildes
2167  
2168 =head4 Synopsis
2169  
2170 $val = $this->imgSrcValue($val,$embedImage);
2171  
2172 =cut
2173  
2174 # -----------------------------------------------------------------------------
2175  
2176 1 ▶sub imgSrcValue {
Subroutine imgSrcValue: called CC=4 SCAR=21.7
Pod documented
2177 1 my ($this,$val,$embedImage) = @_;
2178  
2179 1 ▶ if (ref $val) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val) { } 0 1 1
elsif ($embedImage) { } 0 1 1
2180 # Bilddaten in-memory
2181 0 my $type = Quiq::Image->type($val,-enum=>1);
2182 0 $val = sprintf 'data:image/%s;base64,%s',$type,
2183 MIME::Base64::encode_base64($$val,'');
2184 } elsif ($embedImage) {
2185 0 ▶ if (-f $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $val) { } 0 0 0
2186 # lokale Bilddatei
2187 0 my $type = Quiq::Image->type($val,-enum=>1);
2188 0 $val = sprintf 'data:image/%s;base64,%s',$type,
2189 MIME::Base64::encode_base64(
2190 Quiq::Path->read($val),'');
2191 }
2192 else {
2193 0 warn 'WARNING: <img> Embedding of URL-Image'.
2194 " currently not supported: $val\n";
2195 }
2196 }
2197  
2198 1 return $val;
2199 }
2200  
2201 # -----------------------------------------------------------------------------
2202  
2203 =head3 import() - Setze Konstruktor-Defaults der Klasse
2204  
2205 =head4 Synopsis
2206  
2207 $class->import(@keyVal);
2208  
2209 =head4 Description
2210  
2211 Setze die Konstruktor-Defaults @keyVal der Klasse. Die Setzung gilt
2212 für alle folgenden Konstruktor-Aufrufe, bei denen die betreffenden Werte
2213 beim Konstruktor-Aufruf nicht gesetzt werden.
2214 Die Methode liefert keinen Wert zurück.
2215  
2216 =head4 Example
2217  
2218 =over 4
2219  
2220 =item XHTML (Default):
2221  
2222 use Quiq::Html::Tag;
2223  
2224 =item HTML (Großschreibung) statt XHTML generieren:
2225  
2226 use Quiq::Html::Tag(htmlVersion=>'html-4.01',uppercase=>1);
2227  
2228 =back
2229  
2230 =cut
2231  
2232 # -----------------------------------------------------------------------------
2233  
2234 38 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
2235 38 my $class = shift;
2236 # @_: @keyVal
2237  
2238 38 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 38 41
2239 3 my $key = shift;
2240 3 $Default{$key} = shift;
2241 }
2242  
2243 38 return;
2244 }
2245  
2246 # -----------------------------------------------------------------------------
2247  
2248 =head1 VERSION
2249  
2250 1.240
2251  
2252 =head1 AUTHOR
2253  
2254 Frank Seitz, L<http://fseitz.de/>
2255  
2256 =head1 COPYRIGHT
2257  
2258 Copyright (C) 2026 Frank Seitz
2259  
2260 =head1 LICENSE
2261  
2262 This code is free software; you can redistribute it and/or modify
2263 it under the same terms as Perl itself.
2264  
2265 =cut
2266  
2267 # -----------------------------------------------------------------------------
2268  
2269 36 1;
2270  
2271 # eof
« Quiq/Gd/Component/Axis.pm ↑ Summary Quiq/LaTeX/Document.pm »