When using multiple instances of a specific closure, the Perl debugger lists the same line number range for each instance, while the closures are actually different.
As the parameter to the debugger's b command is a line number, I wonder whether I can set a breakpoint to a specific closure.
Consider this interactive example:
DB<13> sub _s($) { my $s = $_[0]; sub () { $s }; }
DB<17> $s1 = _s(1)
DB<18> $s2 = _s(2)
DB<20> x $s1->()
0 1
DB<21> x $s2->()
0 2
DB<22> x $s1
0 CODE(0x55c7e8754958)
-> &main::__ANON__ in 0
DB<23> x $s2
0 CODE(0x55c7e8764990)
-> &main::__ANON__ in 0
So the code references clearly indicate that $s1 and $s2 are different.
Now could I set a breakpoint when $s1 is called?
Note
My first version tried sub s($) { ... }, resulting in syntax error ... (Might be a runaway multi-line ;; string starting on line 2) when trying to call s(1).
So it seems you cannot really override s/old/new/ ;-)
Another Note
If you set a breakpoint on a line like
my $checker = sub ($) { ... };
inside a subroutine (using closures inside closures), then execution stops each time when $checker is being assigned to, but not when the closure is being called.
My work-around for that was to insert line breaks like this (and set the breakpoint to the ... line):
my $checker = sub ($) {
...
};