=head1 TITLE

messages.rfc - An RFC to discussing the wisdom of allowing run time error
and warning messages to be modified at run time

=head1 VERSION

    Maintainer: Corwin Brust <[EMAIL PROTECTED]>
    Date: 1 Aug 2000
    Version: 1
    Mailing List: [EMAIL PROTECTED]
    Number: 3

=head1 ABSTRACT

I'm probably wrong in this, but I rather think this one's explains it self.

I want perl's error (and warning) messages to be specific to each program I
write.

=head1 DESCRIPTION

I have, and I cannot assume I am alone in this, spent a fair amount of time
creating subroutines which trap various error responses from Perl, only to
turn right around and 'die' with an error message of my own, differing only
in the text shown when the program terminates.

Wouldn't it be great if we could just reword the existing error messages on
a per-script basis to be relevant to that program, and let Perl's normal
error handling mechanism do the work of presenting the user with the bad
news.

=head1 IMPLEMENTATION

It seems, as of this writing, that the means for accessing Perl internal
variables will not be as it has been.
Any method of allowing for program writer defined messages would have to be
closely time to whatever new mechanism we find agreeable. But...

  $perl::core::err{TYPE_MISMATCH} = {
                                     fatal => 1,
                                     handler => sub { 
                                                      my $arg = shift; 
                                                      my $func = shift;
                                                      my $correct_type = shift;
                                                      my $sent_type = shift;
                                                      my $prog = shift;
                                                      my $line = shift;
                                                      my $near = shift;
                                                      CORE::die(qq[Type of
$arg to $func must be $correct_type (not $sent_type) at $prog line $line,
$near\n]);
                                                     },
                                    }
Where CORE::die is able to look for a true value in
$perl::core::err{TYPE_MISMATCH}->{fatal} and either die or issue a warning
as appropriate.

And, yeah, I'm sure there's a B<better> way to implement this.  I hope,
however, that I have shown such a thing can be done.

=head1 REFERENCES

=cut

Reply via email to