Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl changing the current package?

Tags:

perl

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.

like image 598
NO WAR WITH RUSSIA Avatar asked Oct 08 '10 22:10

NO WAR WITH RUSSIA


1 Answers

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.

like image 80
rafl Avatar answered Nov 26 '22 04:11

rafl