Quiq/StreamServe/Stream.pm

filter: Statementstmt 43.7% 77 / 176 Branchbran 23.5% 16 / 68 Conditioncond 14.2% 2 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 59.0% 13 / 22 Podpod 100% 14 / 14 totaltotal 40.4% 122 / 302 CC 46 SCAR 29.2
CC
46
Cov
37%
split
56.0
lookupHeader
42.0
lookup
20.0
CRAP 18.5
« Quiq/Parameters.pm ↑ Summary Quiq/Gd/Component/ScatterGraph.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::StreamServe::Stream - Inhalt einer StreamServe Stream-Datei
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert den Inhalt einer StreamServe
16 Stream-Datei:
17  
18 =over 2
19  
20 =item *
21  
22 Feldwerte können abgfragt werden
23  
24 =item *
25  
26 Über den Blöcken kann iteriert werden
27  
28 =back
29  
30 =cut
31  
32 # -----------------------------------------------------------------------------
33  
34 package Quiq::StreamServe::Stream;
35 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 our $VERSION = '1.240';
42  
43 1 ▶use Quiq::StreamServe::Block;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use Quiq::FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use Quiq::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use Quiq::AnsiColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 # -----------------------------------------------------------------------------
49  
50 =head1 METHODS
51  
52 =head2 Klassenmethoden
53  
54 =head3 new() - Instantiiere Objekt
55  
56 =head4 Synopsis
57  
58 $ssf = $class->new($file,%options);
59  
60 =head4 Arguments
61  
62 =over 4
63  
64 =item $file
65  
66 Pfad der Streamdatei.
67  
68 =back
69  
70 =head4 Options
71  
72 =over 4
73  
74 =item -debug => $bool (Default: 0)
75  
76 Gib den Inhalt des Streams auf STDOUT aus (Blöcke in Lesereihenfolge,
77 Felder alphanumerisch sortiert).
78  
79 =item -ignore => \@vals (Default: [])
80  
81 Feldwerte, die auf einen Leerstring reduziert werden. Beispiel:
82  
83 -ignore => ['.','*','-']
84  
85 =back
86  
87 =head4 Returns
88  
89 Objekt
90  
91 =head4 Description
92  
93 Instantiiere ein Objekt der Klasse und liefere dieses zurück.
94 Enthält die Streamdatei mehr als einen Stream, wird eine Exception
95 geworfen.
96  
97 =cut
98  
99 # -----------------------------------------------------------------------------
100  
101 1 ▶sub new {
Subroutine new: called CC=9 SCAR=22.2
Pod documented
102 1 my $class = shift;
103 # @_: $file,%options
104  
105 # Optionen und Argumente
106  
107 1 my $debug = 0;
108 1 my $ignoreA = [];
109  
110 1 my $argA = $class->parameters(1,1,\@_,
111 -debug => \$debug,
112 -ignore => \$ignoreA,
113 );
114 1 my $file = shift @$argA;
115  
116 # Datenstrukturen mit erstem (zunächst leeren) Block
117  
118 1 my $n = 0;
119 1 my $type;
120 1 my $prefix = '*';
121 1 my $blk = Quiq::StreamServe::Block->new($prefix);
122 1 my @blocks = ($blk);
123 1 my %section;
124 1 my $secBlkA = $section{$prefix} = [$blk];
125  
126 # StreamServe-Datei lesen
127  
128 1 my $fh = Quiq::FileHandle->new('<',$file);
129 1 $fh->setEncoding('UTF-8');
130 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 238 1 239
131 238 chomp;
132 238 ▶ if ($_ eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "") 8 230 238
133 # Wir übergehen Leerzeilen
134 8 next;
135 }
136 230 my ($key,$val) = split /\t/,$_,2;
137 230 ▶ if (!defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 1 229 230
138 # Wir übergehen Zeilen ohne Wert. Es sollte nur eine geben:
139 # BEGIN<NAME>
140 1 ($type) = $key =~ /BEGIN(.*)/;
141 1 ▶ if (++$n > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$n > 1) 0 1 1
142 0 $class->throw(
143 'STREAM-00099: Streamfile contains more than one stream',
144 StreamFile => $file,
145 );
146 }
147 1 next;
148 }
149 229 $val =~ s/^\s+|\s+$//; # Wert von umgebendem Whitespace befreien
150 229 for my $ign (@$ignoreA) { # unerwünschte Werte wegfiltern
151 0 ▶ if ($val eq $ign) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq $ign) 0 0 0
152 0 $val = '';
153 }
154 }
155 229 ▶ if (/^(..)INDCTR/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(..)INDCTR/) { } 9 220 229
156 # Nächsten (zunächst leeren) Block hinzufügen
157 9 $prefix = $1;
158 9 $blk = Quiq::StreamServe::Block->new($prefix);
159 9 push @blocks,$blk;
160 9 ▶ $secBlkA = $section{$prefix} //= [];
Condition50%1/2
$section{$prefix} //= []
l!l
09
MC/DC0%0/1
$section{$prefix} //= []
$section{$prefix}
Truth table50%1/2
A
A= $section{$prefix}
Aresult
11
00
161 9 push @$secBlkA,$blk;
162 }
163 else {
164 220 $blk->add($key=>$val);
165 }
166 }
167 1 $fh->close;
168  
169 1 return $class->SUPER::new(
170 file => $file,
171 type => $type,
172 blockA => \@blocks,
173 sectionH => Quiq::Hash->new(\%section),
174 );
175 }
176  
177 # -----------------------------------------------------------------------------
178  
179 =head3 lookup() - Suche Feld
180  
181 =head4 Synopsis
182  
183 $val = $class->lookup($file,$name);
184  
185 =head4 Arguments
186  
187 =over 4
188  
189 =item $file
190  
191 Stream-Datei
192  
193 =item $name
194  
195 Name des gesuchten Feldes
196  
197 =back
198  
199 =head4 Returns
200  
201 (String) Wert oder C<undef>
202  
203 =head4 Description
204  
205 Durchsuche den Stream $file nach dem ersten Vorkommen des Feldes $name
206 und liefere dessen Wert zurück. Kommt das Feld im Stream nicht vor,
207 liefere C<undef>.
208  
209 =cut
210  
211 # -----------------------------------------------------------------------------
212  
213 0 ▶sub lookup {
Subroutine lookup: not called CC=4 SCAR=30.0
Pod documented
214 0 my ($class,$file,$name) = @_;
215  
216 0 my $val = undef;
217 0 my $fh = Quiq::FileHandle->new('<',$file);
218 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
219 0 chomp;
220 0 ▶ if ($_ eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "") 0 0 0
221 # Wir übergehen Leerzeilen
222 0 next;
223 }
224 0 my ($key,$str) = split /\t/,$_,2;
225 0 ▶ if ($key eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq $name) 0 0 0
226 0 $val = $str;
227 0 last;
228 }
229 }
230 0 $fh->close;
231  
232 0 return $val;
233 }
234  
235 # -----------------------------------------------------------------------------
236  
237 =head3 lookupHeader() - Suche Feld im Header
238  
239 =head4 Synopsis
240  
241 $val = $class->lookupHeader($file,$name);
242  
243 =head4 Arguments
244  
245 =over 4
246  
247 =item $file
248  
249 Stream-Datei
250  
251 =item $name
252  
253 Name des gesuchten Feldes
254  
255 =back
256  
257 =head4 Returns
258  
259 (String) Wert oder C<undef>
260  
261 =head4 Description
262  
263 Durchsuche den Header des Streams $file nach dem ersten Vorkommen des
264 Feldes $name und liefere dessen Wert zurück. Kommt das Feld im Stream
265 nicht vor, liefere C<undef>. Die Felder des Headers beginnen mit einem
266 Stern (C<*>). Gegenüber Metjode lookup() ist die Methode lookupHeader()
267 effizienter, da sie nach Lesen der Headerfelder stoppt.
268  
269 =cut
270  
271 # -----------------------------------------------------------------------------
272  
273 0 ▶sub lookupHeader {
Subroutine lookupHeader: not called CC=6 SCAR=37.4
Pod documented
274 0 my ($class,$file,$name) = @_;
275  
276 0 my $val = undef;
277 0 my $fh = Quiq::FileHandle->new('<',$file);
278 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
279 0 chomp;
280 0 ▶ if ($_ eq '' || $_ =~ /^BEGIN/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "" or $_ =~ /^BEGIN/) 0 0 0
Condition0%0/3
$_ eq "" or $_ =~ /^BEGIN/
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "" or $_ =~ /^BEGIN/
$_ eq "" $_ =~ /^BEGIN/
Truth table0%0/3
A or B
A= $_ eq ""B= $_ =~ /^BEGIN/
ABresult
1X1
011
000
281 # Wir übergehen Leerzeilen und die BEGIN-Zeile
282 0 next;
283 }
284 0 my ($key,$str) = split /\t/,$_,2;
285 0 ▶ if (substr($key,0,1) ne '*') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($key, 0, 1) ne "*") 0 0 0
286 # Stoppe nach Lesen des Headers
287 0 last;
288 }
289 0 ▶ if ($key eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq $name) 0 0 0
290 0 $val = $str;
291 0 last;
292 }
293 }
294 0 $fh->close;
295  
296 0 return $val;
297 }
298  
299 # -----------------------------------------------------------------------------
300  
301 =head3 numberOfStreams() - Anzahl der (Einzel-)Streams
302  
303 =head4 Synopsis
304  
305 $n = $class->numberOfStreams($file);
306  
307 =head4 Arguments
308  
309 =over 4
310  
311 =item $file
312  
313 Stream-Datei
314  
315 =back
316  
317 =head4 Returns
318  
319 (Integer) Anzahl der Einzelstreams
320  
321 =head4 Description
322  
323 Ermittele die Anzahl der Einzelstreams und liefere diese zurück.
324 Ax-Streams zählen wir nicht mit.
325  
326 =cut
327  
328 # -----------------------------------------------------------------------------
329  
330 0 ▶sub numberOfStreams {
Subroutine numberOfStreams: not called CC=4 SCAR=30.0
Pod documented
331 0 my ($class,$file) = @_;
332  
333 0 my $n = 0;
334 0 my $fh = Quiq::FileHandle->new('<',$file);
335 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
336 0 ▶ if (/^BEGIN/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^BEGIN/) 0 0 0
337 0 ▶ if (!/A\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/A\d$/) 0 0 0
338 0 $n++;
339 }
340 }
341 }
342 0 $fh->close;
343  
344 0 return $n;
345 }
346  
347 # -----------------------------------------------------------------------------
348  
349 =head3 split() - Zerlege (Multi-)Stream in Einzelstreams
350  
351 =head4 Synopsis
352  
353 @arr | $arrA = $class->split($file);
354 @arr | $arrA = $class->split(\$data);
355  
356 =head4 Arguments
357  
358 =over 4
359  
360 =item $file
361  
362 Stream-Datei
363  
364 =item $data
365  
366 Stream-Daten
367  
368 =back
369  
370 =head4 Returns
371  
372 (Array of Strings) Liste der Einzelstreams
373  
374 =head4 Description
375  
376 Zerlege einen (Multi-)Stream (aus Datei oder In-Memory-Daten)
377 in Einzelstreams und liefere die Liste der Einzelstreams zurück.
378  
379 Ax-Streams ignorieren wir. D.h. die gelieferte Liste ist leer, wenn der
380 Stream lediglich einen A0- oder A1-Stream enthält.
381  
382 =cut
383  
384 # -----------------------------------------------------------------------------
385  
386 0 ▶sub split {
Subroutine split: not called CC=7 SCAR=40.3
Pod documented
387 0 my ($class,$file) = @_;
388  
389 0 my @arr;
390 0 my $i = 0;
391 0 my $skip = 0;
392 0 my $fh = Quiq::FileHandle->new('<',$file);
393 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
394 0 ▶ if (/^BEGIN/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^BEGIN/) 0 0 0
395 0 ▶ if (/A\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/A\d$/) { } 0 0 0
396 0 $skip = 1;
397 }
398 else {
399 0 $skip = 0;
400 0 $i++;
401 }
402 }
403 0 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 0 0 0
404 0 next;
405 }
406 0 $arr[$i] .= $_;
407 }
408 0 $fh->close;
409  
410 0 $i = 0;
411 0 my $header = shift @arr;
412 0 for my $body (@arr) {
413 0 $arr[$i++] = $header.$body;
414 }
415  
416 0 ▶ return wantarray? @arr: \@arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
417 }
418  
419 # -----------------------------------------------------------------------------
420  
421 =head2 Objektmethoden
422  
423 =head3 allBlocks() - Liste aller Blöcke
424  
425 =head4 Synopsis
426  
427 @arr | $arrH = $ssf->allBlocks;
428  
429 =head4 Returns
430  
431 (Array of Hashes) Liste von Blöcken
432  
433 =head4 Description
434  
435 Liefere die Liste aller Blöcke des Streams.
436  
437 =cut
438  
439 # -----------------------------------------------------------------------------
440  
441 1 ▶sub allBlocks {
Subroutine allBlocks: called CC=2 SCAR=7.1
Pod documented
442 1 my $self = shift;
443  
444 1 my $arr = $self->blockA;
445 1 ▶ return wantarray? @$arr: $arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
446 }
447  
448 # -----------------------------------------------------------------------------
449  
450 =head3 blocks() - Liste der Blöcke einer Blockart
451  
452 =head4 Synopsis
453  
454 @arr | $arrH = $ssf->blocks($prefix);
455 @arr | $arrH = $ssf->blocks($prefix,$sloppy);
456  
457 =head4 Arguments
458  
459 =over 4
460  
461 =item $prefix
462  
463 Die Blockart
464  
465 =back
466  
467 =head4 Options
468  
469 =over 4
470  
471 =item $sloppy
472  
473 Wenn gesetzt, wirf keine Exception, wenn die Blockart nicht existiert,
474 sondern liefere eine leere Liste.
475  
476 =back
477  
478 =head4 Returns
479  
480 (Array of Hashes) Liste von Blöcken
481  
482 =head4 Description
483  
484 Liefere die Liste der Blöcke einer Blockarten. Eine Blockart ist durch
485 ihren Präfix charakterisiert.
486  
487 =cut
488  
489 # -----------------------------------------------------------------------------
490  
491 2 ▶sub blocks {
Subroutine blocks: called CC=4 SCAR=14.2
Pod documented
492 2 my ($self,$prefix,$sloppy) = @_;
493  
494 2 my $arrA = eval {$self->sectionH->get($prefix)};
495 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 1 2
496 1 ▶ if ($sloppy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sloppy) { } 0 1 1
497 0 $arrA = [];
498 }
499 else {
500 1 $self->throw(
501 'STREAMSERVE-00099: Block does not exist',
502 Prefix => $prefix,
503 );
504 }
505 }
506 1 ▶ return wantarray? @$arrA: $arrA;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
507 }
508  
509 # -----------------------------------------------------------------------------
510  
511 =head3 file() - Pfad der Streamdatei (Accessor-Methode)
512  
513 =head4 Synopsis
514  
515 $path = $ssf->file;
516  
517 =head4 Returns
518  
519 (String) Pfad der Streamdatei
520  
521 =head4 Description
522  
523 Liefere den Pfad der Streamdatei.
524  
525 =cut
526  
527 # -----------------------------------------------------------------------------
528  
529 # Accessor-Methode
530  
531 # -----------------------------------------------------------------------------
532  
533 =head3 get() - Liefere Wert
534  
535 =head4 Synopsis
536  
537 $val = $ssf->get($name,$i);
538 $val = $ssf->get($name);
539  
540 =head4 Arguments
541  
542 =over 4
543  
544 =item $name
545  
546 Name des abzufragenden Feldes
547  
548 =item $i (Default: 0)
549  
550 Index im Falle mehrfachen Vorkommens des Feldes
551  
552 =back
553  
554 =head4 Returns
555  
556 (String) Wert
557  
558 =cut
559  
560 # -----------------------------------------------------------------------------
561  
562 1 ▶sub get {
Subroutine get: called CC=3 SCAR=11.4
Pod documented
563 1 my ($self,$name) = splice @_,0,2;
564 1 ▶ my $i = shift // 0;
Condition50%1/2
shift() // 0
l!l
01
MC/DC0%0/1
shift() // 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
565  
566 1 ▶ my $prefix = substr($name,0,1) eq '*'? '*': substr($name,0,2);
Branch: 1 branch
BranchTrueFalseTotal
substr($name, 0, 1) eq '*' ? : 1 0 1
567 1 return $self->sectionH->get($prefix)->[$i]->get($name);
568 }
569  
570 # -----------------------------------------------------------------------------
571  
572 =head3 getFirst() - Liefere ersten Attributwert
573  
574 =head4 Synopsis
575  
576 $val = $ssf->getFirst(@keys);
577  
578 =head4 Description
579  
580 Liefere den ersten nichtleeren Wert der Attribute @keys. Attribute, die
581 nicht existieren, werden übergangen.
582  
583 =cut
584  
585 # -----------------------------------------------------------------------------
586  
587 0 ▶sub getFirst {
Subroutine getFirst: not called CC=4 SCAR=30.0
Pod documented
588 0 my $self = shift;
589 # @_: @keys
590  
591 0 for my $key (@_) {
592 0 my $val = $self->try($key);
593 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
594 0 return $val;
595 }
596 }
597  
598 0 return undef;
599 }
600  
601 # -----------------------------------------------------------------------------
602  
603 =head3 set() - Setze Wert
604  
605 =head4 Synopsis
606  
607 $ssf->set($name,$val,$i);
608 $ssf->set($name,$val);
609  
610 =head4 Arguments
611  
612 =over 4
613  
614 =item $name
615  
616 Name des zu setzenden Feldes
617  
618 =item $val
619  
620 Wert, der gesetzt werden soll
621  
622 =item $i (Default: 0)
623  
624 Index im Falle mehrfachen Vorkommens des Feldes
625  
626 =back
627  
628 =cut
629  
630 # -----------------------------------------------------------------------------
631  
632 0 ▶sub set {
Subroutine set: not called CC=3 SCAR=24.8
Pod documented
633 0 my ($self,$name,$val) = splice @_,0,3;
634 0 ▶ my $i = shift // 0;
Condition0%0/2
shift() // 0
l!l
00
MC/DC0%0/1
shift() // 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
635  
636 0 ▶ my $prefix = substr($name,0,1) eq '*'? '*': substr($name,0,2);
Branch: 1 branch
BranchTrueFalseTotal
substr($name, 0, 1) eq '*' ? : 0 0 0
637 0 return $self->sectionH->get($prefix)->[$i]->set($name,$val);
638 }
639  
640 # -----------------------------------------------------------------------------
641  
642 =head3 prefixes() - Liste der Blockarten (Präfixe)
643  
644 =head4 Synopsis
645  
646 @arr | $arrH = $ssf->prefixes;
647  
648 =head4 Returns
649  
650 (Array of Strings) Liste der Block-Präfixe
651  
652 =head4 Description
653  
654 Liefere die Liste der Blockarten. Eine Blockart ist durch die Liste
655 der gemeinsamen Feldpräfixe charakterisiert.
656  
657 =cut
658  
659 # -----------------------------------------------------------------------------
660  
661 1 ▶sub prefixes {
Subroutine prefixes: called CC=2 SCAR=7.0
Pod documented
662 1 my $self = shift;
663  
664 1 my @arr = sort keys %{$self->sectionH};
665 1 ▶ return wantarray? @arr: \@arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
666 }
667  
668 # -----------------------------------------------------------------------------
669  
670 =head3 report() - Liefere Bericht über den Stream
671  
672 =head4 Synopsis
673  
674 $text = $ssf->report;
675  
676 =head4 Returns
677  
678 (String) Text des Berichts
679  
680 =head4 Description
681  
682 Erzeuge einen Bericht über den Stream und liefere dessen Text zurück.
683  
684 =cut
685  
686 # -----------------------------------------------------------------------------
687  
688 0 ▶sub report {
Subroutine report: not called CC=4 SCAR=30.0
Pod documented
689 0 my $self = shift;
690  
691 0 my $a = Quiq::AnsiColor->new(1);
692  
693 0 my $text = sprintf "---%s---\n",$a->str('bold red','Stream Report');
694  
695 0 for my $blk ($self->allBlocks) {
696 0 $text .= $blk->prefix."\n";
697 0 my $h = $blk->hash;
698 0 my $r = $blk->read;
699 0 for my $key (sort $blk->hash->keys) {
700 # $text .= " $key\n";
701 0 my $val = $h->{$key};
702 $text .= sprintf " %s = %s\n",$key,
703 0 ▶ $r->{$key}? $a->str('green',$val): $val;
Branch: 1 branch
BranchTrueFalseTotal
$r->{$key} ? : 0 0 0
704 }
705 }
706  
707 0 return $text;
708 }
709  
710 # -----------------------------------------------------------------------------
711  
712 =head3 try() - Liefere Wert
713  
714 =head4 Synopsis
715  
716 $val = $ssf->try($name,$i);
717 $val = $ssf->try($name);
718  
719 =head4 Arguments
720  
721 =over 4
722  
723 =item $name
724  
725 Name des abzufragenden Feldes
726  
727 =item $i (Default: 0)
728  
729 Index im Falle mehrfachen Vorkommens des Feldes
730  
731 =back
732  
733 =head4 Returns
734  
735 (String) Wert
736  
737 =head4 Description
738  
739 Wie get(), nur dass der Zugriff auf ein nicht-existentes Feld nicht
740 zu einer Exception führt, sondern C<undef> liefert.
741  
742 =cut
743  
744 # -----------------------------------------------------------------------------
745  
746 0 ▶sub try {
Subroutine try: not called CC=3 SCAR=24.8
Pod documented
747 0 my ($self,$name) = splice @_,0,2;
748 0 ▶ my $i = shift // 0;
Condition0%0/2
shift() // 0
l!l
00
MC/DC0%0/1
shift() // 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
749  
750 0 ▶ my $prefix = substr($name,0,1) eq '*'? '*': substr($name,0,2);
Branch: 1 branch
BranchTrueFalseTotal
substr($name, 0, 1) eq '*' ? : 0 0 0
751 0 my $val = eval {$self->{'sectionH'}->{$prefix}->[$i]->get($name)};
752 0 return $val;
753 }
754  
755 # -----------------------------------------------------------------------------
756  
757 =head3 type() - Typ des Streams
758  
759 =head4 Synopsis
760  
761 $type = $ssf->type;
762 $type = $class->type($file);
763  
764 =head4 Arguments
765  
766 =over 4
767  
768 =item $file
769  
770 Stream-Datei
771  
772 =back
773  
774 =head4 Returns
775  
776 (String) Typ des Stream, z.B. C<SOS1890H>
777  
778 =head4 Description
779  
780 Liefere den Typ der Streamdatei $ssf bzw. $file. Als Klassenmethode
781 gerufen, wird der Typ effizient ermittelt, ohne den ganzen Stream
782 einzulesen.
783  
784 =cut
785  
786 # -----------------------------------------------------------------------------
787  
788 0 ▶sub type {
Subroutine type: not called CC=4 SCAR=30.0
Pod documented
789 0 my $this = shift;
790  
791 # Typ aus dem Objekt liefern
792  
793 0 ▶ if (ref $this) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this) 0 0 0
794 0 return $this->{'type'};
795 }
796  
797 # StreamServe-Datei lesen
798  
799 0 my $file = shift;
800  
801 0 my $type;
802 0 my $fh = Quiq::FileHandle->new('<',$file);
803 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
804 0 ▶ if (/^BEGIN(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^BEGIN(.*)/) 0 0 0
805 0 $type = $1;
806 }
807 }
808 0 $fh->close;
809  
810 0 return $type;
811 }
812  
813 # -----------------------------------------------------------------------------
814  
815 =head1 VERSION
816  
817 1.240
818  
819 =head1 AUTHOR
820  
821 Frank Seitz, L<http://fseitz.de/>
822  
823 =head1 COPYRIGHT
824  
825 Copyright (C) 2026 Frank Seitz
826  
827 =head1 LICENSE
828  
829 This code is free software; you can redistribute it and/or modify
830 it under the same terms as Perl itself.
831  
832 =cut
833  
834 # -----------------------------------------------------------------------------
835  
836 1 1;
837  
838 # eof
« Quiq/Parameters.pm ↑ Summary Quiq/Gd/Component/ScatterGraph.pm »