develooper Front page | perl.perl5.porters | Postings from March 2000

module warnings update

Thread Next
March 9, 2000 03:19
module warnings update
Message ID:

I've almost completed the coding to allow modules to register warnings
categories and should have a patch available today or tomorrow. It turned
out to be a much easier change than I had expected.

Also, before I forget, I've put the code back in that makes it a fatal error
to attempt to use a non-existent category name.

What I would like some input on is the names I picked for all the new

Here is an example that illustrates what can be done.

    package Fred ;

    # create a new warnings category called 'Fred'
    use warnings::register ;

   sub first
       my $path = shift ;
       if (warnings::enabled() && $path !~ m#^/#) {
           warnings::warn("a relative path isn't good") ;

    sub second
        if (warnings::enabled("deprecated")) {
            warnings::warn("deprecated", "second is deprecated, use first
instead") ;
        first ;

The use of

    use warnings::register

is used to create a new category whose name matches that package it is used
in. In this case a category called "Fred" will get created. I'm fairly happy
with the choice of name "register" for this feature.

If warnings::enabled is called without a parameter, it will assume the
category to check is the same as the package it is running in. When called
with a parameter, it uses that as the category to check. Again, I'm fairly
happy with the name.

Finally warnings::warn is used to report a warning (and get optionally
escalated to a fatal error if the calling code has enabled it). Again this
comes in two forms: one expects just the warning message and assumes the
category is the package name; the other expects two parameters, the category
and the message.

I'm considering renaming warnings::warn to warnings::carp. Any opinions?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About