Subversion Repositories DevTools

Rev

Rev 4085 | Details | Compare with Previous | Last modification | View Log | RSS feed

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