Soft call operator: ~> (thoughts)

Short presentation of The new Perl debugger

The link of the project

You may Download presentation or view short video

The main feature of new debugger is debugging debugger commands. Yes you may debug itself (reentrance is not limited). This mean you may extend debugger easily. That is possible because of state of each debugger "copy" is saved in special array accessible through $DB::state

To enable debugger debugging (dd) you turn on this state then run command, you want to debug, after that. Example how to enable debugging debugger command 'step over' (n):

DB::state( 'dd', 1 );
n

Besides new debugger you get the new method to debug scripts and may forget about debugging by 'print' statements.

Now you just put special comment: #DBG: EXPR #

my $x =  { a =>  7 };

for( 1 .. 3 ) {
  #DBG:iter $_ #
  $x->{ a }++;
}

#DBG: e $x #

and get extended output while running script under debugger like this:

$ perl -d:DebugHooks::KillPrint            t.pl

1
2
3
{ a => 10 }

You may also limit output by writing the name of expression you are interested in:

$ perl -d:DebugHooks::KillPrint=iter       t.pl

1
2
3

Do not pass perl globals as arguments to subroutines

Recently I faced this problem when loose an exception message in Mojolicious

What do you think is wrong here

$c->helpers->reply->exception($@) unless eval { $next->(); 1 };

For first sight nothing. We eval code and then catch exception if it is and pass error into sub. But we forget that when arguments are passed into subroutine they are aliased into @_ NOT COPIED (Maybe we forgot that because of it is not documented here ) but, thanks, documented here

 The array @_ is a local array, but its elements are aliases for the actual scalar parameters.

So @_ contain aliases. What does that matter? Look please at this small example:

sub test {
  $@ =  'Oops';
  my( $x ) =  @_;
  print $x; # Oops
}
$@ =  'Exception';
test( $@ );

As you can see between subroutine call and arguments coping there is something may happen and change your global variable. As result you do not get the value you pass into subroutine.

As workaround this problem, I think, you should never pass globals. Take care and pass copies of them:

test( my $copy = $@ );

Aliasing hurts not only perl internal global variables that hurts every global variable:

test( my $copy = $YourPackage::variable );

Hope this small note will save your time when you wanna pass global variable into subroutine.