[svn:mod_parrot] r309 - mod_parrot/trunk/lib/ModParrot/HLL
[email protected] Sun, 13 Jan 2008 08:15:48 -0800 (PST)
| Newsgroups | perl.cvs.mod_parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: jhorwitz
Date: Sun Jan 13 08:15:46 2008
New Revision: 309
Modified:
mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir
Log:
add support for passing module names as perl6 handlers
use PERL6LIB as a search path for modules
don't reload modules that have already been loaded
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 Jan 13 08:15:46 2008
@@ -19,30 +19,53 @@
# XXX should we replace this with .HLL?
.sub __onload :anon :load
load_bytecode 'languages/perl6/perl6.pbc'
+ $P0 = new Hash
+ set_hll_global 'loaded', $P0
.end
.sub load
- .param string path
- .local string rpath
+ .param string handler
+ .local string path
+ .local pmc libdirs
+ .local string prefix
+ .local string module_path
.local pmc env
+ .local pmc handler_key
+ .local string handler_sub
+ .local pmc loaded
- # if a relative path, prepend any runtime search path
- $S0 = substr path, 0, 1
- if $S0 == '/' goto LOAD_HANDLER
+ loaded = get_hll_global 'loaded'
+ $P0 = loaded[handler]
+ handler_sub = 'handler'
+ handler_key = split '::', handler
+ unless_null $P0, RETURN_SUB
+ module_path = join '/', handler_key
env = new 'Env'
- rpath = env['PARROT_RUNTIME']
- if_null rpath, LOAD_HANDLER
- $S0 = rpath
- concat $S0, "/"
- concat $S0, path
- path = $S0
-
+ $S0 = env['PERL6LIB']
+ unless $S0, LOAD_HANDLER
+ libdirs = split ':', $S0
+ $I0 = elements libdirs
+LIBDIR_LOOP:
+ dec $I0
+ prefix = libdirs[$I0]
+ path = prefix
+ path .= '/'
+ path .= module_path
+ path .= '.pm'
+ $I1 = stat path, 0
+ if $I1 goto LOAD_HANDLER
+ if $I0 goto LIBDIR_LOOP
+
LOAD_HANDLER:
# load & compile the Perl6 handler
$P0 = compreg 'Perl6'
$P1 = $P0.'evalfiles'(path)
+RETURN_SUB:
+ # return the sub
+ $P1 = get_hll_global handler_key, handler_sub
+ loaded[handler] = 1
.return($P1)
.end
@@ -51,14 +74,12 @@
# response handler
.sub handler
.param string handler_name
- .local string handler_path
.local string handler_sub
.local pmc handler
.local pmc r
.local pmc ap_const
.local pmc pio
.local int status
- .local int registry
# get apache constants
ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
@@ -67,54 +88,30 @@
$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
- handler_sub = pop $P0
- handler_path = join '/', $P0
- concat handler_path, '.p6'
- handler = get_hll_global handler_sub
- unless_null handler, RUN_HANDLER
+ # set the default handler sub name
+ handler_sub = 'handler'
-LOAD_HANDLER:
+ # load the handler
push_eh REPORT_ERROR
- $P0 = load(handler_path)
+ handler = load(handler_name)
pop_eh
- 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
push_eh REPORT_ERROR
status = handler(r)
pop_eh
-
- if registry == 0 goto RETURN_STATUS
- $S0 = read pio, 1024
- $S1 = pop pio
- r.'puts'($S0)
- status = 0
goto RETURN_STATUS
REPORT_ERROR:
get_results '0,0', $P0, $S0
- $S1 = handler_path
+ $S1 = handler_name
concat $S1, ": "
concat $S1, $S0
$I0 = ap_const['APLOG_ERR']
- r.'log_rerror'(handler_path, 0, $I0, $S1)
+ r.'log_rerror'(handler_name, 0, $I0, $S1)
status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
RETURN_STATUS: