Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: own "mod_perl" implemenation

by gmpassos (Priest)
on Apr 06, 2004 at 04:37 UTC ( [id://342832]=note: print w/replies, xml ) Need Help??


in reply to own "mod_perl" implemenation

I think that what you want is to embed Perl in your server.

Embed Perl in other C program is not difficult, but mod_perl is much more than just Perl inside apache. mod_perl works directly with Apache, and you can handle and control a lot of behaviors of Apache from Perl.

But I don't want to discourage you. Soo, first perlembed in your App. Than you need to redirect the output of Perl to the socket of the client, without forget the reverse of that, the input (STDIN). Well, I think that you have done something like that for CGI.

After do the IO work, you need to overwrite exit() and die(), since you can't let the Perl script to close or dump your server. And the work goes. Soo, you will need to like to hack the Perl internals.

Also you can do a lot of this changes with pure Perl, since the language let you change the Perl interpreter behavior. Soo, here are some modules that can help you to do the pure Perl changes:

  • Die::Alive
  • Safe::World
  • Also you can talk with the mod_perl folks. They can help you, or give you some light.

    Good luck! ;-P

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

    Replies are listed 'Best First'.
    Re^2: own "mod_perl" implemenation
    by esskar (Deacon) on Jul 25, 2005 at 23:43 UTC
      Okay; I finally got time to work on this issue. I looked at Die::Alive and Safe::World but this not quit what i want!
      I wrote a C++ wrapper around the <edit>Perl-</edit> C-API which has a function to overwrite a internal perl funcion which looks like this:
      static const char *CoreGlobal = "CORE::GLOBAL"; bool Interpreter::Overwrite(const char *funcname, const char *newfunc) { if(!gv_stashpv(CoreGlobal, 0)) return false; static size_t len_CoreGlobal = strlen(CoreGlobal); size_t len = strlen(funcname); size_t size = len_CoreGlobal + len + 16; char *fullfuncname = new char[size]; strncpy(fullfuncname, CoreGlobal, size); strncat(fullfuncname, "::", size); strncat(fullfuncname, funcname, size); GV *funcgp = gv_fetchpv(fullfuncname, TRUE, SVt_PVCV); GvCV(funcgp) = perl_get_cv(newfunc, TRUE); GvIMPORTED_CV_on(funcgp); delete [] fullfuncname; return true; }
      now i can do something like the following
      Interpreter perl; perl.Overwrite("exit", "Foo::bar");
      which would substitute perl's exit with the function bar from the Foo package. (Not ensuring that Foo is already loaded!)
      The question is now how to achieve the following:
      Everytime the script calls "exit" (or possible die, or similar) my interpreter won't exit but the script stops running.

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://342832]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2024-04-19 03:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found