1 package VerboseWarnings
;
4 #use warnings; FIXME - Bug 2505
7 use vars
qw(@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 ###############################################################################
35 'warn' => [ 'warn_additional', 'warn_normal', 'warn_pedantic' ],
36 'die' => [ 'error_additional', 'error_normal' ],
39 ###############################################################################
41 use vars
qw( $appName $input $input_abbr $pedantic_p $pedantic_tag $quiet);
42 use vars qw( $warned $erred );
44 sub set_application_name ($) {
46 $appName = $& if !defined $appName && $s =~ /[^\/]+$/;
49 sub application_name () {
53 sub set_input_file_name ($) {
56 $input_abbr = $& if defined $s && $s =~ /[^\/]+$/;
59 sub set_pedantic_mode ($) {
62 $pedantic_tag = $pedantic_p? '': ' (negligible)';
69 sub construct_warn_prefix ($$) {
70 my($prefix, $lc) = @_;
71 die "construct_warn_prefix called before set_application_name"
72 unless defined $appName;
73 die "construct_warn_prefix called before set_input_file_name"
74 unless defined $input || !defined $lc; # be a bit lenient
75 die "construct_warn_prefix called before set_pedantic_mode"
76 unless defined $pedantic_tag;
78 # FIXME: The line number is not accurate, but should be "close enough"
79 # FIXME: This wording is worse than what was there, but it's wrong to
80 # FIXME: hard-code this thing in each warn statement. Need improvement.
81 return "$appName: $prefix: " . (defined $lc? "$input_abbr: line $lc: ": defined $input_abbr? "$input_abbr: ": '');
84 sub warn_additional ($$) {
86 my $prefix = construct_warn_prefix('Warning', $lc);
87 $msg .= "\n" unless $msg =~ /\n$/s;
91 sub warn_normal ($$) {
94 warn_additional($msg, $lc);
97 sub warn_pedantic ($$$) {
98 my($msg, $lc, $flag) = @_;
99 my $prefix = construct_warn_prefix("Warning$pedantic_tag", $lc);
100 $msg .= "\n" unless $msg =~ /\n$/s;
101 warn "$prefix$msg" if ($pedantic_p || !$$flag) && $quiet;
103 $prefix = construct_warn_prefix("Warning$pedantic_tag", undef);
104 warn $prefix."Further similar negligible warnings will not be reported, use --pedantic for details\n" unless ($$flag || !$quiet);
110 sub error_additional ($$) {
112 my $prefix = construct_warn_prefix('ERROR', $lc);
113 $msg .= "\n" unless $msg =~ /\n$/s;
117 sub error_normal ($$) {
120 error_additional($msg, $lc);
124 return $warned; # number of times warned
127 ###############################################################################