Quiq/Converter.pm

filter: Statementstmt 74.0% 117 / 158 Branchbran 38.6% 17 / 44 Conditioncond 66.6% 12 / 18 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 85.7% 24 / 28 Podpod 100% 17 / 17 totaltotal 69.7% 191 / 274 CC 31 SCAR 22.1
CC
31
Cov
66%
epochToDuration
20.9
newlineToName
20.0
doubleDecode
20.0
CRAP 9.2
« Quiq/SqlPlus.pm ↑ Summary Quiq/Html/Widget/Hidden.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Converter - Konvertierung von Werten
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =cut
14  
15 # -----------------------------------------------------------------------------
16  
17 package Quiq::Converter;
18 270 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 270 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 270 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 270 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 270 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 270 our $VERSION = '1.240';
26  
27 270 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 270 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # -----------------------------------------------------------------------------
31  
32 =head1 METHODS
33  
34 =head2 Zeichenketten
35  
36 =head3 newlineToName() - Liefere Namen einer Newline-Zeichenkette
37  
38 =head4 Synopsis
39  
40 $nlName = $this->newlineToName($nl);
41  
42 =head4 Description
43  
44 Liefere den "Namen" einer Newline-Zeichenkette, also "LF", "CRLF"
45 oder "CR".
46  
47 =cut
48  
49 # -----------------------------------------------------------------------------
50  
51 0 ▶sub newlineToName {
Subroutine newlineToName: not called CC=4 SCAR=30.0
Pod documented
52 0 my ($this,$nl) = @_;
53  
54 0 ▶ if ($nl eq "\cJ") {
Branch: 3 branches
BranchTrueFalseTotal
if ($nl eq "\n") { } 0 0 0
elsif ($nl eq "\r\n") { } 0 0 0
elsif ($nl eq "\r") { } 0 0 0
55 0 return 'LF';
56 }
57 elsif ($nl eq "\cM\cJ") {
58 0 return 'CRLF';
59 }
60 elsif ($nl eq "\cM") {
61 0 return 'CR';
62 }
63
64 $this->throw(
65 0 'PATH-00099: Unknown newline string',
66 NewlineString => $nl,
67 );
68 }
69  
70 # -----------------------------------------------------------------------------
71  
72 =head3 camelCaseToSnakeCase() - Wandele CamelCase nach SnakeCase
73  
74 =head4 Synopsis
75  
76 $snake = $this->camelCaseToSnakeCase($camel);
77  
78 =head4 Arguments
79  
80 =over 4
81  
82 =item $camel
83  
84 Bezeichner in CamelCase
85  
86 =back
87  
88 =head4 Returns
89  
90 Bezeichner in SnakeCase
91  
92 =head4 Description
93  
94 Wandele einen in CamelCase geschriebenen Bezeichner in einen
95 SnakeCase Bezeichner und liefere diesen zurück.
96  
97 CamelCase:
98  
99 imsApplyDeltaRowByRow
100  
101 SnakeCase:
102  
103 ims-apply-delta-row-by-row
104  
105 =cut
106  
107 # -----------------------------------------------------------------------------
108  
109 1 ▶sub camelCaseToSnakeCase {
Subroutine camelCaseToSnakeCase: called CC=1 SCAR=0.0
Pod documented
110 1 my ($this,$str) = @_;
111  
112 # Eingebettete Bindestriche und Unterstriche in Camel Case wandeln
113 1 $str =~ s/(.)([A-Z])/$1-\L$2/g;
114  
115 1 return $str;
116 }
117  
118 # -----------------------------------------------------------------------------
119  
120 =head3 snakeCaseToCamelCase() - Wandele SnakeCase nach CamelCase
121  
122 =head4 Synopsis
123  
124 $camel = $this->snakeCaseToCamelCase($snake);
125  
126 =head4 Description
127  
128 Wandele einen in SnakeCase geschriebenen Bezeichner in einen
129 CamelCase Bezeichner und liefere diesen zurück.
130  
131 SnakeCase:
132  
133 ims-apply-delta-row-by-row
134 ims_apply_delta_row_by_row
135  
136 CamelCase:
137  
138 imsApplyDeltaRowByRow
139  
140 =cut
141  
142 # -----------------------------------------------------------------------------
143  
144 79 ▶sub snakeCaseToCamelCase {
Subroutine snakeCaseToCamelCase: called CC=1 SCAR=0.0
Pod documented
145 79 my ($this,$str) = @_;
146  
147 # Eingebettete Bindestriche und Unterstriche in Camel Case wandeln
148 # $str =~ s/(.)[_-](.)/$1\U$2/g;
149 79 $str =~ s/[_-](.)/\U$1/g;
150  
151 79 return $str;
152 }
153  
154 # -----------------------------------------------------------------------------
155  
156 =head3 protectRegexChars() - Maskiere Regex-Metazeichen in Zeichenkette
157  
158 =head4 Synopsis
159  
160 $strProtexted = $this->protectRegexChars($str);
161  
162 =head4 Arguments
163  
164 =over 4
165  
166 =item $str
167  
168 Zeichenkette, in der die Zeichen maskiert werden sollen
169  
170 =back
171  
172 =head4 Returns
173  
174 (String) Zeichenkette, in der die Regex-Metazeichen maskiert sind.
175  
176 =head4 Description
177  
178 Maskiere in Zeichenkete $str alle Regex-Metazeichen und liefere
179 das Resultat zurück. Maskiert werden die Zeichen
180  
181 . + * ? | ( ) { } [ ] \ ^ $
182  
183 Im Gegensatz zur Perl Buildinfunktion quotemeta() bzw. "\Q..."
184 maskiert diese Methode keine anderen Zeichen als Regex-Metazeichen.
185  
186 =cut
187  
188 # -----------------------------------------------------------------------------
189  
190 1 ▶sub protectRegexChars {
Subroutine protectRegexChars: called CC=1 SCAR=0.0
Pod documented
191 1 my ($this,$str) = @_;
192  
193 1 $str =~ s/([.+*?|(){}\[\]\\^\$])/\\$1/g;
194  
195 1 return $str;
196 }
197  
198 # -----------------------------------------------------------------------------
199  
200 =head3 strToHex() - Wandele String in Hex-Darstellung
201  
202 =head4 Synopsis
203  
204 $strHex = $this->strToHex($str);
205  
206 =cut
207  
208 # -----------------------------------------------------------------------------
209  
210 1 ▶sub strToHex {
Subroutine strToHex: called CC=1 SCAR=0.0
Pod documented
211 1 my ($this,$str) = @_;
212  
213 1 $str =~ s/(.)/sprintf '%02x ',ord $1/seg;
214 1 substr($str,-1) = '';
215  
216 1 return $str;
217 }
218  
219 # -----------------------------------------------------------------------------
220  
221 =head3 textToHtml() - Wandele Text nach HTML
222  
223 =head4 Synopsis
224  
225 $html = $this->textToHtml($text);
226  
227 =head4 Description
228  
229 Ersetze in $text die Zeichen &, < und > durch HTML-Entities und
230 liefere das Resultat zurück.
231  
232 =cut
233  
234 # -----------------------------------------------------------------------------
235  
236 0 ▶sub textToHtml {
Subroutine textToHtml: not called CC=1 SCAR=6.9
Pod documented
237 0 my ($this,$str) = @_;
238  
239 0 $str =~ s/&/&amp;/g;
240 0 $str =~ s/</&lt;/g;
241 0 $str =~ s/>/&gt;/g;
242  
243 0 return $str;
244 }
245  
246 # -----------------------------------------------------------------------------
247  
248 =head3 doubleDecode() - Wandele doppelt enkodiertes UTF-8 zurück
249  
250 =head4 Synopsis
251  
252 $class->doubleDecode(\$str);
253 $newStr = $class->doubleDecode($str);
254  
255 =head4 Description
256  
257 Wandele doppelt enkodiertes UTF-8 zurück in einfach enkodiertes UTF-8.
258 Behandelt werden aktuell nur deutsche Umlaute und Sz.
259  
260 =cut
261  
262 # -----------------------------------------------------------------------------
263  
264 0 ▶sub doubleDecode {
Subroutine doubleDecode: not called CC=4 SCAR=30.0
Pod documented
265 0 my ($class,$arg) = @_;
266  
267 0 ▶ my $ref = ref $arg? $arg: \$arg;
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 0 0 0
268  
269 0 ▶ if (defined $$ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$ref) 0 0 0
270 0 $$ref =~ s/\N{U+00C3}\N{U+00A4}/ä/g;
271 0 $$ref =~ s/\N{U+00C3}\N{U+00B6}/ö/g;
272 0 $$ref =~ s/\N{U+00C3}\N{U+00BC}/ü/g;
273 0 $$ref =~ s/\N{U+00C3}\N{U+0084}/Ä/g;
274 0 $$ref =~ s/\N{U+00C3}\N{U+0096}/Ö/g;
275 0 $$ref =~ s/\N{U+00C3}\N{U+009C}/Ü/g;
276 0 $$ref =~ s/\N{U+00C3}\N{U+009F}/ß/g;
277 }
278  
279 0 ▶ return ref $arg? (): $$ref;
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 0 0 0
280 }
281  
282 # -----------------------------------------------------------------------------
283  
284 =head3 umlautToAscii() - Wandele deutsche Umlaute und SZ nach ASCII
285  
286 =head4 Synopsis
287  
288 $class->umlautToAscii(\$str);
289 $newStr = $class->umlautToAscii($str);
290  
291 =head4 Description
292  
293 Schreibe ä, Ä, ö, Ö, ü, Ü, ß in ae, Ae, oe, Oe, ue, Ue, ss um
294 und liefere das Resultat zurück. Wird eine Stringreferenz angegeben,
295 findet die Umschreibung "in-place" statt.
296  
297 Die Methode setzt voraus, dass der String korrekt dekodiert wurde.
298  
299 =cut
300  
301 # -----------------------------------------------------------------------------
302  
303 2649 ▶sub umlautToAscii {
Subroutine umlautToAscii: called CC=4 SCAR=13.9
Pod documented
304 2649 my ($class,$arg) = @_;
305  
306 2649 ▶ my $ref = ref $arg? $arg: \$arg;
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 1 2648 2649
307  
308 2649 ▶ if (defined $$ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$ref) 369 2280 2649
309 369 $$ref =~ s/ä/ae/g;
310 369 $$ref =~ s/ö/oe/g;
311 369 $$ref =~ s/ü/ue/g;
312 369 $$ref =~ s/Ä/Ae/g;
313 369 $$ref =~ s/Ö/Oe/g;
314 369 $$ref =~ s/Ü/Ue/g;
315 369 $$ref =~ s/ß/ss/g;
316 }
317  
318 2649 ▶ return ref $arg? (): $$ref;
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 1 2648 2649
319 }
320  
321 # -----------------------------------------------------------------------------
322  
323 =head2 Zahlen
324  
325 =head3 germanNumber() - Wandele deutsche Zahldarstellung in Zahl
326  
327 =head4 Synopsis
328  
329 $x = $this->germanNumber($germanX);
330  
331 =head4 Alias
332  
333 germanToProgramNumber()
334  
335 =head4 Description
336  
337 Wandele deutsche Zahldarstellung mit Punkt (.) als Stellen-Trenner und
338 Komma (,) als Dezimaltrennzeichen in eine Zahl der Programmiersprache
339 und liefere das Resultat zurück.
340  
341 =cut
342  
343 # -----------------------------------------------------------------------------
344  
345 5 ▶sub germanNumber {
Subroutine germanNumber: called CC=1 SCAR=0.0
Pod documented
346 5 my ($this,$x) = @_;
347  
348 5 $x =~ s/\.//;
349 5 $x =~ s/,/./;
350  
351 5 return $x;
352 }
353  
354 {
355 270 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
356 270 *germanToProgramNumber = \&germanNumber;
357 }
358  
359 # -----------------------------------------------------------------------------
360  
361 =head3 germanMoneyAmount() - Wandele deutschen Geldbetrag in Zahl
362  
363 =head4 Synopsis
364  
365 $x = $this->germanMoneyAmount($germanMoneyAmount);
366  
367 =head4 Description
368  
369 Wandele deutschen Geldbetrag mit Punkt (.) als Stellen-Trenner und
370 Komma (,) als Dezimaltrennzeichen in eine Zahl mit zwei Nachkommastellen
371 der Programmiersprache und liefere das Resultat zurück.
372  
373 =cut
374  
375 # -----------------------------------------------------------------------------
376  
377 3 ▶sub germanMoneyAmount {
Subroutine germanMoneyAmount: called CC=1 SCAR=0.0
Pod documented
378 3 my ($this,$x) = @_;
379 3 return sprintf '%.2f',$this->germanNumber($x);
380 }
381  
382 # -----------------------------------------------------------------------------
383  
384 =head3 intToWord() - Wandele positive ganze Zahl in Wort über Alphabet
385  
386 =head4 Synopsis
387  
388 $word = $this->intToWord($n);
389 $word = $this->intToWord($n,$alphabet);
390  
391 =head4 Returns
392  
393 Zeichenkette
394  
395 =head4 Description
396  
397 Wandele positive ganze Zahl $n in ein Wort über dem Alphabet
398 $alphabet und liefere dieses zurück. Für 0 liefere
399 einen Leerstring.
400  
401 Das Alphabet, über welchem die Worte gebildet werden, wird in Form
402 einer Zeichenkette angegeben, in der jedes Zeichen einmal
403 vorkommt. Per Default wird das Alphabet
404  
405 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
406  
407 verwendet. Die Funktion implementiert folgende Abbildung:
408  
409 0 -> ''
410 1 -> 'A'
411 2 -> 'B'
412
413 ...
414 26 -> 'Z'
415 27 -> 'AA'
416 28 -> 'AB'
417 ...
418 52 -> 'AZ'
419 53 -> 'BA'
420 ...
421  
422 =cut
423  
424 # -----------------------------------------------------------------------------
425  
426 0 ▶sub intToWord {
Subroutine intToWord: not called CC=4 SCAR=30.0
Pod documented
427 0 my $this = shift;
428 0 my $n = shift;
429 0 ▶ my $alphabet = shift || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
Condition0%0/2
shift() || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l!l
00
MC/DC0%0/1
shift() || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
430  
431 0 my $l = length $alphabet;
432  
433 0 my $word = '';
434 0 my $m = $n; # warum dies?
435  
436 0 ▶ while ($m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m) 0 0 0
437 0 my $mod = $m%$l;
438 0 $word = substr($alphabet,$mod-1,1).$word;
439 0 $m = POSIX::floor($m/$l);
440 0 ▶ $m -= 1 if $mod == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $mod == 0 0 0 0
441 }
442  
443 0 return $word;
444 }
445  
446 # -----------------------------------------------------------------------------
447  
448 =head2 Längen
449  
450 =head3 ptToPx() - Rechne Punkt (pt) in Pixel (px) um
451  
452 =head4 Synopsis
453  
454 $px = $this->ptToPx($pt);
455  
456 =head4 Alias
457  
458 pointToPixel()
459  
460 =head4 Arguments
461  
462 =over 4
463  
464 =item $pt (Number)
465  
466 Punkt-Wert
467  
468 =back
469  
470 =head4 Returns
471  
472 Pixel-Wert (Number)
473  
474 =head4 Description
475  
476 Rechne Punkt in Pixel um und liefere das Resultat zurück.
477  
478 1 Punkt = 1/0.75 Pixel
479  
480 =cut
481  
482 # -----------------------------------------------------------------------------
483  
484 1 ▶sub ptToPx {
Subroutine ptToPx: called CC=1 SCAR=0.0
Pod documented
485 1 my ($this,$pt) = @_;
486 1 return $pt*(1/0.75);
487 }
488  
489 {
490 270 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
491 270 *pointToPixel = \&ptToPx;
492 }
493  
494 # -----------------------------------------------------------------------------
495  
496 =head3 pxToPt() - Rechne Pixel (px) in Punkt (pt) um
497  
498 =head4 Synopsis
499  
500 $pt = $this->pxToPt($px);
501  
502 =head4 Alias
503  
504 pixelToPoint()
505  
506 =head4 Arguments
507  
508 =over 4
509  
510 =item $px (Number)
511  
512 Pixel-Wert
513  
514 =back
515  
516 =head4 Returns
517  
518 Punkt-Wert (Number)
519  
520 =head4 Description
521  
522 Rechne Pixel in Punkt um und liefere das Resultat zurück.
523  
524 1 Pixel = 0.75 Punkt
525  
526 =cut
527  
528 # -----------------------------------------------------------------------------
529  
530 2 ▶sub pxToPt {
Subroutine pxToPt: called CC=1 SCAR=0.0
Pod documented
531 2 my ($this,$px) = @_;
532 2 return $px*0.75;
533 }
534  
535 {
536 270 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
537 270 *pixelToPoint = \&pxToPt;
538 }
539  
540 # -----------------------------------------------------------------------------
541  
542 =head2 Zeitdarstellung
543  
544 =head3 epochToDuration() - Wandele Sekunden in (lesbare) Angabe einer Dauer
545  
546 =head4 Synopsis
547  
548 $str = $class->epochToDuration($epoch,$truncate,$format);
549  
550 =head4 Alias
551  
552 secondsToDuration()
553  
554 =head4 Description
555  
556 Wandele eine Zeitangabe in Sekunden in eine Zeichenkette der Form
557  
558 HH:MM:SS ($format nicht angegeben oder 1)
559  
560 oder
561  
562 HHhMMmSSs ($format == 2)
563  
564 oder
565  
566 HhMmSs ($format == 3)
567  
568 =cut
569  
570 # -----------------------------------------------------------------------------
571  
572 2 ▶sub epochToDuration {
Subroutine epochToDuration: called CC=9 SCAR=30.4
Pod documented
573 2 my $class = shift;
574 2 my $s = shift;
575 2 ▶ my $truncate = shift || 0;
Condition50%1/2
shift() || 0
l!l
02
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
576 2 ▶ my $format = shift || 1;
Condition50%1/2
shift() || 1
l!l
02
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
577  
578 2 my $h = int $s/3600;
579 2 $s -= $h*3600;
580 2 my $m = int $s/60;
581 2 $s -= $m*60;
582  
583 2 my $str;
584 2 ▶ if ($format == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($format == 1) { } 2 0 2
elsif ($format == 2) { } 0 0 0
elsif ($format == 3) { } 0 0 0
585 2 $str = sprintf '%02d:%02d:%02d',$h,$m,$s;
586 }
587 elsif ($format == 2) {
588 0 $str = sprintf '%02dh%02dm%02ds',$h,$m,$s;
589 }
590 elsif ($format == 3) {
591 0 $str = sprintf '%dh%dm%ds',$h,$m,$s;
592 }
593 2 ▶ if ($truncate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($truncate) 0 2 2
594 0 $str =~ s/^[0\D]+//;
595 0 ▶ if ($str eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq "") 0 0 0
596 0 $str = '0';
597 0 ▶ if ($format > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format > 1) 0 0 0
598 0 $str .= 's';
599 }
600 }
601 }
602
603 2 return $str;
604 }
605  
606 {
607 270 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
608 270 *secondsToDuration = \&epochToDuration;
609 }
610  
611 # -----------------------------------------------------------------------------
612  
613 =head3 timestampToEpoch() - Wandele Timestamp in lokaler Zeit nach Epoch
614  
615 =head4 Synopsis
616  
617 $t = $class->timestampToEpoch($timestamp);
618  
619 =head4 Description
620  
621 Es wird vorausgesetzt, dass der Timestamp das Format
622  
623 YYYY-MM-DD HH24:MI:SSXFF
624  
625 hat.
626  
627 Fehlende Teile werden als 0 angenommen, so dass insbesondere
628 auch folgende Formate gewandelt werden können:
629  
630 YYYY-MM-DD HH24:MI:SS (keine Sekundenbruchteile)
631 YYYY-MM-DD (kein Zeitanteil)
632  
633 Diese Methode ist z.B. nützlich, um einen Oracle-Timestamp
634 (in lokaler Zeit) nach Epoch zu wandeln.
635  
636 =cut
637  
638 # -----------------------------------------------------------------------------
639  
640 3 ▶sub timestampToEpoch {
Subroutine timestampToEpoch: called CC=5 SCAR=16.1
Pod documented
641 3 my ($class,$timestamp) = @_;
642  
643 3 my ($y,$m,$d,$h,$mi,$s,$ms) = split /\D+/,$timestamp;
644 3 $y -= 1900;
645 3 $m -= 1;
646 3 ▶ $h ||= 0;
Condition100%2/2
$h ||= 0
l!l
21
MC/DC100%1/1
$h ||= 0
$h
Truth table100%2/2
A
A= $h
Aresult
11
00
647 3 ▶ $mi ||= 0;
Condition100%2/2
$mi ||= 0
l!l
21
MC/DC100%1/1
$mi ||= 0
$mi
Truth table100%2/2
A
A= $mi
Aresult
11
00
648 3 ▶ $s ||= 0;
Condition100%2/2
$s ||= 0
l!l
21
MC/DC100%1/1
$s ||= 0
$s
Truth table100%2/2
A
A= $s
Aresult
11
00
649 3 my $t = Time::Local::timelocal($s,$mi,$h,$d,$m,$y);
650 3 ▶ if ($ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ms) 1 2 3
651 1 $t .= ".$ms";
652 }
653  
654 3 return $t;
655 }
656  
657 # -----------------------------------------------------------------------------
658  
659 =head3 epochToTimestamp() - Wandele Epoch in Timestamp in lokaler Zeit
660  
661 =head4 Synopsis
662  
663 $timestamp = $class->epochToTimestamp($t);
664  
665 =head4 Description
666  
667 Wandele Epoch-Wert $t in einen Timestamp der lokalen Zeitzone um
668 und liefere diesen zurück.
669  
670 =head4 See Also
671  
672 L<timestampToEpoch|"timestampToEpoch() - Wandele Timestamp in lokaler Zeit nach Epoch">()
673  
674 =cut
675  
676 # -----------------------------------------------------------------------------
677  
678 3 ▶sub epochToTimestamp {
Subroutine epochToTimestamp: called CC=2 SCAR=6.9
Pod documented
679 3 my ($class,$t) = @_;
680  
681 3 ($t,my $ms) = split /\./,$t;
682 3 my ($s,$mi,$h,$d,$m,$y) = localtime $t;
683 3 $m++;
684 3 $y += 1900;
685  
686 3 my $str = sprintf '%4d-%02d-%02d %02d:%02d:%02d',$y,$m,$d,$h,$mi,$s;
687 3 ▶ if ($ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ms) 1 2 3
688 1 $str .= ",$ms";
689 }
690 3 return $str;
691 }
692  
693 # -----------------------------------------------------------------------------
694  
695 =head2 Array/Hash
696  
697 =head3 stringToKeyVal() - Wandele Zeichenkette in Schüssel/Wert-Paare
698  
699 =head4 Synopsis
700  
701 $arr|@arr = $class->stringToKeyVal($str);
702  
703 =head4 Description
704  
705 Liefere die in der Zeichenkette enthaltenen Schlüssel/Wert-Paare.
706  
707 Die Schlüssel/Wert-Paare haben die Form:
708  
709 $key="$val"
710  
711 oder
712  
713 $key='$val'
714  
715 oder
716  
717 $key={$val}
718  
719 Wenn $val kein Whitespace enthält, können die Anführungsstriche
720 weggelassen werden:
721  
722 $key=$val
723  
724 =head4 Caveats
725  
726 Wenn $val mit einem doppelten Anführungsstrich beginnt, darf $val
727 keine doppelten Anführungsstiche enthalten.
728  
729 =head4 Example
730  
731 $class->stringToKeyVal(q|var1=val1 var2="val2"|);
732 =>
733 ('var1','val1','var2','val2a')
734  
735 =cut
736  
737 # -----------------------------------------------------------------------------
738  
739 1 ▶sub stringToKeyVal {
Subroutine stringToKeyVal: called CC=6 SCAR=18.2
Pod documented
740 1 my ($class,$str) = @_;
741  
742 1 my @arr;
743 1 ▶ while ($str =~ s/^\s*(\w+)=//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^\s*(\w+)=//) 4 1 5
744 4 push @arr,$1;
745 4 ▶ $str =~ s/^"([^"]*)"// || $str =~ s/^\{([^}]*)\}// ||
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/^"([^"]*)"// or $str =~ s/^\{([^}]*)\}// or $str =~ s/^'([^']*)'// or $str =~ s/^(\S*)// 2 2 4
Condition66%4/6
$str =~ s/^"([^"]*)"// or $str =~ s/^\{([^}]*)\}// or $str =~ s/^'([^']*)'//
l!l&&r!l&&!r
202
$str =~ s/^"([^"]*)"// or $str =~ s/^\{([^}]*)\}//
l!l&&r!l&&!r
202
MC/DC33%1/3
$str =~ s/^"([^"]*)"// or $str =~ s/^\{([^}]*)\}// or $str =~ s/^'([^']*)'//
$str =~ s/^"([^"]*)"// $str =~ s/^\{([^}]*)\}// $str =~ s/^'([^']*)'//
Truth table50%2/4
A or B or C
A= $str =~ s/^"([^"]*)"//B= $str =~ s/^\{([^}]*)\}//C= $str =~ s/^'([^']*)'//
ABCresult
1XX1
01X1
0011
0000
746 $str =~ s/^'([^']*)'// || $str =~ s/^(\S*)//;
747 4 push @arr,$1;
748 }
749  
750 1 ▶ return wantarray? @arr: \@arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
751 }
752  
753 # -----------------------------------------------------------------------------
754  
755 =head1 VERSION
756  
757 1.240
758  
759 =head1 AUTHOR
760  
761 Frank Seitz, L<http://fseitz.de/>
762  
763 =head1 COPYRIGHT
764  
765 Copyright (C) 2026 Frank Seitz
766  
767 =head1 LICENSE
768  
769 This code is free software; you can redistribute it and/or modify
770 it under the same terms as Perl itself.
771  
772 =cut
773  
774 # -----------------------------------------------------------------------------
775  
776 270 1;
777  
778 # eof
« Quiq/SqlPlus.pm ↑ Summary Quiq/Html/Widget/Hidden.pm »