Hello Monks,

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;

In reply to On debugging coderefs and inside evals by rinceWind

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.