Devel::StackTrace

Devel::StackTrace

am 16.11.2006 15:06:53 von Billy Patton

I'm trying to use Devel::StackTrace 1.13
I have a module that I want to limit it's scope to reporting just one
module.
I can't even get it to limit according to the docs.
Here is my subroutine that calls it.
sub debug(;$$)
{
my ($msg,$level) = @_; # the level and message
return unless $::Debug; # if global 0 return
$level = 1 unless defined $level; # set default level
return unless $level <= $::Debug; # make sure that level
passed in is >= global
my @ignore_packages = qw (
HTML
GenDeck
);
my $trace = Devel::StackTrace->new(ignore_class =>
\@ignore_packages
,ignore_package =>
\@ignore_packages
);
my $line = (caller(0))[2]; # get line debug called
from
my $caller = (caller(1))[3];
print STDOUT ' ' x $level; # indent according to
level
print STDOUT "$caller from line# $line\n";
print STDOUT $trace->as_string; # print stack trace
}

Sorry I can't send more but it's too much stuff. The first 2 print
STDOUT are hold overs from the original debug calls. THen I started
trying to use Devel::StackTrace. This will trim down once I get the
stack trace to working.

Re: Devel::StackTrace

am 17.11.2006 00:21:03 von paduille.4060.mumia.w

On 11/16/2006 08:06 AM, bpatton wrote:
> I'm trying to use Devel::StackTrace 1.13
> I have a module that I want to limit it's scope to reporting just one
> module.
> I can't even get it to limit according to the docs.
> Here is my subroutine that calls it.
> sub debug(;$$)
> {
> my ($msg,$level) = @_; # the level and message
> return unless $::Debug; # if global 0 return
> $level = 1 unless defined $level; # set default level
> return unless $level <= $::Debug; # make sure that level
> passed in is >= global
> my @ignore_packages = qw (
> HTML
> GenDeck
> );
> my $trace = Devel::StackTrace->new(ignore_class =>
> \@ignore_packages
> ,ignore_package =>
> \@ignore_packages
> );
> my $line = (caller(0))[2]; # get line debug called
> from
> my $caller = (caller(1))[3];
> print STDOUT ' ' x $level; # indent according to
> level
> print STDOUT "$caller from line# $line\n";
> print STDOUT $trace->as_string; # print stack trace
> }
>
> Sorry I can't send more but it's too much stuff. The first 2 print
> STDOUT are hold overs from the original debug calls. THen I started
> trying to use Devel::StackTrace. This will trim down once I get the
> stack trace to working.
>

The 'ignore_package' option only recognizes exact package names--not
hierarchies--and that might force you to make the @ignore_packages array
much bigger than you thought. Rather than to print the trace data
directly, you'll have to use s/// to remove the undesired lines first.

#!/usr/bin/perl

use strict;
use warnings;
use Alias;
use Devel::StackTrace;

my $template = '
my $num = $_[0];
if ($num > 6) {
return ::debug();
} else {
recurse($num + 1);
}
';


package Alpha;
eval "sub recurse { $template }";

package Beta;
eval "sub recurse { $template }";

package Beta::Carotene;
eval "sub recurse { $template }";

package Lambda;
eval "sub recurse { $template }";

package main;

sub debug {
# Create the new stack tracer.
my $trace = Devel::StackTrace->new();
my $str = $trace->as_string();

# Ignore the entire Beta hierarchy.
$str =~ s/^Beta::.*$//mg;
$str =~ s/\n+/\n/sg;
print $str;
0;
}

Alpha::recurse(0);
Beta::recurse(0);
Beta::Carotene::recurse(0);
Lambda::recurse(0);


--
paduille.4060.mumia.w@earthlink.net