Quiq/Dumper.pm

filter: Statementstmt 88.7% 63 / 71 Branchbran 66.6% 24 / 36 Conditioncond 50.0% 8 / 16 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 74.4% 105 / 141 CC 26 SCAR 35.0
CC
26
Cov
77%
dump
40.4
BEGIN
1.0
BEGIN
1.0
CRAP 33.0
« Quiq/Shell.pm ↑ Summary Quiq/JQuery/DataTable.pm »
1 # -----------------------------------------------------------------------------
2  
3 =head1 NAME
4  
5 Quiq::Dumper - Ausgabe Datenstruktur
6  
7 =head1 BASE CLASS
8  
9 L<Quiq::Object>
10  
11 =cut
12  
13 # -----------------------------------------------------------------------------
14  
15 package Quiq::Dumper;
16 2 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 our $VERSION = '1.240';
23  
24 2 ▶use Quiq::AnsiColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # -----------------------------------------------------------------------------
28  
29 =head1 METHODS
30  
31 =head2 Klassenmethoden
32  
33 =head3 dump() - Liefere Datenstruktur in lesbarer Form
34  
35 =head4 Synopsis
36  
37 $str = $this->dump($scalar);
38  
39 =head4 Arguments
40  
41 =over 4
42  
43 =item $scalar
44  
45 Referenz auf eine Datenstruktur.
46  
47 =back
48  
49 =head4 Description
50  
51 Liefere eine Perl-Datenstruktur beliebiger Tiefe in lesbarer Form
52 als Zeichenkette, so dass sie zu Debugzwecken ausgegeben werden kann.
53  
54 Wenn die Klassenvariable $NoClassNames gesetzt ist, unterbleibt die
55 Ausgabe eines evtl. gegebenen Klassennamens vor einer geblessten
56 Struktur:
57  
58 $Quiq::Dumper::NoClassNames = 1;
59  
60 =head4 Example
61  
62 Quiq::Dumper->dump($obj);
63  
64 =cut
65  
66 # -----------------------------------------------------------------------------
67  
68 2 my $maxDepth = undef;
69 2 my $a = Quiq::AnsiColor->new(1);
70 2 our $NoClassNames = 0;
71  
72 15 ▶sub dump {
Subroutine dump: called CC=26 SCAR=37.0
Pod documented
73 15 my ($this,$arg) = splice @_,0,2;
74 15 ▶ my $depth = shift // 0;
Condition100%2/2
shift() // 0
l!l
87
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
75 15 ▶ my $seenH = shift // {};
Condition100%2/2
shift() // {}
l!l
87
MC/DC100%1/1
shift() // {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
76  
77 15 $depth++;
78  
79 # Skalar
80  
81 15 ▶ if (!ref $arg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $arg) 10 5 15
82 10 ▶ if (!defined $arg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arg) 2 8 10
83 2 return 'undef';
84 }
85 8 $arg =~ s/\n/\\n/g;
86 8 $arg =~ s/\r/\\r/g;
87 8 return qq|"$arg"|;
88 }
89  
90 # Referenz
91  
92 5 ▶ if ($seenH->{$arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seenH->{$arg}) 0 5 5
93 0 return "SEEN $arg";
94 }
95 5 $seenH->{$arg}++;
96  
97 5 my $ref = ref $arg;
98 5 my $refType = Scalar::Util::reftype($arg);
99  
100 5 ▶ if ($refType eq 'SCALAR') {
Branch: 6 branches
BranchTrueFalseTotal
if ($refType eq 'SCALAR') { } 2 3 5
elsif ($refType eq 'ARRAY') { } 1 2 3
elsif ($refType eq 'HASH') { } 1 1 2
elsif ($refType eq 'REGEXP') { } 1 0 1
elsif ($refType eq 'CODE') { } 0 0 0
elsif ($refType eq 'GLOB') { } 0 0 0
101 2 return '\\'.$this->dump($$arg,$depth,$seenH);
102 }
103 elsif ($refType eq 'ARRAY') {
104 1 my $str = '';
105 1 ▶ if (!defined($maxDepth) || $depth <= $maxDepth) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $maxDepth or $depth <= $maxDepth) { } 1 0 1
Condition33%1/3
not defined $maxDepth or $depth <= $maxDepth
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $maxDepth or $depth <= $maxDepth
not defined $maxDepth $depth <= $maxDepth
Truth table33%1/3
not(A) or B
A= not defined $maxDepthB= $depth <= $maxDepth
ABresult
1X1
011
000
106 1 ▶ for (my $i = 0; $i < @$arg; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$arg) 3 1 4
107 3 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 2 1 3
108 2 $str .= ",\n";
109 }
110 3 $str .= $this->dump($arg->[$i],$depth,$seenH);
111 }
112 1 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 1 0 1
113 1 $str =~ s/^/ /mg;
114 1 $str = "\n$str\n";
115 }
116 }
117 else {
118 0 $str = @$arg;
119 }
120 1 $str = "[$str]";
121 1 ▶ if (!$NoClassNames && $refType ne $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Quiq::Dumper::NoClassNames and $refType ne $ref) 0 1 1
Condition33%1/3
not $Quiq::Dumper::NoClassNames and $refType ne $ref
!ll&&!rl&&r
010
MC/DC0%0/2
not $Quiq::Dumper::NoClassNames and $refType ne $ref
not $Quiq::Dumper::NoClassNames $refType ne $ref
Truth table33%1/3
not(A) and B
A= not $Quiq::Dumper::NoClassNamesB= $refType ne $ref
ABresult
0X0
100
111
122 0 $str = $a->str('bold dark blue',$ref).' '.$str;
123 }
124 1 return $str;
125 }
126 elsif ($refType eq 'HASH') {
127 1 my $str = '';
128 1 ▶ if (!defined($maxDepth) || $depth <= $maxDepth) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $maxDepth or $depth <= $maxDepth) { } 1 0 1
Condition33%1/3
not defined $maxDepth or $depth <= $maxDepth
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $maxDepth or $depth <= $maxDepth
not defined $maxDepth $depth <= $maxDepth
Truth table33%1/3
not(A) or B
A= not defined $maxDepthB= $depth <= $maxDepth
ABresult
1X1
011
000
129 1 for my $key (sort keys %$arg) {
130 3 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 2 1 3
131 2 $str .= ",\n";
132 }
133 3 $str .= "'$key' => ".$this->dump($arg->{$key},$depth,$seenH);
134 }
135 1 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 1 0 1
136 1 $str =~ s/^/ /mg;
137 1 $str = "\n$str\n";
138 }
139 }
140 else {
141 0 $str = keys %$arg;
142 }
143 1 $str = "{$str}";
144 1 ▶ if (!$NoClassNames && $refType ne $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Quiq::Dumper::NoClassNames and $refType ne $ref) 0 1 1
Condition33%1/3
not $Quiq::Dumper::NoClassNames and $refType ne $ref
!ll&&!rl&&r
010
MC/DC0%0/2
not $Quiq::Dumper::NoClassNames and $refType ne $ref
not $Quiq::Dumper::NoClassNames $refType ne $ref
Truth table33%1/3
not(A) and B
A= not $Quiq::Dumper::NoClassNamesB= $refType ne $ref
ABresult
0X0
100
111
145 0 $str = $a->str('bold dark blue',$ref).' '.$str;
146 }
147 1 return $str;
148 }
149 elsif ($refType eq 'REGEXP') {
150 1 return "/$arg/";
151 }
152 elsif ($refType eq 'CODE') {
153 # FIXME: nicht richtig ausgearbeitet
154 0 return "CODE: $arg";
155 }
156 elsif ($refType eq 'GLOB') {
157 # FIXME: nicht richtig ausgearbeitet
158 0 return "GLOB: $arg";
159 }
160  
161 $this->throw(
162 0 'DUMPER-00002: Unknown reference type',
163 ReferenceType => "$refType - $arg",
164 );
165 }
166  
167 # -----------------------------------------------------------------------------
168  
169 =head1 VERSION
170  
171 1.240
172  
173 =head1 AUTHOR
174  
175 Frank Seitz, L<http://fseitz.de/>
176  
177 =head1 COPYRIGHT
178  
179 Copyright (C) 2026 Frank Seitz
180  
181 =head1 LICENSE
182  
183 This code is free software; you can redistribute it and/or modify
184 it under the same terms as Perl itself.
185  
186 =cut
187  
188 # -----------------------------------------------------------------------------
189  
190 2 1;
191  
192 # eof
« Quiq/Shell.pm ↑ Summary Quiq/JQuery/DataTable.pm »