[svn:mod_parrot] r509 - in mod_parrot/trunk: eg/php lib/ModParrot/HLL

[email protected] Sun, 30 Nov 2008 08:36:08 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Sun Nov 30 08:36:07 2008
New Revision: 509

Modified:
   mod_parrot/trunk/eg/php/README
   mod_parrot/trunk/lib/ModParrot/HLL/pipp.pir

Log:
update pipp to new HLL module standards
support POST data


Modified: mod_parrot/trunk/eg/php/README
==============================================================================
--- mod_parrot/trunk/eg/php/README	(original)
+++ mod_parrot/trunk/eg/php/README	Sun Nov 30 08:36:07 2008
@@ -1,11 +1,10 @@
 This is a PHP implementation of "Polly" from the Perl 6 examples.  It uses
-the Plumhead compiler included with the Parrot distribution.  Place it in your
+the Pipp compiler included with the Parrot distribution.  Place it in your
 document root and configure as follows:
 
 ParrotIncludePath /path/to/parrot/runtime/library:/path/to/mod_parrot/lib
-ParrotLoad ModParrot/HLL/plumhead.pbc
+ParrotLoadImmediate ModParrot/HLL/pipp.pbc
 AddType application/x-httpd-php .php
-ParrotAddType plumhead application/x-httpd-php
 
 You will also want to set the PARROT_RUNTIME environment variable to your
 parrot build directory before starting Apache.  You can do this on the command

Modified: mod_parrot/trunk/lib/ModParrot/HLL/pipp.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/pipp.pir	(original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/pipp.pir	Sun Nov 30 08:36:07 2008
@@ -19,6 +19,22 @@
 .sub __onload :anon :load
     load_bytecode 'languages/pipp/pipp.pbc'
     load_bytecode 'CGI/QueryHash.pbc'
+    load_bytecode 'ModParrot/Apache/RequestRec.pbc'
+    load_bytecode 'ModParrot/Apache/Module.pbc'
+    load_bytecode 'ModParrot/Constants.pbc'
+
+    .local pmc add_module, cmds, hooks, mp_const
+
+    mp_const = get_root_global [ 'ModParrot'; 'Constants' ], 'table'
+
+    # we have no directives, so this will remain empty
+    cmds = new 'ResizablePMCArray'
+
+    hooks = new 'ResizablePMCArray'
+    $I0 = mp_const['MP_HOOK_RESPONSE']
+    hooks[0] = $I0
+    add_module = get_hll_global [ 'ModParrot'; 'Apache'; 'Module' ], 'add'
+    $P1 = add_module("modparrot_pipp_module", "pipp", cmds, hooks)
 .end
 
 .sub run_php_file
@@ -30,33 +46,57 @@
     .return($P1)
 .end
 
-#.sub config
-
 # response handler
-.sub handler
+.sub response_handler
     .param pmc ctx
-    .param string php_file
+    .local string php_file
     .local pmc r
     .local pmc ap_const
-    .local string args
+    .local string args, data
     .local int status
     .local pmc query_parse
     .local pmc get_hash, post_hash
     .local pmc interp
 
+    ap_const = get_root_global [ 'ModParrot'; 'Apache'; 'Constants' ], 'table'
+
     # get the request_rec object
     r = ctx.'request_rec'()
 
+    # is this PHP?
+    $S0 = r.'handler'()
+    if $S0 == 'application/x-httpd-php' goto have_php
+    status = ap_const['DECLINED']
+    .return(status)
+
+  have_php:
     # get the interpreter object
     interp = ctx.'interp'()
 
-    # parse query string
+    # parse query string (do this regardless of method)
     args = r.'args'()
     query_parse = get_hll_global [ 'CGI'; 'QueryHash' ], 'parse'
     get_hash = new 'Hash'
     get_hash = query_parse(args)
     set_hll_global '$_GET', get_hash
+
+    # parse POST data
+    $S0 = r.'method'()
+    unless $S0 == 'POST' goto run_script
+    $I0 = 0
+    $I1 = 8192
+    $P0 = new 'String'
+    $P1 = new 'String'
+  post_read_loop:
+    $I0 = r.'read'($P0, $I1)
+    $P1 .= $P0
+    if $I0 == $I1 goto post_read_loop
+    data = $P1
+    post_hash = new 'Hash'
+    post_hash = query_parse(data)
+    set_hll_global '$_POST', post_hash
     
+  run_script:
     php_file = r.'filename'()
     interp.'capture_stdout'(1)
     run_php_file(php_file)
@@ -66,7 +106,6 @@
     interp.'capture_stdout'(0)
     r.'puts'($S0)
 
-    ap_const = get_root_global [ 'ModParrot'; 'Apache'; 'Constants' ], 'table'
     status = ap_const['OK']
 
     .return(status)