Subversion Repositories DevTools

Rev

Rev 7300 | Rev 7308 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7300 Rev 7307
Line 7... Line 7...
7
# Environment(s): jats
7
# Environment(s): jats
8
#
8
#
9
# Description   : A Perl Package to perform error handling within JATS
9
# Description   : A Perl Package to perform error handling within JATS
10
#
10
#
11
#                 Uses global variables
11
#                 Uses global variables
12
#                       $::ScmWho;
-
 
13
#                       $::ScmVerbose;
12
#                       $::ScmVerbose;
14
#                       $::ScmQuiet;
13
#                       $::ScmQuiet;
15
#                       $::ScmDebug;
14
#                       $::ScmDebug;
16
#                 For use with existing scripts
15
#                 For use with existing scripts
17
#
16
#
18
#
-
 
19
#......................................................................#
17
#......................................................................#
20
 
18
 
21
package JatsError;
19
package JatsError;
22
use base qw(Exporter);
20
use base qw(Exporter);
23
 
21
 
Line 25... Line 23...
25
use strict;
23
use strict;
26
use warnings;
24
use warnings;
27
use Data::Dumper;
25
use Data::Dumper;
28
use IO::Handle;
26
use IO::Handle;
29
 
27
 
-
 
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
 
30
#-------------------------------------------------------------------------------
42
#-------------------------------------------------------------------------------
31
# Function        : BEGIN
43
# Function        : BEGIN
32
#
44
#
33
# Description     : Standard Package Interface
45
# Description     : Standard Package Interface
34
#
46
#
Line 64... Line 76...
64
    @EXPORT_OK   = qw();
76
    @EXPORT_OK   = qw();
65
 
77
 
66
    #
78
    #
67
    #   Ensure globals have a defined value
79
    #   Ensure globals have a defined value
68
    #
80
    #
69
    $::ScmWho = ''                          unless defined( $::ScmWho );
-
 
70
    $::ScmVerbose = $ENV{GBE_VERBOSE} || 0  unless defined( $::ScmVerbose );
81
    $::ScmVerbose = $ENV{GBE_VERBOSE} || 0  unless defined( $::ScmVerbose );
71
    $::ScmDebug = $ENV{GBE_DEBUG} || 0      unless defined( $::ScmDebug );
82
    $::ScmDebug = $ENV{GBE_DEBUG} || 0      unless defined( $::ScmDebug );
72
    $::ScmQuiet = 0                         unless defined( $::ScmQuiet );
83
    $::ScmQuiet = 0                         unless defined( $::ScmQuiet );
73
 
84
 
-
 
85
    $ScmErrorCount = 0;
-
 
86
    $ScmExitCode = 1;
-
 
87
 
74
    #
88
    #
75
    #   Force autoflush in an attempt to limit the intermingling of
89
    #   Force autoflush in an attempt to limit the intermingling of
76
    #   Error and non-error output.
90
    #   Error and non-error output.
77
    #
91
    #
78
    STDOUT->autoflush(1);
92
    STDOUT->autoflush(1);
79
    STDERR->autoflush(1);
93
    STDERR->autoflush(1);
80
}
94
}
81
 
95
 
82
 
-
 
83
 
-
 
84
# exported package globals go here
-
 
85
#our $ScmWho;
-
 
86
#our $ScmVerbose;
-
 
87
#our $ScmDebug;
-
 
88
#our $ScmQuiet;
-
 
89
our $ScmOnExit;
-
 
90
our $ScmDelayExit;
-
 
91
our $ScmErrorCount;
-
 
92
our $ScmExitCode;
-
 
93
 
-
 
94
# non-exported package globals go here
96
# non-exported package globals go here
95
$ScmErrorCount = 0;
-
 
96
$ScmExitCode = 1;
-
 
97
 
-
 
98
 
-
 
99
my $EName = '';
-
 
100
my $EFn = '';
-
 
101
my @captured;
97
my @captured;
102
my $capturing;
98
my $capturing;
103
 
99
 
104
#  initialize package globals, first exported ones
-
 
105
 
-
 
106
 
-
 
107
#-------------------------------------------------------------------------------
100
#-------------------------------------------------------------------------------
108
# Function        : import
101
# Function        : import
109
#
102
#
110
# Description     : Package import function
103
# Description     : Package import function
111
#                   This function will examine arguments provided in the
104
#                   This function will examine arguments provided in the
Line 115... Line 108...
115
# Inputs          : $pack           - Name of this package
108
# Inputs          : $pack           - Name of this package
116
#                   @vars           - User Config Options
109
#                   @vars           - User Config Options
117
#                   Config Options:
110
#                   Config Options:
118
#                       :name=xxxx
111
#                       :name=xxxx
119
#                       :function=xxxx
112
#                       :function=xxxx
-
 
