Subversion Repositories DevTools

Rev

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