Jesse Luehrs wrote:
> On Tue, Jul 10, 2012 at 05:05:45AM -0000, Father Chrysostomos wrote:
> > Anything else is madness.
>
> I'm fine with this. My question is - how do you do this from perl space,
> if you don't know the name of the stash (as in, you just have the
> hashref)? I had been using Symbol::gensym in my code to generate new
> stash entries, but that's clearly wrong, because they have the wrong
> name. So... how do they get the right name? (If this isn't currently
> possible, should Symbol be rewritten with some XS to allow for doing
> the right thing?)
Temporary aliasing works:
sub vivify_isa {
my $stashref = shift;
local *__CLASS__:: = $stashref;
*{"__CLASS__::ISA"};
return;
}
use Devel::Peek;
Dump $foo::{ISA}; # a PVLV, because it does not exist
vivify_isa \%foo::;
Dump $foo::{ISA}; # GvSTASH points to foo
Dump \@{$foo::{ISA}};
Thread Previous