I have just released this new module to CPAN. Since is hard to make an enverioment like thak work inside an object, I will be glad if the monks can test this module, specially trying to use it in hard ways. ;-P

With Safe::World you can create multiple virtual instances/compartments of a Perl interpreter, that will work/run without touch the other instances/compartments and mantaining the main interpreter normal.

Each instance (WORLD object) has their own STDOUT, STDERR and STDIN handlers, also has a fake HEADOUT output for the headers implemented inside the STDOUT. Soo, you can use this to redirect the outputs of the WORLD object to a FILEHANDLER, SCALAR or a SUB.

The module Safe::World was created for 3 purposes:

1. A Safe compartment that can be "fully" cleanned.

2. A Safe compartment with the output handlers implemented, creating a full WORLD, working as a normal Perl Interpreter from inside.

3. A WORLD object (a virtual Perl interpreter) that can be linked/assembled with other WORLD objects, and work/run as if the objects where only one, than be able to unlink/disassemble them.

The last is the advanced purpose, that need all the previous resources, and most important thing of Safe::World. Actually this was projected to work with mod_perl, soo the Perl codes can be runned in different compartments, but can have some part of the code cached in memory, specially the Perl Modules (Classes) that need to be loaded all the time.

Soo, you can load your classes in one World, and your script/page in other World, then link them and run your code normally. Then after run it you unlink the 2 Worlds, and only CLEAN the World with your script/page, and now you can keep the 1st World with your Classes cached, to link it again with the next script/page to run.

To get it:
http://cpan.org/authors/id/G/GM/GMPASSOS/Safe-World-0.01.tar.gz

I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P
And please, test it!

Graciliano M. P.
"Creativity is the expression of the liberty".

  • Comment on Safe::World/0.01 - Create multiple virtual instances of a Perl interpreter that can be assembled together.

Replies are listed 'Best First'.
Re: Safe::World/0.01 - Create multiple virtual instances of a Perl interpreter that can be assembled together.
by liz (Monsignor) on Nov 30, 2003 at 11:01 UTC
    I may not be getting it. But I got the following test results under Linux:
    • 5.6.2: core dumps
    • 5.8.0-unthreaded fails in tests 7,9,11,18.20,22,28
    • 5.8.1-unthreaded fails in tests 7,9,11,18.20,22,28
    • 5.8.2-unthreaded fails in tests 7,9,11,18.20,22,28
    • 5.8.0-threaded fails in tests 7,9,11,18.20,22,28
    • 5.8.1-threaded fails in tests 7,9,11,18.20,22,28
    • 5.8.2-threaded fails in tests 7,9,11,18.20,22,28
    • 5.9.0-unthreaded fails in tests 7,9,11,18.20,22,28
    • 5.9.1-unthreaded fails in tests 7,9,11,18.20,22,28
    /msg me if you want more information.

    Liz

    Update:
    Your pod states:

    CLEAN
    Call DESTROY() and clean the compartment.
    I haven't looked at the source code, but in general it's a bad idea to call DESTROY yourself. It will get called again by Perl when the object is really destroyed (e.g. at global destruction).
      First thanks for the tests, and to send them by e-mail. You helped a lot to fix the bugs. Version 0.02 is on the way.

      About the call of DESTROY() from CLEAN(), well, as is documented in POD, CLEAN() shouldn't be called by hand, only by DESTROY. Actually DESTROY() call CLEAN(), but if you call CLEAN before DESTROY, CLEAN call DESTROY to make the rigth process. Soo, I use some flags to ensure that DESTROY and CALL are called only 1 time, and to avoid a recursion loop.

      Graciliano M. P.
      "Creativity is the expression of the liberty".

Re: Safe::World/0.01 - Create multiple virtual instances of a Perl interpreter that can be assembled together.
by Anonymous Monk on Nov 30, 2003 at 05:20 UTC
    This is a interesting approach. Can be very useful with mod_perl to run CGI.

    I have no idea how you have implemented that just with pure Perl! :)