Author: jhorwitz
Date: Sat Sep 1 10:52:34 2007
New Revision: 245
Modified:
mod_parrot/trunk/lib/Apache/RequestRec.pir
mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir
Log:
NQP::Registry handler emulates CGI for NQP scripts
Modified: mod_parrot/trunk/lib/Apache/RequestRec.pir
==============================================================================
--- mod_parrot/trunk/lib/Apache/RequestRec.pir (original)
+++ mod_parrot/trunk/lib/Apache/RequestRec.pir Sat Sep 1 10:52:34 2007
@@ -173,14 +173,19 @@
=cut
.sub filename :method
- .param string f
+ .param string f :optional
+ .param int update_r :opt_flag
.local pmc r
.local pmc request_rec_filename
.local string filename
getattribute r, self, 'r'
request_rec_filename = get_root_global [ '_modparrot'; 'NCI' ], 'request_rec_filename'
- filename = request_rec_filename( r, f )
+ if update_r == 1 goto CALL_NCI
+ f = ""
+
+CALL_NCI:
+ filename = request_rec_filename( r, f, update_r )
.pcc_begin_return
.return filename
Modified: mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir (original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir Sat Sep 1 10:52:34 2007
@@ -26,7 +26,10 @@
.local string rpath
.local pmc env
- # prepend runtime path, if set
+ # if a relative path, prepend any runtime search path
+ $S0 = substr path, 0, 1
+ if $S0 == '/' goto LOAD_HANDLER
+
env = new 'Env'
rpath = env['PARROT_RUNTIME']
if_null rpath, LOAD_HANDLER
@@ -53,8 +56,27 @@
.local pmc handler
.local pmc r
.local pmc ap_const
+ .local pmc pio
.local int status
+ .local int registry
+
+ # get the request_rec object
+ $P0 = get_class [ 'Apache'; 'RequestRec' ]
+ r = new $P0
+
+ # NQP::Registry is a special case:
+ # 1. set handler path to apache's parsed filename
+ # 2. push "string" io layer to save script output for later processing
+ unless handler_name == 'NQP::Registry' goto PARSE_HANDLER
+ registry = 1
+ handler_path = r.'filename'()
+ pio = getstdout
+ push pio, "string"
+ handler_sub = "handler"
+ goto LOAD_HANDLER
+PARSE_HANDLER:
+ registry = 0
$P0 = split '::', handler_name
handler_sub = pop $P0
handler_path = join '/', $P0
@@ -67,10 +89,18 @@
handler = get_hll_global handler_sub
RUN_HANDLER:
+ # set default content type
+ r.'content_type'("text/html")
# run the handler, passing in Apache::RequestRec object
- r = new [ 'Apache'; 'RequestRec' ]
status = handler(r)
+ if registry == 0 goto RETURN_STATUS
+ $S0 = read pio, 1024
+ $S1 = pop pio
+ r.'puts'($S0)
+ status = 0
+
+RETURN_STATUS:
# return status code
.return(status)
.end
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.