パッドのクリーンアップが早すぎるようです:
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;
}
そして、私が得るものは次のとおりです。
...
$found=1
$where=HASH(...)
$counter=0
$found=0
$where=
または、誰かが私がやっていることを指し示すことができれば、本当に感謝します. 最初のクロージャーと外側のクロージャーの間にインクリメンタル変数を作成しましたが、それらもリセットされました。最も内側のクロージャーに参照を設定しても、名前付きサブスコープには何もありません!
ここで関係するコード全体は 500 行です。コードを含めることは実際的ではありません。