1 package VerboseWarnings
;
4 #use warnings; FIXME - Bug 2505
7 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9 ###############################################################################
13 VerboseWarnings.pm - Verbose warnings for Perl scripts
17 Contains convenience functions to construct Unix-style informational,
22 ###############################################################################
36 'warn' => [ 'warn_additional', 'warn_normal', 'warn_pedantic' ],
37 'die' => [ 'error_additional', 'error_normal' ],
40 ###############################################################################
42 use vars
qw( $appName $input $input_abbr $pedantic_p $pedantic_tag $quiet);
43 use vars qw( $warned $erred );
45 sub set_application_name ($) {
47 $appName = $& if !defined $appName && $s =~ /[^\/]+$/;
50 sub application_name () {
54 sub set_input_file_name ($) {
57 $input_abbr = $& if defined $s && $s =~ /[^\/]+$/;
60 sub set_pedantic_mode ($) {
63 $pedantic_tag = $pedantic_p? '': ' (negligible)';
70 sub construct_warn_prefix ($$) {
71 my($prefix, $lc) = @_;
72 die "construct_warn_prefix called before set_application_name"
73 unless defined $appName;
74 die "construct_warn_prefix called before set_input_file_name"
75 unless defined $input || !defined $lc; # be a bit lenient
76 die "construct_warn_prefix called before set_pedantic_mode"
77 unless defined $pedantic_tag;
79 # FIXME: The line number is not accurate, but should be "close enough"
80 # FIXME: This wording is worse than what was there, but it's wrong to
81 # FIXME: hard-code this thing in each warn statement. Need improvement.
82 return "$appName: $prefix: " . (defined $lc? "$input_abbr: line $lc: ": defined $input_abbr? "$input_abbr: ": '');
85 sub warn_additional ($$) {
87 my $prefix = construct_warn_prefix('Warning', $lc);
88 $msg .= "\n" unless $msg =~ /\n$/s;
92 sub warn_normal ($$) {
95 warn_additional($msg, $lc);
98 sub warn_pedantic ($$$) {
99 my($msg, $lc, $flag) = @_;
100 my $prefix = construct_warn_prefix("Warning$pedantic_tag", $lc);
101 $msg .= "\n" unless $msg =~ /\n$/s;
102 warn "$prefix$msg" if ($pedantic_p || !$$flag) && $quiet;
104 $prefix = construct_warn_prefix("Warning$pedantic_tag", undef);
105 warn $prefix."Further similar negligible warnings will not be reported, use --pedantic for details\n" unless ($$flag || !$quiet);
111 sub error_additional ($$) {
113 my $prefix = construct_warn_prefix('ERROR', $lc);
114 $msg .= "\n" unless $msg =~ /\n$/s;
118 sub error_normal ($$) {
121 error_additional($msg, $lc);
125 return $warned; # number of times warned
128 ###############################################################################