Delegate off to methods declared in the same package as the coderef, eg:
{ package Foo; sub gen { my $x; sub { $x * 2; }; sub inc_x { $_[0]->x++ } }  my $foo = Foo::gen; $foo->inc_x;
Uses B to inspect the coderef to get the package name it was created in.
This mechanism has priority over finding variables with PadWalker::closed_over().