1 package VerboseWarnings;
6 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
8 ###############################################################################
12 VerboseWarnings.pm - Verbose warnings for Perl scripts
16 Contains convenience functions to construct Unix-style informational,
21 ###############################################################################
33 ###############################################################################
35 use vars qw( $appName $input $input_abbr $pedantic_p $pedantic_tag );
37 sub set_application_name ($) {
39 $appName = $& if !defined $appName && $s =~ /[^\/]+$/;
42 sub set_input_file_name ($) {
45 $input_abbr = $& if defined $s && $s =~ /[^\/]+$/;
48 sub set_pedantic_mode ($) {
51 $pedantic_tag = $pedantic_p? '': ' (negligible)';
58 sub construct_warn_prefix ($$) {
59 my($prefix, $lc) = @_;
60 die "construct_warn_prefix called before set_application_name"
61 unless defined $appName;
62 die "construct_warn_prefix called before set_input_file_name"
63 unless defined $input;
64 die "construct_warn_prefix called before set_pedantic_mode"
65 unless defined $pedantic_tag;
67 # FIXME: The line number is not accurate, but should be "close enough"
68 # FIXME: This wording is worse than what was there, but it's wrong to
69 # FIXME: hard-code this thing in each warn statement. Need improvement.
70 return "$appName: $prefix: " . (defined $lc? "$input_abbr: line $lc: ": "$input_abbr: ");
73 sub warn_normal ($$) {
75 my $prefix = construct_warn_prefix('Warning', $lc);
76 $msg .= "\n" unless $msg =~ /\n$/s;
80 sub warn_pedantic ($$$) {
81 my($msg, $lc, $flag) = @_;
82 my $prefix = construct_warn_prefix("Warning$pedantic_tag", $lc);
83 $msg .= "\n" unless $msg =~ /\n$/s;
84 warn "$prefix$msg" if $pedantic_p || !$$flag;
86 $prefix = construct_warn_prefix("Warning$pedantic_tag", undef);
87 warn $prefix."Further similar negligible warnings will not be reported, use --pedantic for details\n" unless $$flag;
92 sub error_normal ($$) {
94 my $prefix = construct_warn_prefix('ERROR', $lc);
95 $msg .= "\n" unless $msg =~ /\n$/s;
99 ###############################################################################