It seems that it's cleaning up the pad too early:
sub search {
my ( $self, $test ) = @_;
my $where;
my $found = 0;
my $counter = 0;
$self->descend( pre_each => sub {
my $lvl = shift;
my $ev_return
= $lvl->each_value( sub {
$counter++;
my ( $name, $value ) = @_;
say "\$name=$name";
say "\$value=$value";
return 1 unless $found = $test->( $value );
$where = { key => $lvl, name => $name, value => $value };
# when any intermediate function sees QUIT_FLAG, it
# knows to return control to the method that called it.
return QUIT_FLAG;
});
say "\$found=$found";
say "\$where=$where";
return $ev_return;
});
say "\$counter=$counter";
say "\$found=$found";
say "\$where=$where";
return unless $found;
return $where;
}
And what I get is:
...
$found=1
$where=HASH(...)
$counter=0
$found=0
$where=
Or, if anybody can point to something bone-headed I'm doing, I'd really appreciate it. I even created incremental variables between the first and outer closure, but they got reset too. Even setting references on the innermost closure, gets me nothing in the named sub scope!
The entire code concerned here is 500 lines. It is impractical to include the code.
It would be really good if you could provide a complete, runnable example.
Stab in the dark: does it help to have an extraneous use of $found in the outer anonymous sub (e.g. $found if 0;
)?