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 ###############################################################################
36 ###############################################################################
38 use vars qw( $appName $input $input_abbr $pedantic_p $pedantic_tag );
40 sub set_application_name ($) {
42 $appName = $& if !defined $appName && $s =~ /[^\/]+$/;
45 sub set_input_file_name ($) {
48 $input_abbr = $& if !defined $input && defined $s && $s =~ /[^\/]+$/;
51 sub set_pedantic_mode ($) {
54 $pedantic_tag = $pedantic_p? '': ' (negligible)';
61 sub construct_warn_prefix ($$) {
62 my($prefix, $lc) = @_;
63 die "construct_warn_prefix called before set_application_name"
64 unless defined $appName;
65 die "construct_warn_prefix called before set_input_file_name"
66 unless defined $input;
67 die "construct_warn_prefix called before set_pedantic_mode"
68 unless defined $pedantic_tag;
70 # FIXME: The line number is not accurate, but should be "close enough"
71 # FIXME: This wording is worse than what was there, but it's wrong to
72 # FIXME: hard-code this thing in each warn statement. Need improvement.
73 return "$appName: $prefix: " . (defined $lc? "$input_abbr: line $lc: ": "$input_abbr: ");
76 sub warn_normal ($$) {
78 my $prefix = construct_warn_prefix('Warning', $lc);
79 $msg .= "\n" unless $msg =~ /\n$/s;
83 sub warn_pedantic ($$$) {
84 my($msg, $lc, $flag) = @_;
85 my $prefix = construct_warn_prefix("Warning$pedantic_tag", $lc);
86 $msg .= "\n" unless $msg =~ /\n$/s;
87 warn "$prefix$msg" if $pedantic_p || !$$flag;
89 $prefix = construct_warn_prefix("Warning$pedantic_tag", undef);
90 warn $prefix."Further similar negligible warnings will not be reported, use --pedantic for details\n" unless $$flag;
95 sub error_normal ($$) {
97 my $prefix = construct_warn_prefix('ERROR', $lc);
98 $msg .= "\n" unless $msg =~ /\n$/s;
102 ###############################################################################