[svn:mod_parrot] r246 - mod_parrot/trunk/lib/ModParrot/HLL

[email protected]
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Sun Sep  2 09:35:24 2007
New Revision: 246

Modified:
   mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir

Log:
port NQP::Registry to perl6 HLL


Modified: mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir	(original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir	Sun Sep  2 09:35:24 2007
@@ -16,23 +16,34 @@
 
 .namespace [ 'ModParrot::HLL::perl6' ]
 
-# XXX should replace with .HLL eventually
+# XXX should we replace this with .HLL?
 .sub __onload :anon :load
-    # this might need an absolute path until we can tweak the runtime prefix
     load_bytecode 'perl6.pbc'
 .end
 
 .sub _load
-    .param string module
+    .param string path
+    .local string rpath
+    .local pmc env
+
+    # 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
+    $S0 = rpath
+    concat $S0, "/"
+    concat $S0, path
+    path = $S0
 
+LOAD_HANDLER:
     # load & compile the Perl6 handler
-    $S0 = 'use '
-    concat $S0, module
     $P0 = compreg 'Perl6'
-    $P1 = $P0.'compile'($S0)
-    $P1()
+    $P1 = $P0.'evalfiles'(path)
 
-    .return(0)
+    .return($P1)
 .end
 
 #.sub _config
@@ -40,30 +51,56 @@
 # response handler
 .sub _handler
     .param string handler_name
+    .local string handler_path
     .local string handler_sub
-    .local string handler_module
-    .local pmc r
     .local pmc handler
+    .local pmc r
     .local pmc ap_const
+    .local pmc pio
     .local int status
+    .local int registry
 
-    # mod_perl uses NS::handler, but until Perl6 compiler supports namespaces,
-    # we'll use the subroutine name as the name of the handlers
+    # get the request_rec object
+    $P0 = get_class [ 'Apache'; 'RequestRec' ]
+    r = new $P0
+
+    # ModPerl6::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 == 'ModPerl6::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
-    push $P0, 'handler'
-    handler_sub = join '__', $P0
+    handler_sub = pop $P0
+    handler_path = join '/', $P0
+    concat handler_path, '.p6'
     handler = get_hll_global handler_sub
     unless_null handler, RUN_HANDLER
 
 LOAD_HANDLER:
-    $I0 = _load(handler_name)
+    $P0 = _load(handler_path)
     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.