Mattsteel - 2009-07-27

Hello all.

I'm using this IDE since months, and have to say this is a good IDE,
light, simple, easy to use, but not bug-free ;-)

I found a subtle bug in perl5db.pl module trying this piece of script:

my $code = sub { print "hello\n" } ;
print "Let's call $code\n";
$code->();
print "Done.\n";

During a normal debug session, moving the mouse over the variable
$code (that is a code-reference, i.e. ref($code) returns CODE), the IDE
replies with an “<undef>” which is not right. The same thing happens
listing $code in the “variable” watch-window.

I tried to fix it and patched the perl5db.pl module to handle this
case, so the IDE replies something like “$code: code = 0x1a81c40”.

Since the module source is more than 700 lines long, I think useful
giving here the four chunks I added: I simply added another "elsif"
case just before the ending "else", so you should be able to insert
these few lines directly in your dbTemplate.txt in the correct
position.

#within SizeOfDerefValue sub:
  } elsif ($refType eq 'CODE') {
    return length($reference);

#within ShortEval sub:
  } elsif ($refType eq 'CODE') {
    $reference =~ /\((.*)\)/;
    return "code = $1";

#within LongEval sub:
  } elsif ($refType eq 'CODE') {
      $reference =~ /\((.*)\)/;
      $retValue = "code = $1";

#within ShowDerefValues sub:
  } elsif ($refType eq 'CODE') {
    $type = "code";
    $reference =~ /\((.*)\)/;
    $value = "$1";

I also fixed the HashToStr sub to return immediately if it not an Hash:

sub HashToStr {
  my ($hashRef) = @_;
  my $value;
  return "$hashRef" unless ref($hashRef) eq 'HASH';
  #...

And, last, I improved the InternalEvalCode sub to avoid subtle crashes.

sub InternalEvalCode {
  my $statement = shift;
  my $olddie = $SIG{__DIE__};
  my $result;
  $SIG{__DIE__} = sub { $result = 0 } ;
  $result = eval qq{ $statement } ;
  $SIG{__DIE__} = $olddie;
  return $result;
}

Regards.
M.