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

RE: [ID 20000325.010] warnings stuff

Thread Previous | Thread Next
From:
Marquess,P,Paul,NEL38 R
Date:
March 28, 2000 11:53
Subject:
RE: [ID 20000325.010] warnings stuff
Message ID:
5104D4DBC598D211B5FE0000F8FE7EB2067FE5F6@mbtlipnt02.btlabs.bt.co.uk
From: Tom Christiansen [mailto:tchrist@chthon.perl.com]
 
> Here's a lexical warnings demo using with the sysreadline() function
> that doubtless we've all written a zillion times.  It brings
> up two matters about warnings::warn and warnings::enabled --
> 
> 1) I think Perl need's a warn to pass one's caller's warnings
>    mask to one's callees.  Otherwise, when you have a level
>    of indirection as I have here, you lose everything.
> 
> 2) How does one control carp/croak vs cluck/confess?  I seem to be
>    getting the second set, but the source seems to show getting the
>    first set.

I think there are a few options for getting around this

1. Completely Manual System

control which scope that warnings::(enabled|warn) looks at for the bitmask
with a variable - like $Carp::CarpLevel does currently. The major problem
with this is knowing what to set the variable to. Assuming the warning is
embedded in a module, there is no way to know how far up the caller list to
go to find the "application". I don't think this is a viable option.

2. Walk up the "caller" list until a different package is found.

If you make the assumption that warnings::(enabled|warn) are going to be
predominantly used in modules, it would be easy to walk up the caller list
until a different package name is encountered and use the bitmask it finds
there.

3. Allow option 2 to be fine tuned.

The problem with the previous option are the exceptions. For example there
may be a module that calls a private sub-module. If warnings::(enabled|warn)
are used in the sub-module, reporting the error from the point of view of
the main module (i.e. the first different package found in the caller list)
may, or may not, be the appropriate thing to do. In this case an equivalent
of $Carp::CarpLevel could be used to set the number of package changes that
need to be encountered in the caller list before the bitmask is found. 

Option 3 feels like the way to go. Any opinions?

Paul

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About