Subversion Repositories DevTools

Rev

Rev 6198 | Rev 6504 | 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++;
6276 dpurdie 561
#    DebugTraceBack();
227 dpurdie 562
    ErrorDoExit() unless ( $ScmDelayExit );
563
}
564
 
565
#-------------------------------------------------------------------------------
566
# Function        : ReportError
567
#
568
# Description     : Like Error, but the error exit is delayed
569
#
570
# Inputs          : An array of strings to display
571
#
572
sub ReportError
573
{
574
    _Message '(E)', @_;
575
    $ScmErrorCount++;
576
}
577
 
578
#-------------------------------------------------------------------------------
579
# Function        : ErrorDoExit
580
#
581
# Description     : Will terminate the program if delayed error messages
582
#                   have been seen.
583
#
584
# Inputs          : None
585
#
586
# Returns         : Will return if no errors have been reported
587
#
588
 
589
sub ErrorDoExit
590
{
591
    if ( $ScmErrorCount )
592
    {
5109 dpurdie 593
        # If capturing, then force the captured messages to be displayed
594
        DumpCapture();
595
 
227 dpurdie 596
        #
597
        #   Prevent recusion.
598
        #   Kill error processing while doing error exit processing
599
        #
600
        if ( my $func = $ScmOnExit )
601
        {
602
            $ScmOnExit = undef;
283 dpurdie 603
            &$func( $ScmExitCode );
227 dpurdie 604
        }
261 dpurdie 605
        exit $ScmExitCode;
227 dpurdie 606
    }
607
}
608
 
609
#-------------------------------------------------------------------------------
263 dpurdie 610
# Function        : ArgsToString
611
#
612
# Description     : Convert an array of arguments to a string
613
#                   Main purpose is to allow Debug and Verbose
614
#                   calls to pass undef values without causing warnings
615
#
616
# Inputs          : REF to a list of scalar values
617
#                   Passing a REF is faster
618
#
619
# Returns         : A string
620
#
621
sub ArgsToString
622
{
623
    my $result = '';
624
 
625
    $result .= (defined ($_) ? $_ : '\'undef\'') . ' ' foreach  ( @{$_[0]} );
626
    return $result;
627
}
628
 
629
#-------------------------------------------------------------------------------
630
# Function        : Verbose0
631
#                   Verbose
227 dpurdie 632
#                   Verbose2
633
#                   Verbose3
634
#
635
# Description     : Various levels of progress reporting
636
#                   By default none are displayed
637
#
638
# Inputs          : A single line string
639
#                   Multi-line output is not supported
263 dpurdie 640
#                   Arguments will be processed such that undef is handled well
227 dpurdie 641
#
263 dpurdie 642
sub Verbose0
643
{
644
    _Message '------', ArgsToString (\@_);
645
}
227 dpurdie 646
sub Verbose
647
{
263 dpurdie 648
    _Message '(V)', ArgsToString (\@_) if ($::ScmVerbose);
227 dpurdie 649
}
650
 
651
sub Verbose2
652
{
263 dpurdie 653
    _Message '(V)', ArgsToString (\@_) if ($::ScmVerbose >= 2);
227 dpurdie 654
}
655
 
656
sub Verbose3
657
{
263 dpurdie 658
    _Message '(V)', ArgsToString (\@_) if ($::ScmVerbose >= 3);
227 dpurdie 659
}
660
 
661
sub IsVerbose
662
{
663
    my( $level) = @_;
664
    return $::ScmVerbose >= $level;
665
}
666
 
667
#-------------------------------------------------------------------------------
668
# Function        : Debug
669
#                   Debug0
670
#                   Debug1
671
#                   Debug2
672
#                   Debug3
673
#
674
# Description     : Various levels of debug reporting
675
#                   By default none are displayed
676
#
677
# Inputs          : A single line string
678
#                   Multi-line output is not supported
263 dpurdie 679
#                   Arguments will be processed such that undef is handled well
227 dpurdie 680
#
681
sub Debug0
682
{
263 dpurdie 683
    _Message '------', ArgsToString (\@_);
227 dpurdie 684
}
685
 
686
sub Debug
687
{
263 dpurdie 688
    _Message '(D)', ArgsToString (\@_) if ($::ScmDebug >= 1 ) ;
227 dpurdie 689
}
690
 
691
 
692
sub Debug2
693
{
263 dpurdie 694
    _Message '(D)', ArgsToString (\@_) if ($::ScmDebug >= 2) ;
227 dpurdie 695
}
696
 
697
 
698
sub Debug3
699
{
263 dpurdie 700
    _Message '(D)', ArgsToString (\@_) if ($::ScmDebug >= 3) ;
227 dpurdie 701
}
702
 
703
sub IsDebug
704
{
705
    my( $level) = @_;
706
    return $::ScmDebug >= $level;
707
}
708
 
709
#-------------------------------------------------------------------------------
5109 dpurdie 710
# Function        : StartCapture 
711
#
712
# Description     : Start capturing non-debug non-verbose messages 
713
#
714
# Inputs          : mode    - True: Start 
715
#
716
# Returns         : 
717
#
718
sub StartCapture
719
{
720
    my ($mode) = @_;
721
    $capturing = $mode;
722
}
723
 
