tags:

views:

81

answers:

1

Without using a source-filter, is there a way to change the current running package? I'm trying to accomplish the same thing oose.pm does, and I'm wondering if I can drop my users in a non-main package.

+5  A: 

I think you'll be able to do that by changing PL_curstash and PL_curstname on the C level.

PL_curstash = gv_stashpvs("Some::Package", GV_ADD);
sv_setpvs(PL_curstname, "Some::Package");

PL_curstash is the stash of the current package during compilation, PL_curstname is its name.

Update:

I've found this problem kind of interesting and implemented the solution as Devel::ChangePackage. Turns out what I initially suggested just works. You can get it either from http://github.com/rafl/devel-changepackage, or from a CPAN mirror near you once they have updated.

rafl
But he's trying to change the _caller's_ package, not his own.
cjm
That's why he should do the above instead of pushing curstash and curstname onto the save stack and making the changes local to the current scope, like the package keyword would do.
rafl