113
#                       :prefix=xxxx
120
#                       :quiet=xxx
114
#                       :quiet=xxx
121
#                       :debug=xxx
115
#                       :debug=xxx
122
#                       :verbose=xxx
116
#                       :verbose=xxx
123
#                       :delay_exit=xxx
117
#                       :delay_exit=xxx
124
#
118
#
Line 163... Line 157...
163
#                       function    - Name of enclosing function
157
#                       function    - Name of enclosing function
164
#                       verbose     - vebosity level
158
#                       verbose     - vebosity level
165
#                       debug       - debug level
159
#                       debug       - debug level
166
#                       on_exit     - Register on-exit function
160
#                       on_exit     - Register on-exit function
167
#                       delay_exit  - Delay exit on error
161
#                       delay_exit  - Delay exit on error
-
 
162
#                       prefix      - Optional prefix. First line only
168
#
163
#
169
# Returns         :
164
# Returns         :
170
#
165
#
171
sub ErrorConfig
166
sub ErrorConfig
172
{
167
{
173
    my %args = @_;
168
    my %args = @_;
174
 
169
 
175
    while (my($key, $value) = each %args)
170
    while (my($key, $value) = each %args)
176
    {
171
    {
177
        if (       $key =~ /^name/ ) {
172
        if ( $key =~ /^name/ ) {
178
            $EName = $value;
173
            $EName = $value;
179
 
174
 
180
        } elsif ( $key =~ /^function/ ) {
175
        } elsif ( $key =~ /^function/ ) {
181
            $EFn = ':' . $value;
176
            $EFn = ':' . $value;
182
 
177
 
-
 
178
        } elsif ( $key =~ /^prefix/ ) {
-
 
179
            $ElPrefix = $value;
-
 
180
 
183
        } elsif ( $key =~ /^debug/ ) {
181
        } elsif ( $key =~ /^debug/ ) {
184
            $::ScmDebug = $value
182
            $::ScmDebug = $value
185
                if ( defined $value && $value > $::ScmDebug  );
183
                if ( defined $value && $value > $::ScmDebug  );
186
 
184
 
187
        } elsif ( $key =~ /^verbose/ ) {
185
        } elsif ( $key =~ /^verbose/ ) {
Line 207... Line 205...
207
 
205
 
208
    #
206
    #
209
    #   Calculate the prefix to all messages
207
    #   Calculate the prefix to all messages
210
    #   Based on Name and Function( if provided
208
    #   Based on Name and Function( if provided
211
    #
209
    #
212
    $::ScmWho = "[$EName$EFn] ";
210
    $EPrefix = "[$EName$EFn] ";
213
 
211
 
214
    #
212
    #
215
    #   Extract program specfic debug flags from the environment
213
    #   Extract program specfic debug flags from the environment
216
    #   These will be based on the reporting 'name'
214
    #   These will be based on the reporting 'name'
217
    #       GBE_name_DEBUG
215
    #       GBE_name_DEBUG
Line 274... Line 272...
274
    #   The error information will be restored when the handle returned to
272
    #   The error information will be restored when the handle returned to
275
    #   the user goes out of scope.
273
    #   the user goes out of scope.
276
    #
274
    #
277
    my $self;
275
    my $self;
278
 
276
 
279
    $self->{ScmWho}         =  $::ScmWho;
277
    $self->{EPrefix}        =  $EPrefix;
-
 
278
    $self->{ElPrefix}       =  $ElPrefix;
280
    $self->{ScmVerbose}     =  $::ScmVerbose;
279
    $self->{ScmVerbose}     =  $::ScmVerbose;
281
    $self->{ScmDebug}       =  $::ScmDebug;
280
    $self->{ScmDebug}       =  $::ScmDebug;
282
    $self->{ScmQuiet}       =  $::ScmQuiet;
281
    $self->{ScmQuiet}       =  $::ScmQuiet;
283
    $self->{ScmOnExit}      =  $ScmOnExit;
282
    $self->{ScmOnExit}      =  $ScmOnExit;
284
    $self->{ScmDelayExit}   =  $ScmDelayExit;
283
    $self->{ScmDelayExit}   =  $ScmDelayExit;
Line 302... Line 301...
302
}
301
}
303
 
302
 
304
#-------------------------------------------------------------------------------
303
#-------------------------------------------------------------------------------
305
# Function        : DESTROY
304
# Function        : DESTROY
306
#
305
#
307
# Description     : Called when the handle retruned by ErrorConfig goes out of
306
# Description     : Called when the handle returned by ErrorConfig goes out of
308
#                   scope.
307
#                   scope.
309
#
308
#
310
#                   Restores the state of the Error Reporting information
309
#                   Restores the state of the Error Reporting information
311
#
310
#
312
# Inputs          : $self               - Created by ErrorReConfig
311
# Inputs          : $self               - Created by ErrorReConfig
Line 315... Line 314...
315
#
314
#
316
 
315
 
317
sub DESTROY
316
sub DESTROY
318
{
317
{
319
    my ($self) = @_;
318
    my ($self) = @_;
320
    $::ScmWho         = $self->{ScmWho};
319
    $EPrefix          = $self->{EPrefix};
-
 
320
    $ElPrefix         = $self->{ElPrefix};
321
    $::ScmVerbose     = $self->{ScmVerbose};
321
    $::ScmVerbose     = $self->{ScmVerbose};
322
    $::ScmDebug       = $self->{ScmDebug};
322
    $::ScmDebug       = $self->{ScmDebug};
323
    $::ScmQuiet       = $self->{ScmQuiet};
323
    $::ScmQuiet       = $self->{ScmQuiet};
324
    $ScmOnExit        = $self->{ScmOnExit};
324
    $ScmOnExit        = $self->{ScmOnExit};
325
    $ScmDelayExit     = $self->{ScmDelayExit};
325
    $ScmDelayExit     = $self->{ScmDelayExit};
Line 359... Line 359...
359
    #
359
    #
360
    #   Generate the message prefix
360
    #   Generate the message prefix
361
    #   This will only be used on the first line
361
    #   This will only be used on the first line
362
    #   All other lines will have a space filled prefix
362
    #   All other lines will have a space filled prefix
363
    #
363
    #
364
    my $prefix = $::ScmWho . $tag;
364
    my $prefix = $EPrefix . $tag;
365
    #
365
    #
366
    #   Kill the eol if the Question is being asked
366
    #   Kill the eol if the Question is being asked
367
    #
367
    #
368
    my $eol = ( $tag =~ m/Q/ ) ? "" : "\n";
368
    my $eol = ( $tag =~ m/Q/ ) ? "" : "\n";
369
    foreach my $nextline ( @_ )
369
    foreach my $nextline ( @_ ) {
370
    {
-
 
371
        next unless ( defined $nextline );              # Ignore undefined arguments
370
        next unless ( defined $nextline );              # Ignore undefined arguments
372
        chomp( my $line = $nextline );
371
        chomp( my $line = $nextline );
373
        if ( $count == 1 )
372
        if ( $count == 0 ) {
-
 
373
            $line = ($ElPrefix || '') . $line;
-
 
374
 
374
        {
375
        } elsif ( $count == 1 ) {
375
            my $bol = $eol ? "" : "\n";
376
            my $bol = $eol ? "" : "\n";
376
            $prefix = $bol . ' ' x length($prefix);
377
            $prefix = $bol . ' ' x length($prefix);
377
        }
378
        }
378
        $count++;
379
        $count++;
379
 
380
 
380
        if ($capturing && $tag =~ m/[MWEF]/)
381
        if ($capturing && $tag =~ m/[MWEF]/) {
381
        {
-
 
382
            push @captured, "$prefix $line$eol" 
382
            push @captured, "$prefix $line$eol" 
383
        }
383
 
384
        else
384
        } else {
385
        {
-
 
386
            print "$prefix $line$eol";
385
            print "$prefix $line$eol";
387
        }
386
        }
388
    }
387
    }
389
}
388
}
390
 
389
 
Line 790... Line 789...
790
    #
789
    #
791
    my $estate = ErrorReConfig ();
790
    my $estate = ErrorReConfig ();
792
    push @DebugStack, $estate;
791
    push @DebugStack, $estate;
793
    
792
    
794
    $::ScmDebug = $new_level if ( defined $new_level && $new_level );
793
    $::ScmDebug = $new_level if ( defined $new_level && $new_level );
795
    $::ScmWho =   $name      if ( defined $name && $name );
794
    $EPrefix =   $name        if ( defined $name && $name );
796
 
795
 
797
    return $::ScmDebug;
796
    return $::ScmDebug;
798
}
797
}
799
 
798
 
800
#-------------------------------------------------------------------------------
799
#-------------------------------------------------------------------------------