[ABE.pm] debug() from perltoot
Faber J. Fedor
faber at linuxnj.com
Wed May 17 16:34:04 PDT 2006
I'm working through the perltoot; mostly copying and pasting code
snippets and trying to get them to work. There's one debug routine in
perltoot that I don't get. In the "Overridden Methods" section, the author
says to add the following to the subclass:
use Carp;
my $Debugging = 0;
sub debug {
my $self = shift;
confess "usage: thing->debug(level)" unless @_ == 1;
my $level = shift;
if (ref($self)) {
$self->{"_DEBUG"} = $level;
} else {
$Debugging = $level; # whole class
}
$self->SUPER::debug($Debugging);
}
Further down in my subclass code, I have things like
carp $stmt."\n" if($Debugging);
In my calling program, I do this:
my $newTable = SummaryTable->new();
$newTable->debug(1);
and my carp-ing statement never get called.
After working through this, I've come to one of two conclusions: either
every subclass has a $self->{_DEBUG} defined (which means it should go
into the superclass) or I replace
if (ref($self)) {
$self->{"_DEBUG"} = $level;
} else {
$Debugging = $level; # whole class
}
with simply
$Debugging = $level;
So how is this overriding method supposed to work?
--
Regards,
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701
http://www.linuxnj.com
More information about the ABE-pm
mailing list