[Bioperl-l] How to get rid of warnings
Chris Fields
cjfields at uiuc.edu
Sun Aug 20 01:58:30 UTC 2006
On Aug 19, 2006, at 1:07 PM, Sendu Bala wrote:
> Hilmar Lapp wrote:
>> Well, the rule would be:
>>
>> 1) if a local (instance) verbosity has been set, use it
>> 2) otherwise, if a global (class, static) verbosity has been set,
>> use it
>> 3) otherwise, use a default value.
>>
>> This would mean indeed that if you changed verbosity for a specific
>> instance it will be unaffected by global changes of the verbosity
>> level.
>>
>> If that doesn't sound good, you would reverse rules 1) and 2).
>
> But then if you set the global verbosity how do you later change your
> mind, unset it, and go back to using instance verbosity?
>
I think verbosity can be changed using Bio::Root::Root method verbose
($verbose_value). The method is a get/set which defaults to 0 (or
the previous set value if not 0) when called without an argument.
Every BioPerl class inherits Bio::Root::Root directly or indirectly;
many (but not all) allow you to set it via the constructor using '-
verbose'.
>> Or am I missing something?
>
> Well, assuming we would prefer global changes to really be global
> changes, and we reversed 1) and 2), if we have just a single simple
> global variable, how does a method like &warn even know that it is
> 'set'
> (and not still on its default value)? How does it know when it is
> unset
> (we no longer want a globally acting verbosity)?
>
> Like I say, you have to have a default of undef and set the value to
> undef to turn the feature off, which doesn't seem very nice to me.
>
> I'd prefer to be able to chose a global verbosity level and
> independently turn global behaviour on and off by supplying a method a
> boolean or even the words 'on'|'off', not supplying int or undef
I prefer to leave it as it is. I don't think it is broken. Using
verbose() is pretty straightforward:
From Bio::Root::Root:
Title : verbose
Usage : $self->verbose(1)
Function: Sets verbose level for how ->warn behaves
-1 = no warning
0 = standard, small warning
1 = warning with stack trace
2 = warning becomes throw
Returns : The current verbosity setting (integer between -1 to 2)
Args : -1,0,1 or 2
sub verbose {
my ($self,$value) = @_;
# allow one to set global verbosity flag
return $DEBUG if $DEBUG;
return $VERBOSITY unless ref $self;
if (defined $value || ! defined $self->{'_root_verbose'}) {
$self->{'_root_verbose'} = $value || 0;
}
return $self->{'_root_verbose'};
}
According to RootI, the degree of verbosity for warn() is set to 0 by
default if verbose() is not set. Previously, verbose() wasn't
available unless the class inherited Bio::Root::Root. However, the
constructor for RootI indicates that Bio::Root::Root inheritance is
required (I think this came about prior to v1.4).
Anyway, the degree of verbosity is based on verbose() You should be
able to set this normally using most classes w/o problems, and turn
the warnings off (-1) or make the warnings throw instead (2) based
upon what you want to accomplish. It is set to 0 by default if it is
called at any time; it also only sets verbosity to a defined value
(in other words, it is not undef and cannot be set to undef; if you
can then there is something wrong). I don't think there are explicit
checks on the value set within verbose() but I don't see the problem
with that. Error handling methods like warn() do that for you.
Now, if you find that something doesn't work this way, it is a bug.
BTW, the reason you don't want simple 'on/off' is that you may want
different degrees of error handling strictness, hence a sliding and
easily testable scale. So, you should be able to turn warnings on
and off by resetting verbose() to the appropriate value. You could
also have any warning changed to a throw() instead.
The problem you'll find (as I have found) is some classes/interfaces
do not set verbose() based on parameters upon instantiation (i.e. you
could pass the parameter '-verbose' and it won't do anything). This
makes it hard to set error handling upon instantiation to a user-
defined value.
Others may not use RootI-implemented error handling/debugging
methods; they may use built-in warn or STDERR (ugh) instead of $self-
>warn(). And still others with internal objects may also neglect to
set '-verbose' for those objects based on the current object's
verbose value ($self->verbose). It's all based on how well the
classes are maintained and how well the maintainer knows BioPerl's
error handling mechanisms.
Christopher Fields
Postdoctoral Researcher
Lab of Dr. Robert Switzer
Dept of Biochemistry
University of Illinois Urbana-Champaign
More information about the Bioperl-l
mailing list