Quiq/LineProcessor/Line.pm

filter: Statementstmt 87.5% 56 / 64 Branchbran 68.7% 11 / 16 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 88.8% 16 / 18 Podpod 100% 13 / 13 totaltotal 84.0% 100 / 119 CC 11 SCAR 8.7
CC
11
Cov
82%
new
5.0
dump
4.2
inputR
2.0
CRAP 2.4
« Quiq/ContentProcessor/BaseType.pm ↑ Summary Quiq/Css/Snippets.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::LineProcessor::Line - Zeile einer Datei
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert eine Zeile, bestehend aus
16 dem Zeileninhalt (Text) und einer Zeilennummer.
17  
18 =cut
19  
20 # -----------------------------------------------------------------------------
21  
22 package Quiq::LineProcessor::Line;
23 2 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 2 our $VERSION = '1.240';
31  
32 # -----------------------------------------------------------------------------
33  
34 =head1 METHODS
35  
36 =head2 Konstruktor
37  
38 =head3 new() - Instantiiere Zeilen-Objekt
39  
40 =head4 Synopsis
41  
42 $ln = $class->new($text,$number,\$input);
43  
44 =head4 Description
45  
46 Instantiiere Zeilenobjekt und liefere eine Referenz auf dieses
47 Objekt zurück.
48  
49 =cut
50  
51 # -----------------------------------------------------------------------------
52  
53 39 ▶sub new {
Subroutine new: called CC=4 SCAR=16.1
Pod documented
54 39 my ($class,$text,$number,$inputR) = @_;
55  
56 # Sicherheitstest für Übergangsphase nach Einführung des Parameters
57  
58 39 ▶ if (!$inputR || !ref $inputR) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inputR and ref $inputR) 0 39 39
Condition33%1/3
$inputR and ref $inputR
!ll&&!rl&&r
0039
MC/DC0%0/2
$inputR and ref $inputR
$inputR ref $inputR
Truth table33%1/3
A and B
A= $inputRB= ref $inputR
ABresult
0X0
100
111
59 0 ▶ $class->throw(
Branch: 1 branch
BranchTrueFalseTotal
!defined($inputR) ? : 0 0 0
60 'LINE-00002: Illegal path',
61 Path => !defined($inputR)? 'undef': $inputR,
62 Text => $text,
63 Line => $number,
64 );
65 }
66  
67 39 my $self = bless [],$class;
68 39 $self->text($text); # entfernt Whitespace am Ende
69 39 $self->number($number);
70 39 $self->inputR($inputR);
71  
72 39 return $self;
73 }
74  
75 # -----------------------------------------------------------------------------
76  
77 =head2 Akzessoren
78  
79 =head3 text() - Liefere/Setze Zeilentext
80  
81 =head4 Synopsis
82  
83 $text = $ln->text;
84 $text = $ln->text($text);
85 $text = $ln->text($text,$strip);
86  
87 =head4 Description
88  
89 Liefere den Zeilentext. Ist ein Argument angegeben, setze den
90 Zeilentext auf den Wert. Ist $strip wahr, entferne Whitespace am
91 Zeilenende. Dadurch werden Zeilen, die nur aus Whitespace
92 bestehen, zu Leerzeilen.
93  
94 =cut
95  
96 # -----------------------------------------------------------------------------
97  
98 70 ▶sub text {
Subroutine text: called CC=2 SCAR=6.9
Pod documented
99 70 my $self = shift;
100 # @_: $text,$strip
101  
102 70 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 41 29 70
103 41 my $text = shift;
104 41 $text =~ s/\s+$//;
105 41 $self->[0] = $text;
106 }
107 70 return $self->[0];
108 }
109  
110 # -----------------------------------------------------------------------------
111  
112 =head3 textNl() - Liefere Zeilentext mit Newline
113  
114 =head4 Synopsis
115  
116 $text = $ln->textNl;
117  
118 =head4 Description
119  
120 Liefere den Zeilentext mit einem angehängten Newline.
121  
122 =cut
123  
124 # -----------------------------------------------------------------------------
125  
126 0 ▶sub textNl {
Subroutine textNl: not called CC=1 SCAR=6.9
Pod documented
127 0 my $self = shift;
128 0 return $self->[0]."\n";
129 }
130  
131 # -----------------------------------------------------------------------------
132  
133 =head3 number() - Liefere/Setze Zeilennummer
134  
135 =head4 Synopsis
136  
137 $n = $ln->number;
138 $n = $ln->number($n);
139  
140 =cut
141  
142 # -----------------------------------------------------------------------------
143  
144 44 ▶sub number {
Subroutine number: called CC=2 SCAR=6.9
Pod documented
145 44 my $self = shift;
146 # @_: $n
147  
148 44 ▶ $self->[1] = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 39 5 44
149 44 return $self->[1];
150 }
151  
152 # -----------------------------------------------------------------------------
153  
154 =head3 inputR() - Liefere/Setze Referenz auf Input-Bezeichnung
155  
156 =head4 Synopsis
157  
158 $inputR = $ln->inputR;
159 $inputR = $ln->inputR(\$input);
160  
161 =head4 Description
162  
163 Liefere/Setze eine Referenz auf die Input-Bezeichung.
164  
165 =cut
166  
167 # -----------------------------------------------------------------------------
168  
169 39 ▶sub inputR {
Subroutine inputR: called CC=2 SCAR=7.0
Pod documented
170 39 my $self = shift;
171 # @_: $inputR
172  
173 39 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 39 0 39
174 39 $self->[2] = shift;
175 }
176  
177 39 return $self->[2];
178 }
179  
180 # -----------------------------------------------------------------------------
181  
182 =head3 input() - Liefere die Input-Bezeichnung
183  
184 =head4 Synopsis
185  
186 $input = $ln->input;
187  
188 =cut
189  
190 # -----------------------------------------------------------------------------
191  
192 0 ▶sub input {
Subroutine input: not called CC=1 SCAR=6.9
Pod documented
193 0 my $self = shift;
194 0 return ${$self->[2]};
195 }
196  
197 # -----------------------------------------------------------------------------
198  
199 =head2 Eigenschaften
200  
201 =head3 isEmpty() - Test auf Leerzeile
202  
203 =head4 Synopsis
204  
205 $bool = $ln->isEmpty;
206  
207 =head4 Description
208  
209 Liefere "wahr", wenn Zeile eine Leerzeile ist, andernfalls "falsch".
210  
211 =cut
212  
213 # -----------------------------------------------------------------------------
214  
215 11 ▶sub isEmpty {
Subroutine isEmpty: called CC=2 SCAR=6.9
Pod documented
216 11 ▶ return CORE::length shift->[0]? 0: 1;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length +(shift())->[0] ? : 8 3 11
217 }
218  
219 # -----------------------------------------------------------------------------
220  
221 =head3 indentation() - Liefere Einrücktiefe der Zeile
222  
223 =head4 Synopsis
224  
225 $n = $ln->indentation;
226  
227 =head4 Description
228  
229 Liefere die Tiefe der Einrückung. Die Einrücktiefe ist die Anzahl
230 an Whitespacezeichen am Anfang der Zeile.
231  
232 =cut
233  
234 # -----------------------------------------------------------------------------
235  
236 4 ▶sub indentation {
Subroutine indentation: called CC=1 SCAR=0.0
Pod documented
237 4 my $self = shift;
238 4 $self->[0] =~ /^(\s*)/;
239 4 return CORE::length $1;
240 }
241  
242 # -----------------------------------------------------------------------------
243  
244 =head3 length() - Liefere Zeilenlänge
245  
246 =head4 Synopsis
247  
248 $n = $ln->length;
249  
250 =head4 Description
251  
252 Liefere die Länge der Zeile.
253  
254 =cut
255  
256 # -----------------------------------------------------------------------------
257  
258 2 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod documented
259 2 return CORE::length shift->[0];
260 }
261  
262 # -----------------------------------------------------------------------------
263  
264 =head2 Operationen
265  
266 =head3 append() - Füge Text zu Zeile hinzu
267  
268 =head4 Synopsis
269  
270 $ln->append($text);
271  
272 =head4 Description
273  
274 Füge $text zu Zeile $ln hinzu. Die Methode liefert keinen Wert zurück.
275  
276 =cut
277  
278 # -----------------------------------------------------------------------------
279  
280 1 ▶sub append {
Subroutine append: called CC=1 SCAR=0.0
Pod documented
281 1 my ($self,$text) = @_;
282 1 $self->[0] .= $text;
283 1 return;
284 }
285  
286 # -----------------------------------------------------------------------------
287  
288 =head3 trim() - Entferne Whitespace am Anfang und Ende
289  
290 =head4 Synopsis
291  
292 $ln->trim;
293  
294 =head4 Description
295  
296 Entferne Whitespace am Anfang und am Ende der Zeile. Die Methode
297 liefert keinen Wert zurück.
298  
299 =cut
300  
301 # -----------------------------------------------------------------------------
302  
303 1 ▶sub trim {
Subroutine trim: called CC=1 SCAR=0.0
Pod documented
304 1 my $self = shift;
305 1 $self->[0] =~ s/^\s+//;
306 1 $self->[0] =~ s/\s+$//;
307 1 return;
308 }
309  
310 # -----------------------------------------------------------------------------
311  
312 =head3 unindent() - Entferne Einrückung
313  
314 =head4 Synopsis
315  
316 $ln->unindent($n);
317  
318 =head4 Description
319  
320 Entferne die ersten $n Zeichen von der Zeile. Die Methode liefert
321 keinen Wert zurück.
322  
323 =cut
324  
325 # -----------------------------------------------------------------------------
326  
327 1 ▶sub unindent {
Subroutine unindent: called CC=1 SCAR=0.0
Pod documented
328 1 my ($self,$n) = @_;
329 1 $self->[0] = substr $self->[0],$n;
330 1 return;
331 }
332  
333 # -----------------------------------------------------------------------------
334  
335 =head2 Externe Repräsentation
336  
337 =head3 dump() - Liefere externe Repräsentation
338  
339 =head4 Synopsis
340  
341 $str = $ln->dump($format);
342 $str = $ln->dump;
343  
344 =head4 Description
345  
346 Erzeuge eine externe Zeilenrepräsentation in Format $format
347 und liefere diese zurück.
348  
349 B<Formate>
350  
351 =over 4
352  
353 =item Z<>0
354  
355 Text der Zeile plus Newline (Default).
356  
357 =item Z<>1
358  
359 Text der Zeile plus Newline und vorangestellter
360 Zeilennummer im Format:
361  
362 NNNN: TEXT
363  
364 =back
365  
366 =cut
367  
368 # -----------------------------------------------------------------------------
369  
370 7 ▶sub dump {
Subroutine dump: called CC=4 SCAR=14.3
Pod documented
371 7 my $self = shift;
372 7 ▶ my $format = shift || 0;
Condition100%2/2
shift() || 0
l!l
16
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
373  
374 7 ▶ unless ($format) {
Branch: 2 branches
BranchTrueFalseTotal
if ($format) { } 1 6 7
if (do { $format == 1 }) 1 0 1
375 6 return $self->[0]."\n";
376 }
377 0 elsif ($format == 1) {
378 1 return sprintf "%4d: %s\n",$self->[1],$self->[0];
379 }
380  
381 $self->throw(
382 0 'LINE-00001: Ungültiges Ausgabeformat',
383 Format => $format,
384 );
385 }
386  
387 # -----------------------------------------------------------------------------
388  
389 =head1 VERSION
390  
391 1.240
392  
393 =head1 AUTHOR
394  
395 Frank Seitz, L<http://fseitz.de/>
396  
397 =head1 COPYRIGHT
398  
399 Copyright (C) 2026 Frank Seitz
400  
401 =head1 LICENSE
402  
403 This code is free software; you can redistribute it and/or modify
404 it under the same terms as Perl itself.
405  
406 =cut
407  
408 # -----------------------------------------------------------------------------
409  
410 2 1;
411  
412 # eof
« Quiq/ContentProcessor/BaseType.pm ↑ Summary Quiq/Css/Snippets.pm »