package Devel::TraceState; # Initial code from Devel::Trace $VERSION = '0.01'; use Devel::StackTrace::WithLexicals; use Data::Dumper; $TRACE = 1; # This is the important part. The rest is just fluff. sub DB::DB { return unless $TRACE; my $trace = Devel::StackTrace::WithLexicals->new( #ignore_package => qr/^(?!main)(....)?/ ignore_package => qr/^Devel/ ); my ($p, $f, $l) = caller; my $code = \@{"::_<$f"}; print STDERR ">> $f:$l: $code->[$l]"; #print STDERR Dumper($trace); print STDERR $trace->as_string; #print STDERR Dumper($trace->frame(1)->lexicals) if $f =~ /^hmm/ && $trace->frame(1); print STDERR Dumper([$trace->frames]) if $f =~ /^hmm/ && $trace->frame(1); } sub import { my $package = shift; foreach (@_) { if ($_ eq 'trace') { my $caller = caller; *{$caller . '::trace'} = \&{$package . '::trace'}; } else { use Carp; croak "Package $package does not export `$_'; aborting"; } } } my %tracearg = ('on' => 1, 'off' => 0); sub trace { my $arg = shift; $arg = $tracearg{$arg} while exists $tracearg{$arg}; $TRACE = $arg; } 1;