| 1 | # ----------------------------------------------------------------------------- | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Quiq::Debug - Hilfe beim Debuggen von Programmen | ||||||||||
| 8 | |||||||||||
| 9 | =head1 BASE CLASS | ||||||||||
| 10 | |||||||||||
| 11 | L<Quiq::Object> | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | # ----------------------------------------------------------------------------- | ||||||||||
| 16 | |||||||||||
| 17 | package Quiq::Debug; | ||||||||||
| 18 | 4 | ▶ | use base qw/Quiq::Object/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 4 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 4 | our $VERSION = '1.240'; | |||||||||
| 25 | |||||||||||
| 26 | 4 | ▶ | use Data::Printer color=>{string=>'black'}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 4 | ▶ | use Data::Printer (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 4 | ▶ | use Quiq::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 4 | ▶ | use Quiq::Shell; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 4 | ▶ | use Quiq::Terminal; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 4 | ▶ | use Encode (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | # ----------------------------------------------------------------------------- | ||||||||||
| 34 | |||||||||||
| 35 | =head1 METHODS | ||||||||||
| 36 | |||||||||||
| 37 | =head2 Datenstrukturen | ||||||||||
| 38 | |||||||||||
| 39 | =head3 dump() - Liefere Datenstruktur in lesbarer Form | ||||||||||
| 40 | |||||||||||
| 41 | =head4 Synopsis | ||||||||||
| 42 | |||||||||||
| 43 | $str = $this->dump($ref,@opt); | ||||||||||
| 44 | |||||||||||
| 45 | =head4 Arguments | ||||||||||
| 46 | |||||||||||
| 47 | =over 4 | ||||||||||
| 48 | |||||||||||
| 49 | =item $ref | ||||||||||
| 50 | |||||||||||
| 51 | Referenz auf eine Datenstruktur. | ||||||||||
| 52 | |||||||||||
| 53 | =item @opt | ||||||||||
| 54 | |||||||||||
| 55 | Optionen der Funktion np() des Moduls Data::Printer. Dokumentation siehe | ||||||||||
| 56 | dort. | ||||||||||
| 57 | |||||||||||
| 58 | =back | ||||||||||
| 59 | |||||||||||
| 60 | =head4 Description | ||||||||||
| 61 | |||||||||||
| 62 | Liefere eine Perl-Datenstruktur beliebiger Tiefe in lesbarer Form | ||||||||||
| 63 | als Zeichenkette, so dass sie zu Debugzwecken ausgegeben werden kann. | ||||||||||
| 64 | Die Methode nutzt das Modul Data::Printer und davon die Funktion | ||||||||||
| 65 | np(). Die Optionen @opt werden an diese Funktion weiter geleitet. | ||||||||||
| 66 | |||||||||||
| 67 | =head4 Example | ||||||||||
| 68 | |||||||||||
| 69 | Quiq::Debug->dump($obj,colored=>1); | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||
| 73 | # ----------------------------------------------------------------------------- | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub dump { | ||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | 0 | my ($this,$ref) = splice @_,0,2; | |||||||||
| 77 | 0 | return Data::Printer::np($ref,@_); | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | # ----------------------------------------------------------------------------- | ||||||||||
| 81 | |||||||||||
| 82 | =head2 Module | ||||||||||
| 83 | |||||||||||
| 84 | =head3 modulePaths() - Pfade der geladenen Perl Moduldateien | ||||||||||
| 85 | |||||||||||
| 86 | =head4 Synopsis | ||||||||||
| 87 | |||||||||||
| 88 | $str = $this->modulePaths; | ||||||||||
| 89 | |||||||||||
| 90 | =head4 Description | ||||||||||
| 91 | |||||||||||
| 92 | Liefere eine Aufstellung der Pfade der aktuell geladenen | ||||||||||
| 93 | Perl Moduldateien. Ein Modulpfad pro Zeile, alphabetisch sortiert. | ||||||||||
| 94 | |||||||||||
| 95 | =head4 Example | ||||||||||
| 96 | |||||||||||
| 97 | Die aktuell geladenen Moduldateien auf STDOUT ausgeben: | ||||||||||
| 98 | |||||||||||
| 99 | print Quiq::Debug->modulePaths; | ||||||||||
| 100 | ==> | ||||||||||
| 101 | /home/fs/lib/perl5/Quiq/Debug.pm | ||||||||||
| 102 | /home/fs/lib/perl5/Quiq/Object.pm | ||||||||||
| 103 | /home/fs/lib/perl5/Perl/Quiq/Stacktrace.pm | ||||||||||
| 104 | /usr/share/perl/5.20/base.pm | ||||||||||
| 105 | /usr/share/perl/5.20/strict.pm | ||||||||||
| 106 | /usr/share/perl/5.20/vars.pm | ||||||||||
| 107 | /usr/share/perl/5.20/warnings.pm | ||||||||||
| 108 | /usr/share/perl/5.20/warnings/register.pm | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||
| 111 | |||||||||||
| 112 | # ----------------------------------------------------------------------------- | ||||||||||
| 113 | |||||||||||
| 114 | 1 | ▶ | sub modulePaths { | ||||||||
|
Subroutine
modulePaths: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 115 | 1 | my $this = shift; | |||||||||
| 116 | 1 | return join("\n",sort values %INC)."\n"; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | # ----------------------------------------------------------------------------- | ||||||||||
| 120 | |||||||||||
| 121 | =head2 Subroutines | ||||||||||
| 122 | |||||||||||
| 123 | =head3 findSubroutine() - Suche Subroutine | ||||||||||
| 124 | |||||||||||
| 125 | =head4 Synopsis | ||||||||||
| 126 | |||||||||||
| 127 | @arr | $str = $this->findSubroutine($pattern); | ||||||||||
| 128 | |||||||||||
| 129 | =head4 Description | ||||||||||
| 130 | |||||||||||
| 131 | Suche die Subroutines, die den Pattern $pattern erfüllen, in den | ||||||||||
| 132 | Moduldateien (.pm) entlang der Pfade in @INC. Im Array-Kontext liefere die | ||||||||||
| 133 | Liste der Modulnamen, im Skalarkontext die Liste als Zeichenkette (ein | ||||||||||
| 134 | Modulpfad pro Zeile). | ||||||||||
| 135 | |||||||||||
| 136 | =head4 Example | ||||||||||
| 137 | |||||||||||
| 138 | B<ANPASSEN> | ||||||||||
| 139 | |||||||||||
| 140 | Die aktuell geladenen Moduldateien auf STDOUT ausgeben: | ||||||||||
| 141 | |||||||||||
| 142 | print Quiq::Debug->findSubroutine; | ||||||||||
| 143 | ==> | ||||||||||
| 144 | /home/fs/lib/perl5/Quiq/Debug.pm | ||||||||||
| 145 | /home/fs/lib/perl5/Quiq/Object.pm | ||||||||||
| 146 | /home/fs/lib/perl5/Perl/Quiq/Stacktrace.pm | ||||||||||
| 147 | /usr/share/perl/5.20/base.pm | ||||||||||
| 148 | /usr/share/perl/5.20/strict.pm | ||||||||||
| 149 | /usr/share/perl/5.20/vars.pm | ||||||||||
| 150 | /usr/share/perl/5.20/warnings.pm | ||||||||||
| 151 | /usr/share/perl/5.20/warnings/register.pm | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | # ----------------------------------------------------------------------------- | ||||||||||
| 156 | |||||||||||
| 157 | 0 | ▶ | sub findSubroutine { | ||||||||
|
Subroutine
findSubroutine: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 158 | 0 | my ($this,$pattern) = @_; | |||||||||
| 159 | |||||||||||
| 160 | 0 | my $p = Quiq::Path->new; | |||||||||
| 161 | |||||||||||
| 162 | 0 | $pattern = qr/(sub\s+$pattern)/; | |||||||||
| 163 | |||||||||||
| 164 | 0 | my @modules; | |||||||||
| 165 | 0 | for my $dir (@INC) { | |||||||||
| 166 | 0 | ▶ | if (!-d $dir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 167 | 0 | next; | |||||||||
| 168 | } | ||||||||||
| 169 | # say "*** $dir ***"; | ||||||||||
| 170 | 0 | my @files = $p->find($dir,-pattern=>qr/\.pm$/); | |||||||||
| 171 | 0 | for my $file (@files) { | |||||||||
| 172 | 0 | my $data = $p->read($file); | |||||||||
| 173 | 0 | ▶ | if ($data =~ /$pattern/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | 0 | say "*** $file ***"; | |||||||||
| 175 | 0 | ▶ | while ($data =~ /$pattern/g) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 176 | 0 | say $1; | |||||||||
| 177 | } | ||||||||||
| 178 | } | ||||||||||
| 179 | } | ||||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | 0 | return; | |||||||||
| 183 | } | ||||||||||
| 184 | |||||||||||
| 185 | # ----------------------------------------------------------------------------- | ||||||||||
| 186 | |||||||||||
| 187 | =head2 Textvergleich | ||||||||||
| 188 | |||||||||||
| 189 | =head3 showDiff() - Zeige Differenz zwischen zwei Dateien | ||||||||||
| 190 | |||||||||||
| 191 | =head4 Synopsis | ||||||||||
| 192 | |||||||||||
| 193 | $str = $this->showDiff($file1,$file2,@opt); | ||||||||||
| 194 | |||||||||||
| 195 | =head4 Options | ||||||||||
| 196 | |||||||||||
| 197 | =over 4 | ||||||||||
| 198 | |||||||||||
| 199 | =item -verbose => $bool (Default: 0) | ||||||||||
| 200 | |||||||||||
| 201 | Liefere in der ersten Zeile das Diff-Kommando. | ||||||||||
| 202 | |||||||||||
| 203 | =back | ||||||||||
| 204 | |||||||||||
| 205 | =head4 Description | ||||||||||
| 206 | |||||||||||
| 207 | Zeige die Differenz zwischen zwei Dateien. Die Anzeige wird auf die | ||||||||||
| 208 | Breite des Terminals eingestellt. | ||||||||||
| 209 | |||||||||||
| 210 | =head4 Example | ||||||||||
| 211 | |||||||||||
| 212 | perl -MQuiq::Debug -E 'print Quiq::Debug->showDiff($file1,$file2)' | less | ||||||||||
| 213 | |||||||||||
| 214 | =cut | ||||||||||
| 215 | |||||||||||
| 216 | # ----------------------------------------------------------------------------- | ||||||||||
| 217 | |||||||||||
| 218 | 0 | ▶ | sub showDiff { | ||||||||
|
Subroutine
showDiff: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 219 | 0 | my ($this,$file1,$file2) = splice @_,0,3; | |||||||||
| 220 | |||||||||||
| 221 | # Optionen | ||||||||||
| 222 | |||||||||||
| 223 | 0 | my $verbose = 0; | |||||||||
| 224 | |||||||||||
| 225 | 0 | $this->parameters(\@_, | |||||||||
| 226 | -verbose => \$verbose, | ||||||||||
| 227 | ); | ||||||||||
| 228 | |||||||||||
| 229 | # Operation ausführen | ||||||||||
| 230 | |||||||||||
| 231 | 0 | my $sh = Quiq::Shell->new; | |||||||||
| 232 | |||||||||||
| 233 | 0 | my $str = ''; | |||||||||
| 234 | 0 | my $width = Quiq::Terminal->width; | |||||||||
| 235 | 0 | my $cmd = "diff -W $width -b -y $file1 $file2"; | |||||||||
| 236 | 0 | ▶ | if ($verbose) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 237 | 0 | $str = "*** $cmd ***\n"; | |||||||||
| 238 | } | ||||||||||
| 239 | 0 | $str .= $sh->exec($cmd, | |||||||||
| 240 | -sloppy => 1, | ||||||||||
| 241 | -capture => 'stdout', | ||||||||||
| 242 | ); | ||||||||||
| 243 | |||||||||||
| 244 | 0 | return $str; | |||||||||
| 245 | } | ||||||||||
| 246 | |||||||||||
| 247 | # ----------------------------------------------------------------------------- | ||||||||||
| 248 | |||||||||||
| 249 | =head3 showRdiff() - Zeige Differenz einer Datei in zwei Verzeichnissen, lokal und remote | ||||||||||
| 250 | |||||||||||
| 251 | =head4 Synopsis | ||||||||||
| 252 | |||||||||||
| 253 | $str = $this->showRdiff($lRoot,$rRoot,$file,%options); | ||||||||||
| 254 | |||||||||||
| 255 | =head4 Arguments | ||||||||||
| 256 | |||||||||||
| 257 | =over 4 | ||||||||||
| 258 | |||||||||||
| 259 | =item $lRoot | ||||||||||
| 260 | |||||||||||
| 261 | Lokales Wurzelverzeichnis | ||||||||||
| 262 | |||||||||||
| 263 | =item $rRoot | ||||||||||
| 264 | |||||||||||
| 265 | Remote Wurzelverzeichnis (per ssh erreichbar) | ||||||||||
| 266 | |||||||||||
| 267 | =back | ||||||||||
| 268 | |||||||||||
| 269 | =head4 Options | ||||||||||
| 270 | |||||||||||
| 271 | =over 4 | ||||||||||
| 272 | |||||||||||
| 273 | =item -commandOnly => $bool (Default: 0) | ||||||||||
| 274 | |||||||||||
| 275 | Zeige nur das Kommando, führe es jedoch nicht aus. | ||||||||||
| 276 | |||||||||||
| 277 | =back | ||||||||||
| 278 | |||||||||||
| 279 | =head4 Returns | ||||||||||
| 280 | |||||||||||
| 281 | (String) Differenz, wie sie von diff(1) dargestellt wird. | ||||||||||
| 282 | |||||||||||
| 283 | =head4 Description | ||||||||||
| 284 | |||||||||||
| 285 | Das Kommando ermittelt die Differenz einer Datei in zwei Verzeichnissen | ||||||||||
| 286 | mit der gleichen Struktur, wobei das eine Verzeichnis lokal und das | ||||||||||
| 287 | andere remote ist, und liefert diese Differenz zurück. | ||||||||||
| 288 | |||||||||||
| 289 | =head4 Example | ||||||||||
| 290 | |||||||||||
| 291 | Differenz einer Datei in ZUGFeRD-Installation in Entwicklungs- | ||||||||||
| 292 | und Produktivumgebung: | ||||||||||
| 293 | |||||||||||
| 294 | $ perl -MQuiq::Debug -E 'print Quiq::Debug->showRdiff($ENV{"ZUGFERD_HOME"},"z3po\@z3po:/opt/Zugferd","etc/niederlassung.csv")' | ||||||||||
| 295 | |||||||||||
| 296 | =cut | ||||||||||
| 297 | |||||||||||
| 298 | # ----------------------------------------------------------------------------- | ||||||||||
| 299 | |||||||||||
| 300 | 0 | ▶ | sub showRdiff { | ||||||||
|
Subroutine
showRdiff: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 301 | 0 | my $this = shift; | |||||||||
| 302 | |||||||||||
| 303 | # Argumente und Optionen | ||||||||||
| 304 | |||||||||||
| 305 | 0 | my $commandOnly = 0; | |||||||||
| 306 | |||||||||||
| 307 | 0 | my $argA = $this->parameters(3,3,\@_, | |||||||||
| 308 | -commandOnly => \$commandOnly, | ||||||||||
| 309 | ); | ||||||||||
| 310 | 0 | my ($lRoot,$rRoot,$file) = @$argA; | |||||||||
| 311 | |||||||||||
| 312 | # Operation ausführen | ||||||||||
| 313 | |||||||||||
| 314 | 0 | my $sh = Quiq::Shell->new; | |||||||||
| 315 | |||||||||||
| 316 | 0 | my ($login,$root) = split /:/,$rRoot,2; | |||||||||
| 317 | |||||||||||
| 318 | 0 | my $cmd = "ssh $login cat $root/$file | diff $lRoot/$file -"; | |||||||||
| 319 | 0 | my $str = $sh->exec($cmd,-sloppy=>1,-capture=>'stdout+stderr'); | |||||||||
| 320 | # $str = Encode::decode('UTF-8',$str); | ||||||||||
| 321 | |||||||||||
| 322 | 0 | return $str; | |||||||||
| 323 | } | ||||||||||
| 324 | |||||||||||
| 325 | # ----------------------------------------------------------------------------- | ||||||||||
| 326 | |||||||||||
| 327 | =head1 VERSION | ||||||||||
| 328 | |||||||||||
| 329 | 1.240 | ||||||||||
| 330 | |||||||||||
| 331 | =head1 AUTHOR | ||||||||||
| 332 | |||||||||||
| 333 | Frank Seitz, L<http://fseitz.de/> | ||||||||||
| 334 | |||||||||||
| 335 | =head1 COPYRIGHT | ||||||||||
| 336 | |||||||||||
| 337 | Copyright (C) 2026 Frank Seitz | ||||||||||
| 338 | |||||||||||
| 339 | =head1 LICENSE | ||||||||||
| 340 | |||||||||||
| 341 | This code is free software; you can redistribute it and/or modify | ||||||||||
| 342 | it under the same terms as Perl itself. | ||||||||||
| 343 | |||||||||||
| 344 | =cut | ||||||||||
| 345 | |||||||||||
| 346 | # ----------------------------------------------------------------------------- | ||||||||||
| 347 | |||||||||||
| 348 | 4 | 1; | |||||||||
| 349 | |||||||||||
| 350 | # eof | ||||||||||