Subversion Repositories DevTools

Rev

Rev 6177 | Rev 6276 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 3
#
279 dpurdie 4
# Module name   : JatsError
227 dpurdie 5
# Module type   : Perl Package
279 dpurdie 6
# Compiler(s)   : Perl
227 dpurdie 7
# Environment(s): jats
8
#
9
# Description   : A Perl Package to perform error handling within JATS
10
#
11
#                 Uses global variables
12
#                       $::ScmVerbose;
13
#                       $::ScmQuiet;
14
#                       $::ScmDebug;
15
#                 For use with existing scripts
16
#
17
#......................................................................#
18
 
283 dpurdie 19
package JatsError;
20
use base qw(Exporter);
21
 
255 dpurdie 22
require 5.006_001;
227 dpurdie 23
use strict;
24
use warnings;
25
use Data::Dumper;
26
use IO::Handle;
27
 
6198 dpurdie 28
# exported package globals go here
29
#our $ScmVerbose;
30
#our $ScmDebug;
31
#our $ScmQuiet;
32
our $ScmOnExit;
33
our $ScmDelayExit;
34
our $ScmErrorCount;
35
our $ScmExitCode;
36
 
37
my $EPrefix = '';
38
my $EName = '';
39
my $EFn = '';
40
my $ElPrefix = '';
41
my $EIndent = '';
42
my $EOffset = '';
43
 
227 dpurdie 44
#-------------------------------------------------------------------------------
45
# Function        : BEGIN
46
#
47
# Description     : Standard Package Interface
48
#
49
# Inputs          :
50
#
51
# Returns         :
52
#
53
 
