Aaron Sherman <[EMAIL PROTECTED]> wrote:

> An off-the-wall thought... If this is not the "expected" condition,
> should it have the extra meaning of an assertion? For example,
> could set $! to 'defined $foo but $foo eq ""' and, if -w was in use,
> issue 'warn "Exceptional condition: $!"'

Interesting idea; the problem with warn is that you always get a message
with -w, which is a pain.

I can't count the number of times I've had to do something like:

  if (defined $foo and $foo ne "bar") { }

to avoid my program writing garbage to STDERR.

Messages should have priorities, somewhat like syslog priorities.  I tend
to find myself writing this sort of thing:

package Foo;
sub speak { print __PACKAGE__.": @_\n" }
sub quiet { }
%SEV = map { $_ => $c++ }
@SEV = (debug,    verbose, info,  notice, warning,
        err,      crit,    alert, emerg);
@FUNCS= [mutter,   mumble,  say,   remark, moan,
         complain, shout,   yell,  scream ]
$MESSAGE_LEVEL=2;
*{$FUNCS[$_]} = \&quiet foreach (0..$MESSAGE_LEVEL-1);
*{$FUNCS[$_]} = \&speak foreach ($MESSAGE_LEVEL..$#SEV);

mutter "Connecting to database";
mumble "Selecting some data";
say "Your result is: empty";
remark "An empty result is unusual; check your head";
complain "can't open /etc/hosts";
shout "Fix your permissions on /, too open!";
yell "The disk is about to fill up!";
scream "About to run out of virtual memory!";

In my actual module (http://sam.vilain.net/pm/Codeine.pm or
http://sam.vilain.net/Codeine-0.07.tar.gz, if you're interested), I also
define alternatives to "die", such as "barf", "melt", and "explode".

So then "use warnings" would simply make warning messages "say" level
rather than "mutter".

And "but" would have an implied { mutter "mmm, that's odd" }

Sam.

Reply via email to