rinceWind has asked for the wisdom of the Perl Monks concerning the following question:
In the process of working on a module for persistent coderefs, I have been intrigued as to the wherefores of the debugger when executing inside eval code. Usually it gets it right, and displays the correct line of code it is evaluating.
My question is: how does the debugger know anything about lines of dynamic code under the circumstances?
Secondly, if the code being run is a coderef, does the debugger have a clue about this?
I am interested in some general infomation about how the debugger obtains information about what it is running, in particular, code inside evals and passed coderefs.
Here is the code I have been developing. I am trying to make the debug mode (as set by $foo->debug(1)) able to give a better hint as to what is happening at expense of execution speed.
use strict; package Persistent::Code; sub new { my ($class,$src,$permflag) = @_; my %flags; $flags{'perm'} = 1 if $permflag; my $cr = eval "sub { $src }"; return undef if $@; my $self = [$cr,$src,\%flags]; bless $self, $class; } sub src { my $self = shift; $self->[1]; } sub coderef { my $self = shift; $self->[0]; } sub debug { my $self = shift; @_ ? ($self->[2]{debug} = shift) : $self->[2]{debug}; } sub perm { my $self = shift; @_ ? ($self->[2]{perm} = shift) : $self->[2]{perm}; } sub run { my $self = shift; my $pkg = ref $self; if ($self->[2]{debug}) { my $src = $self->[1]; print "eval: ",$src; wantarray ? eval "(&sub {$src}(@_))" : eval "&sub {$src}(@_)" +; } else { goto &{$self->[0]}; } } sub STORABLE_freeze { my ($self,$cloning) = @_; $self->[2]{perm} ? $self->[1] : ''; } sub STORABLE_thaw { my ($obj,$cloning,$code) = @_; return if !$code; my $class = ref $obj; my $newobj = $class->new($code,'perm'); @$obj = @$newobj; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: On debugging coderefs and inside evals
by erikharrison (Deacon) on Mar 16, 2002 at 03:25 UTC | |
by rinceWind (Monsignor) on Mar 16, 2002 at 20:17 UTC |