54
BEGIN {
283 dpurdie 55
    our ($VERSION, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
227 dpurdie 56
 
57
    # set the version for version checking
58
    $VERSION     = 1.00;
59
 
279 dpurdie 60
    @EXPORT      = qw(ErrorConfig ErrorReConfig ErrorDoExit
261 dpurdie 61
                      ReportError Fatal Error Warning
227 dpurdie 62
                      Message Message1
63
                      Information Information1
64
                      Question
263 dpurdie 65
                      Verbose0 Verbose Verbose2 Verbose3
227 dpurdie 66
                      Debug0 Debug Debug2 Debug3
67
                      IsVerbose IsDebug IsQuiet
231 dpurdie 68
                      DebugDumpData DebugDumpPackage DebugTraceBack
227 dpurdie 69
                      DebugPush DebugPop
5109 dpurdie 70
                      StartCapture
71
                      DumpCapture
227 dpurdie 72
                      );
73
 
74
    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
75
 
76
    # your exported package globals go here,
77
    # as well as any optionally exported functions
78
    @EXPORT_OK   = qw();
79
 
80
    #
81
    #   Ensure globals have a defined value
82
    #
263 dpurdie 83
    $::ScmVerbose = $ENV{GBE_VERBOSE} || 0  unless defined( $::ScmVerbose );
84
    $::ScmDebug = $ENV{GBE_DEBUG} || 0      unless defined( $::ScmDebug );
85
    $::ScmQuiet = 0                         unless defined( $::ScmQuiet );
227 dpurdie 86
 
6198 dpurdie 87
    $ScmErrorCount = 0;
88
    $ScmExitCode = 1;
89
 
227 dpurdie 90
    #
91
    #   Force autoflush in an attempt to limit the intermingling of
92
    #   Error and non-error output.
93
    #
94
    STDOUT->autoflush(1);
95
    STDERR->autoflush(1);
96
}
97
 
98
# non-exported package globals go here
5109 dpurdie 99
my @captured;
100
my $capturing;
279 dpurdie 101
 
227 dpurdie 102
#-------------------------------------------------------------------------------
103
# Function        : import
104
#
105
# Description     : Package import function
279 dpurdie 106
#                   This function will examine arguments provided in the
227 dpurdie 107
#                   invoking 'uses' list and will configure the package
108
#                   accordingly.
109
#
110
# Inputs          : $pack           - Name of this package
111
#                   @vars           - User Config Options
112
#                   Config Options:
113
#                       :name=xxxx
279 dpurdie 114
#                       :function=xxxx
6198 dpurdie 115
#                       :prefix=xxxx
116
#                       :indent=nn/xxx
117
#                       :offset=nn/xxx
227 dpurdie 118
#                       :quiet=xxx
119
#                       :debug=xxx
120
#                       :verbose=xxx
121
#                       :delay_exit=xxx
122
#
123
# Returns         : 
124
#
125
sub import {
126
    my $pack = shift;
127
    my @vars;
128
    my @config;
129
 
130
    #
131
    #   Extract options of the form: :name=value and pass them to the
132
    #   ErrorConfig function. All other arguments will be passed to the
133
    #
134
    foreach ( @_ )
135
    {
136
        if ( m/^:(.+)=(.+)/ ) {
137
            push @config, $1, $2;
138
        } else {
139
            push @vars, $_;
140
        }
141
    }
142
 
143
    ErrorConfig( @config )
144
        if ( @config );
145
 
146
    #
147
    #   Invoke Exporter function to handle the arguments that I don't understand
148
    #
149
    $pack->export_to_level(1, $pack , @vars);
150
}
151
 
152
#-------------------------------------------------------------------------------
153
# Function        : ErrorConfig
154
#
155
# Description     : Configure aspects of the JATS error handle
279 dpurdie 156
#                   See ErrorReConfig
227 dpurdie 157
#
158
# Inputs          : A hash of option,value pairs
159
#                   Valid options
160
#                       name        - Name to report in error
279 dpurdie 161
#                       function    - Name of enclosing function
6198 dpurdie 162
#                       prefix      - 1st line prefix
227 dpurdie 163
#                       verbose     - vebosity level
164
#                       debug       - debug level
165
#                       on_exit     - Register on-exit function
166
#                       delay_exit  - Delay exit on error
6198 dpurdie 167
#                       prefix      - Optional prefix. First line only
168
#                       indent      - Optional. All lines (number or text)
169
#                       offset      - Optional. Extra lines (number or text)
227 dpurdie 170
#
171
# Returns         :
172
#
173
sub ErrorConfig
174
{
175
    my %args = @_;
176
 
177
    while (my($key, $value) = each %args)
178
    {
6198 dpurdie 179
        if ( $key =~ /^name/ ) {
279 dpurdie 180
            $EName = $value;
227 dpurdie 181
 
279 dpurdie 182
        } elsif ( $key =~ /^function/ ) {
183
            $EFn = ':' . $value;
184
 
6198 dpurdie 185
        } elsif ( $key =~ /^prefix/ ) {
186
            $ElPrefix = $value;
187
 
188
        } elsif ( $key =~ /^indent/ ) {
189
            my $pad = $value;
190
            if ($pad =~ m~^\d+$~) {
191
                $pad = ' ' x $value;
192
            }
193
            $EIndent = $EIndent . $pad;
194
 
195
        } elsif ( $key =~ /^offset/ ) {
196
            $EOffset = $value;
197
            if ($EOffset =~ m~^\d+$~) {
198
                $EOffset = ' ' x $value;
199
            }
200
 
227 dpurdie 201
        } elsif ( $key =~ /^debug/ ) {
279 dpurdie 202
            $::ScmDebug = $value
203
                if ( defined $value && $value > $::ScmDebug  );
227 dpurdie 204
 
205
        } elsif ( $key =~ /^verbose/ ) {
279 dpurdie 206
            $::ScmVerbose = $value
207
                if ( defined $value && $value > $::ScmVerbose  );
227 dpurdie 208
 
209
        } elsif ( $key =~ /^quiet/ ) {
210
            $::ScmQuiet = $value || 0;
211
 
212
        } elsif ( $key =~ /^on_exit/ ) {
213
            $ScmOnExit = $value;
214
 
215
        } elsif ( $key =~ /^delay_exit/ ) {
216
            $ScmDelayExit = $value;
217
 
2429 dpurdie 218
        } elsif ( $key =~ /^exitCode/i ) {
219
            $ScmExitCode = $value || 1;
220
 
227 dpurdie 221
        } else {
222
            Error("ErrorConfig, Unknown option: $key");
223
        }
224
    }
225
 
226
    #
279 dpurdie 227
    #   Calculate the prefix to all messages
228
    #   Based on Name and Function( if provided
229
    #
6198 dpurdie 230
    $EPrefix = "[$EName$EFn] " if $EName;
279 dpurdie 231
 
232
    #
227 dpurdie 233
    #   Extract program specfic debug flags from the environment
234
    #   These will be based on the reporting 'name'
235
    #       GBE_name_DEBUG
236
    #       GBE_name_VERBOSE
237
    #
279 dpurdie 238
    if ( $EName )
227 dpurdie 239
    {
240
        my ($value, $tag);
241
 
279 dpurdie 242
        $tag = "GBE_${EName}_DEBUG" ;
261 dpurdie 243
        $tag =~ s~\s+~~g;
227 dpurdie 244
        $value = $ENV{ $tag };
245
        if (defined $value)
246
        {
247
            $::ScmDebug = $value;
248
            Warning("Envar: $tag setting debug: $value");
249
        }
250
 
279 dpurdie 251
        $tag = "GBE_${EName}_VERBOSE" ;
261 dpurdie 252
        $tag =~ s~\s+~~g;
227 dpurdie 253
        $value = $ENV{ $tag };
254
        if (defined $value)
255
        {
256
            $::ScmVerbose = $value;
257
            Warning("Envar: $tag setting verbose: $value");
258
        }
259
    }
260
 
261
    #
262
    #   Sanitise quiet and verbose
263
    #   Any verboseness disables quiet
264
    #
265
    $::ScmQuiet = 0 if ( $::ScmVerbose );
266
    $::ScmQuiet = 0 if ( $::ScmDebug );
267
}
268
 
279 dpurdie 269
#-------------------------------------------------------------------------------
270
# Function        : ErrorReConfig
271
#
272
# Description     : Similar to ErrorConfig , except it is used to push and
273
#                   automatically pop the current state
274
#
275
#                   Intended to be used to control error reporting
276
#                   within a function. Let the class go out of scope
277
#                   at the end of the function.
278
#
279
#                   Not intended that the user hold and pass around the
280
#                   class ref as this may confuse all.
281
#
282
# Inputs          : As for ErrorConfig
283
#
284
# Returns         : Ref to a class
285
#                   When this goes out of scope the Error State will be
286
#                   restored.
287
#
288
sub ErrorReConfig
289
{
290
    #
291
    #   Create a small class to hold existing Error Information
292
    #   The error information will be restored when the handle returned to
293
    #   the user goes out of scope.
294
    #
295
    my $self;
227 dpurdie 296
 
6198 dpurdie 297
    $self->{EPrefix}        =  $EPrefix;
298
    $self->{ElPrefix}       =  $ElPrefix;
299
    $self->{EIndent}        =  $EIndent;
300
    $self->{EOffset}        =  $EOffset;
279 dpurdie 301
    $self->{ScmVerbose}     =  $::ScmVerbose;
302
    $self->{ScmDebug}       =  $::ScmDebug;
303
    $self->{ScmQuiet}       =  $::ScmQuiet;
304
    $self->{ScmOnExit}      =  $ScmOnExit;
305
    $self->{ScmDelayExit}   =  $ScmDelayExit;
306
    $self->{ScmErrorCount}  =  $ScmErrorCount;
307
    $self->{ScmExitCode}    =  $ScmExitCode;
308
    $self->{EName}          =  $EName;
309
    $self->{EFn}            =  $EFn;
310
 
311
    bless ($self, __PACKAGE__);
312
 
313
    #
314
    #   Invoke ErrorConfig to do the hard work
315
    #
316
    ErrorConfig (@_);
317
 
318
    #
319
    #   Return ref to stored data
320
    #
321
    return $self;
322
 
323
}
324
 
227 dpurdie 325
#-------------------------------------------------------------------------------
279 dpurdie 326
# Function        : DESTROY
327
#
6198 dpurdie 328
# Description     : Called when the handle returned by ErrorConfig goes out of
279 dpurdie 329
#                   scope.
330
#
331
#                   Restores the state of the Error Reporting information
332
#
333
# Inputs          : $self               - Created by ErrorReConfig
334
#
335
# Returns         : Nothing
336
#
337
 
338
sub DESTROY
339
{
340
    my ($self) = @_;
6198 dpurdie 341
    $EPrefix          = $self->{EPrefix};
342
    $ElPrefix         = $self->{ElPrefix};
343
    $EIndent          = $self->{EIndent};
344
    $EOffset          = $self->{EOffset};
279 dpurdie 345
    $::ScmVerbose     = $self->{ScmVerbose};
346
    $::ScmDebug       = $self->{ScmDebug};
347
    $::ScmQuiet       = $self->{ScmQuiet};
348
    $ScmOnExit        = $self->{ScmOnExit};
349
    $ScmDelayExit     = $self->{ScmDelayExit};
350
    $ScmErrorCount    = $self->{ScmErrorCount};
351
    $ScmExitCode      = $self->{ScmExitCode};
352
    $EFn              = $self->{EFn};
353
    $EName            = $self->{EName};
354
}
355
 
356
 
357
#-------------------------------------------------------------------------------
227 dpurdie 358
# Function        : Information
359
#                   Message
360
#                   Question
361
#                   Warning
362
#                   Error
363
#                   Verbose
364
#                   Debug
365
#                   _Message ( Internal use only )
366
#
367
# Description     : Error, Warning and Message routines
368
#                   These routines will display a message to the user
369
#                   with the module name.
370
#
371
#                   Multiple arguments are displayed on their own line
372
#                   with suitable spacing.
373
#
374
# Inputs          : Lines of text to display
375
#
376
# Returns         : Nothing
377
#
378
sub _Message
379
{
380
    my $tag = shift;                # First argument is a tag
381
    my $count = 0;
382
 
383
    #
384
    #   Generate the message prefix
385
    #   This will only be used on the first line
386
    #   All other lines will have a space filled prefix
387
    #
6198 dpurdie 388
    my $prefix = $EPrefix . $tag. $EIndent;
227 dpurdie 389
    #
390
    #   Kill the eol if the Question is being asked
391
    #
392
    my $eol = ( $tag =~ m/Q/ ) ? "" : "\n";
6198 dpurdie 393
    foreach my $nextline ( @_ ) {
231 dpurdie 394
        next unless ( defined $nextline );              # Ignore undefined arguments
227 dpurdie 395
        chomp( my $line = $nextline );
6198 dpurdie 396
        if ( $count == 0 ) {
397
            $line = ($ElPrefix || '') . $line;
398
 
399
        } elsif ( $count == 1 ) {
227 dpurdie 400
            my $bol = $eol ? "" : "\n";
6198 dpurdie 401
            $prefix = $bol . ' ' x length($prefix) . $EOffset;
227 dpurdie 402
        }
5109 dpurdie 403
        $count++;
227 dpurdie 404
 
6198 dpurdie 405
        if ($capturing && $tag =~ m/[MWEF]/) {
5109 dpurdie 406
            push @captured, "$prefix $line$eol" 
6198 dpurdie 407
 
408
        } else {
5109 dpurdie 409
            print "$prefix $line$eol";
410
        }
227 dpurdie 411
    }
412
}
413
 
414
#-------------------------------------------------------------------------------
415
# Function        : Information
416
#                   Information1
417
#
418
# Description     : Will display informational messages
419
#                   These are normal operational messages. These may be
420
#                   supressed through the use of QUIET options
421
#
422
# Inputs          : An array of strings to display
423
#
424
sub Information
425
{
426
    _Message '(I)', @_ unless ( $::ScmQuiet);
427
}
428
 
429
sub Information1
430
{
431
    _Message '(I)', @_ unless ( $::ScmQuiet > 1);
432
}
433
 
434
 
435
#-------------------------------------------------------------------------------
436
# Function        : Message
437
#                   Message1
438
#
439
# Description     : Same as Information, except a different prefix
440
#
441
# Inputs          : An array of strings to display
442
#
443
sub Message
444
{
445
    _Message '(M)', @_ unless ( $::ScmQuiet > 1);
446
}
447
 
448
sub Message1
449
{
450
    _Message '(M)', @_ unless ( $::ScmQuiet);
451
}
452
 
453
#-------------------------------------------------------------------------------
454
# Function        : IsQuiet
455
#
456
# Description     : Determine if an Infrmation or Message will be displayed
457
#                   May be used to reduce excessive processing that may be
458
#                   discarded
459
#
460
# Inputs          : $level      - Level to test
461
#
462
# Returns         : TRUE:       A Message at $level would be displayed
463
#
464
sub IsQuiet
465
{
466
    my( $level) = @_;
467
    return $::ScmQuiet >= $level;
468
}
469
 
470
#-------------------------------------------------------------------------------
471
# Function        : Warning
472
#
473
# Description     : Display a warning message
474
#                   These may be disabled with a high quiet level
475
#
476
# Inputs          : An array of strings to display
477
#
478
sub Warning
479
{
480
    _Message '(W)', @_ unless ( $::ScmQuiet > 2);
481
}
482
 
483
#-------------------------------------------------------------------------------
484
# Function        : Question
485
#
486
# Description     : Display a Question message
487
#                   These cannot be disabled
488
#
489
# Inputs          : An array of strings to display
490
#
491
sub Question
492
{
493
    _Message '(Q)', @_;
494
    STDERR->flush;              # Force output to be displayed
495
    STDOUT->flush;              # Force output to be displayed
496
}
497
 
498
#-------------------------------------------------------------------------------
261 dpurdie 499
# Function        : Fatal
500
#
501
# Description     : Display a multi line fatal message
502
#                   This will cause the program to exit.
503
#
504
#                   Similar to Error(), except
505
#                       Display a (F) prefix
506
#                       Alters the exit code to "2"
507
#                       Will terminate program execution.
508
#                       Will not honor delayed exit configuration.
509
#
510
#                   Fatal is to be used to indicate to consumer processes that
511
#                   the error is a function of the infrastructure and cannot be
512
#                   corrected by a user. ie:
513
#                       clearcase is not available
514
#                           Not just a bad user parameter
515
#                       dpkg_archive is not available
516
#                       release manager database is not available
517
#
518
#                   Intended to be used by build deamons to determine if building
519
#                   should continue, or if the entire build process should be
520
#                   terminated.
521
#
522
# Inputs          : An array of strings to display
523
#
524
# Returns         : May not return
525
#
526
sub Fatal
527
{
528
    _Message '(F)', @_;
529
    $ScmErrorCount++;
530
    $ScmExitCode = 2;
531
    ErrorDoExit() unless ( $ScmDelayExit );
532
}
533
 
534
#-------------------------------------------------------------------------------
227 dpurdie 535
# Function        : Error
536
#
261 dpurdie 537
# Description     : Display a multi line error message
227 dpurdie 538
#                   This may cause the program to exit, or the user may have
539
#                   configured the package to accumulate error messages
540
#
541
#                   This could be used to generate multiple error messages
542
#                   while parsing a file, and then terminate program execution at
543
#                   the end of the phase.
544
#
545
# Inputs          : An array of strings to display
2429 dpurdie 546
#                   First entry May be an exist code of the form
547
#                       ExitCode=nnn
227 dpurdie 548
#
549
# Returns         : May not return
550
#
551
 
552
sub Error
553
{
2429 dpurdie 554
    if ( $_[0] =~ m~^ExitCode=(\d+)$~i )
555
    {
556
        $ScmExitCode = $1 || 1;
557
        shift @_;
558
    }
227 dpurdie 559
    _Message '(E)', @_;
560
    $ScmErrorCount++;
561
    ErrorDoExit() unless ( $ScmDelayExit );
562
}
563
 
564
#-------------------------------------------------------------------------------
565
# Function        : ReportError
566
#
567
# Description     : Like Error, but the error exit is delayed
568
#
569
# Inputs          : An array of strings to display
570
#
571
sub ReportError
572
{
573
    _Message '(E)', @_;
574
    $ScmErrorCount++;
575
}
576
 
577
#-------------------------------------------------------------------------------
578
# Function        : ErrorDoExit
579
#
580
# Description     : Will terminate the program if delayed error messages
581
#                   have been seen.
582
#
583
# Inputs          : None
584
#
585
# Returns         : Will return if no errors have been reported
586
#
587
 
588
sub ErrorDoExit
589
{
590
    if ( $ScmErrorCount )
591
    {
5109 dpurdie 592
        # If capturing, then force the captured messages to be displayed
593
        DumpCapture();
594
 
227 dpurdie 595
        #
596
        #   Prevent recusion.
597
        #   Kill error processing while doing error exit processing
598
        #
599
        if ( my $func = $ScmOnExit )
600
        {
601
            $ScmOnExit = undef;
283 dpurdie 602
            &$func( $ScmExitCode );
227 dpurdie 603
        }
261 dpurdie 604
        exit $ScmExitCode;
227 dpurdie 605
    }
606
}
607
 
608
#-------------------------------------------------------------------------------
263 dpurdie 609
# Function        : ArgsToString
610
#
611
# Description     : Convert an array of arguments to a string
612
#                   Main purpose is to allow Debug and Verbose
613
#                   calls to pass undef values without causing warnings
614
#
615
# Inputs          : REF to a list of scalar values
616
#                   Passing a REF is faster
617
#
618
# Returns         : A string
619
#
620
sub ArgsToString
621
{
622
    my $result = '';
623
 
624
    $result .= (defined ($_) ? $_ : '\'undef\'') . ' ' foreach  ( @{$_[0]} );
625
    return $result;
626
}
627
 
628
#-------------------------------------------------------------------------------
629
# Function        : Verbose0
630
#                   Verbose
227 dpurdie 631
#                   Verbose2
632
#                   Verbose3
633
#
634
# Description     : Various levels of progress reporting
635
#                   By default none are displayed
636
#
637
# Inputs          : A single line string
638
#                   Multi-line output is not supported
263 dpurdie 639
#                   Arguments will be processed such that undef is handled well
227 dpurdie 640
#
263 dpurdie 641
sub Verbose0
642
{
643
    _Message '------', ArgsToString (\@_);
644
}
227 dpurdie 645
sub Verbose
646
{
263 dpurdie 647
    _Message '(V)', ArgsToString (\@_) if ($::ScmVerbose);
227 dpurdie 648
}
649
 
650
sub Verbose2
651
{
263 dpurdie 652
    _Message '(V)', ArgsToString (\@_) if ($::ScmVerbose >= 2);
227 dpurdie 653
}
654
 
655
sub Verbose3
656
{
263 dpurdie 657
    _Message '(V)', ArgsToString (\@_) if ($::ScmVerbose >= 3);
227 dpurdie 658
}
659
 
660
sub IsVerbose
661
{
662
    my( $level) = @_;
663
    return $::ScmVerbose >= $level;
664
}
665
 
666
#-------------------------------------------------------------------------------
667
# Function        : Debug
668
#                   Debug0
669
#                   Debug1
670
#                   Debug2
671
#                   Debug3
672
#
673
# Description     : Various levels of debug reporting
674
#                   By default none are displayed
675
#
676
# Inputs          : A single line string
677
#                   Multi-line output is not supported
263 dpurdie 678
#                   Arguments will be processed such that undef is handled well
227 dpurdie 679
#
680
sub Debug0
681
{
263 dpurdie 682
    _Message '------', ArgsToString (\@_);
227 dpurdie 683
}
684
 
685
sub Debug
686
{
263 dpurdie 687
    _Message '(D)', ArgsToString (\@_) if ($::ScmDebug >= 1 ) ;
227 dpurdie 688
}
689
 
690
 
691
sub Debug2
692
{
263 dpurdie 693
    _Message '(D)', ArgsToString (\@_) if ($::ScmDebug >= 2) ;
227 dpurdie 694
}
695
 
696
 
697
sub Debug3
698
{
263 dpurdie 699
    _Message '(D)', ArgsToString (\@_) if ($::ScmDebug >= 3) ;
227 dpurdie 700
}
701
 
702
sub IsDebug
703
{
704
    my( $level) = @_;
705
    return $::ScmDebug >= $level;
706
}
707
 
708
#-------------------------------------------------------------------------------
5109 dpurdie 709
# Function        : StartCapture 
710
#
711
# Description     : Start capturing non-debug non-verbose messages 
712
#
713
# Inputs          : mode    - True: Start 
714
#
715
# Returns         : 
716
#
717
sub StartCapture
718
{
719
    my ($mode) = @_;
720
    $capturing = $mode;
721
}
722
 
723
#-------------------------------------------------------------------------------
724
# Function        : DumpCapture 
725
#
726
# Description     : Dump the captured output
727
#
728
# Inputs          : None
729
#
730
# Returns         : Nothing
731
#
732
sub DumpCapture
733
{
734
    foreach my $line ( @captured) {
735
        print $line;
736
    }
737
    @captured = ();
738
    $capturing = 0;
739
}
740
 
741
#-------------------------------------------------------------------------------
227 dpurdie 742
# Function        : DebugDumpData
743
#
744
# Description     : Dump a data structure
745
#
746
# Inputs          : $name           - A name to give the structure
747
#                   @refp           - An array of references
748
#
749
# Returns         :
750
#
751
sub DebugDumpData
752
{
753
    my ($name, @refp) = @_;
754
 
755
    my $ii = 0;
4085 dpurdie 756
    $Data::Dumper::Sortkeys = 1;
227 dpurdie 757
    foreach  ( @refp )
758
    {
759
        print Data::Dumper->Dump ( [$_], ["*[Arg:$ii] $name" ]);
760
        $ii++
761
    }
762
}
763
 
764
#-------------------------------------------------------------------------------
231 dpurdie 765
# Function        : DebugTraceBack
766
#
767
# Description     : Display the call stack
768
#
769
# Inputs          : $tag
770
#
771
# Returns         : Nothing
772
#
773
sub DebugTraceBack
774
{
775
    my ($tag) = @_;
776
    $tag = 'TraceBack' unless ( $tag );
777
 
778
    #
779
    #   Limit the stack stace.
780
    #   It can't go on forever
781
    #
782
    foreach my $ii ( 0 .. 20 )
783
    {
784
         my ($package, $filename, $line) = caller($ii);
785
         last unless ( $package );
786
         print "$tag: $ii: $package, $filename, $line\n";
787
    }
788
}
789
 
790
#-------------------------------------------------------------------------------
227 dpurdie 791
# Function        : DebugPush
792
#
793
# Description     : Save the current debug level and then use a new name and
794
#                   debug level for future reporting
795
#
279 dpurdie 796
#                   Provided for backward compatability
797
#                   Preferred solution is ErrorReConfig
798
#
799
# Inputs          : $name       - New program name
227 dpurdie 800
#                   $level      - New program debug level
801
#
802
# Returns         : Current debug level
803
#
804
 
805
my @DebugStack = ();
806
sub DebugPush
807
{
808
    my ($name, $new_level) = @_;
279 dpurdie 809
    my %args;
227 dpurdie 810
 
279 dpurdie 811
    #
812
    #   Save current state on a stack
813
    #
814
    my $estate = ErrorReConfig ();
815
    push @DebugStack, $estate;
816
 
227 dpurdie 817
    $::ScmDebug = $new_level if ( defined $new_level && $new_level );
6198 dpurdie 818
    $EPrefix =   $name        if ( defined $name && $name );
227 dpurdie 819
 
820
    return $::ScmDebug;
821
}
822
 
823
#-------------------------------------------------------------------------------
824
# Function        : DebugPop
825
#
826
# Description     : Restores the operation of the DebugPush
827
#
828
# Inputs          : None
829
#
830
sub DebugPop
831
{
279 dpurdie 832
    pop @DebugStack;
227 dpurdie 833
}
834
 
835
#-------------------------------------------------------------------------------
836
# Function        : DebugDumpPackage
837
#
838
# Description     : Dump data within the scope of a given package
839
#
840
# Inputs          : $packageName            - To dump
841
#
842
# Returns         : 
843
#
844
 
845
sub DebugDumpPackage
846
{
847
    no strict "vars";
848
    no strict "refs";
849
    my ($packageName) = @_;
850
    print "==DebugDumpPackage: $packageName =============================\n";
851
 
852
    local $Data::Dumper::Pad = "\t ";
853
    local $Data::Dumper::Maxdepth = 2;
854
    local $Data::Dumper::Indent  = 1;
855
 
856
    # We want to get access to the stash corresponding to the package name
857
 
858
    *stash = *{"${packageName}::"};  # Now %stash is the symbol table
6177 dpurdie 859
 
227 dpurdie 860
    # Iterate through the symbol table, which contains glob values
861
    # indexed by symbol names.
6177 dpurdie 862
 
863
    foreach my $varName ( sort keys %stash)
227 dpurdie 864
    {
6177 dpurdie 865
        my $globValue = $stash{$varName};
227 dpurdie 866
        print "$varName =============================\n";
867
        next if ( $varName eq 'stash' );
283 dpurdie 868
        local *alias = $globValue;
227 dpurdie 869
        if (defined ($alias)) {
870
            print Data::Dumper->Dump ( [$alias], ["*$varName" ]);
871
#            print "\t \$$varName $alias \n";
872
        } 
369 dpurdie 873
        if (@alias) {
227 dpurdie 874
            print Data::Dumper->Dump ( [\@alias], ["*$varName" ]);
875
#            print "\t \@$varName @alias \n";
876
        } 
369 dpurdie 877
        if (%alias) {
227 dpurdie 878
            print Data::Dumper->Dump ( [\%alias], ["*$varName" ]);
879
#            print "\t \%$varName ",%alias," \n";
880
        }
881
        if (defined (&alias)) {
882
#            print Data::Dumper->Dump ( [\&alias], ["*$varName" ]);
883
            print "\t \&$varName ","Code Fragment"," \n";
884
        }
885
     }
886
}
887
 
888
#
889
#
890
1;