[Petal] [Utils] Error log messages
Steve Purkis
spurkis at mkdoc.com
Tue Sep 9 15:58:23 BST 2003
On Tuesday, September 9, 2003, at 01:04 pm, William McKee wrote:
> On Tue, Sep 09, 2003 at 12:38:35PM +0100, Steve Purkis wrote:
>> A debug flag is an excellent idea, but for consitency across the Petal
>> project it would ideally be added to Petal and used by Petal::Utils.
>> There are plenty of ways to do this, if anyone's interested let me
>> know.
>
> Seems like the best solution would be to set it as an option when the
> Petal object is created (or as a global)?
Ideally, both. But at the very least, as a class var. Here's yet
another debugging algorithm (what I currently do in Pangloss):
$Pangloss::DEBUG{'Class::Foo'} = 1; # class-level debugging
$Pangloss::DEBUG{ ALL } = 1; # debug all classes
$foo->emit( 'a message' );
And in Pangloss::Object you have:
sub emit {
my $self = shift;
my $mesg = shift;
my $class = $self->class;
my ($package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask) = caller( 1 );
$subroutine =~ s/.*:://;
if ($Pangloss::DEBUG{ ALL } || $Pangloss::DEBUG{ $class }) {
my $warn_str = "[$class\::$subroutine] $mesg";
$warn_str .= "\n" unless $mesg =~ /\n/;
warn( $warn_str );
}
return $self;
}
sub class {
my $thing = shift;
return ref($thing) || $thing;
}
Adding per-object debugging wouldn't be difficult. Heck, you could
even do trees by sticking a grep in there...
food for thought,
-Steve
More information about the Petal
mailing list