724
#-------------------------------------------------------------------------------
725
# Function        : DumpCapture 
726
#
727
# Description     : Dump the captured output
728
#
729
# Inputs          : None
730
#
731
# Returns         : Nothing
732
#
733
sub DumpCapture
734
{
735
    foreach my $line ( @captured) {
736
        print $line;
737
    }
738
    @captured = ();
739
    $capturing = 0;
740
}
741
 
742
#-------------------------------------------------------------------------------
227 dpurdie 743
# Function        : DebugDumpData
744
#
745
# Description     : Dump a data structure
746
#
747
# Inputs          : $name           - A name to give the structure
748
#                   @refp           - An array of references
749
#
750
# Returns         :
751
#
752
sub DebugDumpData
753
{
754
    my ($name, @refp) = @_;
755
 
756
    my $ii = 0;
4085 dpurdie 757
    $Data::Dumper::Sortkeys = 1;
227 dpurdie 758
    foreach  ( @refp )
759
    {
760
        print Data::Dumper->Dump ( [$_], ["*[Arg:$ii] $name" ]);
761
        $ii++
762
    }
763
}
764
 
765
#-------------------------------------------------------------------------------
231 dpurdie 766
# Function        : DebugTraceBack
767
#
768
# Description     : Display the call stack
769
#
770
# Inputs          : $tag
771
#
772
# Returns         : Nothing
773
#
774
sub DebugTraceBack
775
{
776
    my ($tag) = @_;
777
    $tag = 'TraceBack' unless ( $tag );
778
 
779
    #
780
    #   Limit the stack stace.
781
    #   It can't go on forever
782
    #
783
    foreach my $ii ( 0 .. 20 )
784
    {
785
         my ($package, $filename, $line) = caller($ii);
786
         last unless ( $package );
787
         print "$tag: $ii: $package, $filename, $line\n";
788
    }
789
}
790
 
791
#-------------------------------------------------------------------------------
227 dpurdie 792
# Function        : DebugPush
793
#
794
# Description     : Save the current debug level and then use a new name and
795
#                   debug level for future reporting
796
#
279 dpurdie 797
#                   Provided for backward compatability
798
#                   Preferred solution is ErrorReConfig
799
#
800
# Inputs          : $name       - New program name
227 dpurdie 801
#                   $level      - New program debug level
802
#
803
# Returns         : Current debug level
804
#
805
 
806
my @DebugStack = ();
807
sub DebugPush
808
{
809
    my ($name, $new_level) = @_;
279 dpurdie 810
    my %args;
227 dpurdie 811
 
279 dpurdie 812
    #
813
    #   Save current state on a stack
814
    #
815
    my $estate = ErrorReConfig ();
816
    push @DebugStack, $estate;
817
 
227 dpurdie 818
    $::ScmDebug = $new_level if ( defined $new_level && $new_level );
6198 dpurdie 819
    $EPrefix =   $name        if ( defined $name && $name );
227 dpurdie 820
 
821
    return $::ScmDebug;
822
}
823
 
824
#-------------------------------------------------------------------------------
825
# Function        : DebugPop
826
#
827
# Description     : Restores the operation of the DebugPush
828
#
829
# Inputs          : None
830
#
831
sub DebugPop
832
{
279 dpurdie 833
    pop @DebugStack;
227 dpurdie 834
}
835
 
836
#-------------------------------------------------------------------------------
837
# Function        : DebugDumpPackage
838
#
839
# Description     : Dump data within the scope of a given package
840
#
841
# Inputs          : $packageName            - To dump
842
#
843
# Returns         : 
844
#
845
 
846
sub DebugDumpPackage
847
{
848
    no strict "vars";
849
    no strict "refs";
850
    my ($packageName) = @_;
851
    print "==DebugDumpPackage: $packageName =============================\n";
852
 
853
    local $Data::Dumper::Pad = "\t ";
854
    local $Data::Dumper::Maxdepth = 2;
855
    local $Data::Dumper::Indent  = 1;
856
 
857
    # We want to get access to the stash corresponding to the package name
858
 
859
    *stash = *{"${packageName}::"};  # Now %stash is the symbol table
6177 dpurdie 860
 
227 dpurdie 861
    # Iterate through the symbol table, which contains glob values
862
    # indexed by symbol names.
6177 dpurdie 863
 
864
    foreach my $varName ( sort keys %stash)
227 dpurdie 865
    {
6177 dpurdie 866
        my $globValue = $stash{$varName};
227 dpurdie 867
        print "$varName =============================\n";
868
        next if ( $varName eq 'stash' );
283 dpurdie 869
        local *alias = $globValue;
227 dpurdie 870
        if (defined ($alias)) {
871
            print Data::Dumper->Dump ( [$alias], ["*$varName" ]);
872
#            print "\t \$$varName $alias \n";
873
        } 
369 dpurdie 874
        if (@alias) {
227 dpurdie 875
            print Data::Dumper->Dump ( [\@alias], ["*$varName" ]);
876
#            print "\t \@$varName @alias \n";
877
        } 
369 dpurdie 878
        if (%alias) {
227 dpurdie 879
            print Data::Dumper->Dump ( [\%alias], ["*$varName" ]);
880
#            print "\t \%$varName ",%alias," \n";
881
        }
882
        if (defined (&alias)) {
883
#            print Data::Dumper->Dump ( [\&alias], ["*$varName" ]);
884
            print "\t \&$varName ","Code Fragment"," \n";
885
        }
886
     }
887
}
888
 
889
#
890
#
891
1;