Changes between Version 35 and Version 36 of ModParrotHLLDocs

Show
Ignore:
Timestamp:
01/02/09 00:58:45 (13 years ago)
Author:
jhorwitz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ModParrotHLLDocs

    v35 v36  
    351351}}} 
    352352 
    353 === Capturing Output === 
    354  
    355 TODO 
     353=== I/O Redirection === 
     354 
     355mod_parrot can tie Parrot I/O operations on standard input and output to an Apache request, emulating CGI behavior.  This is useful when you either don't want to expose the Apache API to the language, or the language lacks the features to support it (i.e. no objects). 
     356 
     357To tie a request to stdin or stdout, use the {{{stdin}}} and {{{stdout}}} methods of {{{ModParrot;Interpreter}}}. 
     358 
     359 * {{{PMC stdin(PMC handle)}}} 
     360 * {{{PMC stdout(PMC handle)}}} 
     361 
     362{{{handle}}} is a PMC of one of the following types: 
     363 
     364 * {{{ModParrot;Apache;RequestRec}}} - ties I/O on to the request 
     365 * {{{FileHandle}}} - assigns the filehandle object 
     366 
     367Each method returns the previous handle so you can restore it later.  You must always restore stdin and stdout before returning from a metahandler. 
     368 
     369Here is code adapted from Pipp's response metahandler.  It ties the request to stdin and stdout, runs the requested PHP script, and restores stdin and stdout to their original filehandles. 
     370 
     371{{{ 
     372interp = ctx.'interp'() 
     373php_file = r.'filename'() 
     374oldout = interp.'stdout'(r) 
     375oldin = interp.'stdin'(r) 
     376r.'content_type'("text/html") 
     377run_php_file(php_file) 
     378interp.'stdout'(oldout) 
     379interp.'stdin'(oldin) 
     380}}} 
    356381 
    357382=== Return Values ===