[svn:mod_parrot] r342 - in mod_parrot/trunk: eg/perl6 languages languages/perl6 lib/ModParrot/HLL

[email protected] Thu, 29 May 2008 08:29:57 -0700 (PDT)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Thu May 29 08:29:56 2008
New Revision: 342

Added:
   mod_parrot/trunk/languages/
   mod_parrot/trunk/languages/perl6/
   mod_parrot/trunk/languages/perl6/mod_perl6.pm
   mod_parrot/trunk/lib/ModParrot/HLL/perl6-pir.pir
Modified:
   mod_parrot/trunk/eg/perl6/README
   mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir

Log:
mod_perl6 is now "pure perl"


Modified: mod_parrot/trunk/eg/perl6/README
==============================================================================
--- mod_parrot/trunk/eg/perl6/README	(original)
+++ mod_parrot/trunk/eg/perl6/README	Thu May 29 08:29:56 2008
@@ -1,5 +1,10 @@
-This directory contains example mod_perl6 handlers.  Until the perl6 compiler
-implements search paths, the HLL layer needs some help loading handler modules.
-In particular, you'll need to set the PARROT_RUNTIME and PERL6LIB environment
-variables, which you can do on the command line or in Apache's envvars script
-(found in the same directory as apachectl).
+This directory contains example mod_perl6 handlers.
+
+How to use mod_perl6:
+
+1) Create a directory for storing Perl 6 libraries.
+2) Copy languages/perl6/mod_perl6.pm to that directory.
+3) In the Apache's envvars script, set PERL6LIB to the directory you created,
+   and set PARROT_RUNTIME to your parrot source directory.
+4) Configure your handlers in httpd.conf (the examples contain instructions)
+5) Restart Apache (do a full stop and start if you've just changed envvars).

Added: mod_parrot/trunk/languages/perl6/mod_perl6.pm
==============================================================================
--- (empty file)
+++ mod_parrot/trunk/languages/perl6/mod_perl6.pm	Thu May 29 08:29:56 2008
@@ -0,0 +1,36 @@
+# $Id$
+
+# Copyright (c) 2007, 2008 Jeff Horwitz
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module ModParrot::HLL::perl6;
+
+our %loaded_modules;
+
+sub load($handler)
+{
+    unless (%loaded_modules{$handler}) {
+        use $handler;
+        %loaded_modules{$handler} = 1;
+    }
+}
+
+sub handler($ctx, $handler)
+{
+    my $r = $ctx.request_rec();
+    load($handler);
+    my $status = ::($handler)::handler($r);
+    # return $status;
+    $status;
+}

Added: mod_parrot/trunk/lib/ModParrot/HLL/perl6-pir.pir
==============================================================================
--- (empty file)
+++ mod_parrot/trunk/lib/ModParrot/HLL/perl6-pir.pir	Thu May 29 08:29:56 2008
@@ -0,0 +1,163 @@
+# $Id: perl6.pir 331 2008-01-25 19:27:12Z jhorwitz $
+
+# Copyright (c) 2007, 2008 Jeff Horwitz
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.namespace [ 'ModParrot'; 'HLL'; 'perl6' ]
+
+# 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 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
+
+    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'
+    $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
+
+#.sub config
+
+# response handler
+.sub handler
+    .param pmc ctx
+    .param string handler_name
+    .local string handler_sub
+    .local pmc handler
+    .local pmc r
+    .local pmc ap_const
+    .local int status
+
+    # get apache constants
+    ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
+
+    # get the request_rec object
+    r = ctx.'request_rec'()
+
+    # set the default handler sub name
+    handler_sub = 'handler'
+
+    # load the handler
+    push_eh REPORT_ERROR
+        handler = load(handler_name)
+    pop_eh
+
+    # 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
+    goto RETURN_STATUS
+
+REPORT_ERROR:
+    get_results '0,0', $P0, $S0
+    $S1 = handler_name
+    concat $S1, ": "
+    concat $S1, $S0
+    $I0 = ap_const['APLOG_ERR']
+    r.'log_rerror'(handler_name, 0, $I0, $S1)
+    status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
+
+RETURN_STATUS:
+    # return status code
+    .return(status)
+.end
+
+# authen handler
+.sub authen_handler
+    .param pmc ctx
+    .param string handler_name
+    .local string handler_sub
+    .local pmc handler
+    .local pmc r
+    .local pmc ap_const
+    .local int status
+
+    # get apache constants
+    ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
+
+    # get the request_rec object
+    r = ctx.'request_rec'()
+
+    # set the default handler sub name
+    handler_sub = 'handler'
+
+    # load the handler
+    push_eh REPORT_ERROR
+        handler = load(handler_name)
+    pop_eh
+
+    # run the handler, passing in Apache::RequestRec object
+    push_eh REPORT_ERROR
+        status = handler(r)
+    pop_eh
+    goto RETURN_STATUS
+
+REPORT_ERROR:
+    get_results '0,0', $P0, $S0
+    $S1 = handler_name
+    concat $S1, ": "
+    concat $S1, $S0
+    $I0 = ap_const['APLOG_ERR']
+    r.'log_rerror'(handler_name, 0, $I0, $S1)
+    status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
+
+RETURN_STATUS:
+    # return status code
+    .return(status)
+.end

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	Thu May 29 08:29:56 2008
@@ -16,148 +16,16 @@
 
 .namespace [ 'ModParrot'; 'HLL'; 'perl6' ]
 
-# 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
+    .local string mp6_path
+    .local pmc find_file_in_path
 
-.sub load
-    .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
-
-    loaded = get_hll_global 'loaded'
-    $P0 = loaded[handler]
-    handler_sub = 'handler'
-    handler_key = split '::', handler
-    unless_null $P0, RETURN_SUB
+    load_bytecode 'languages/perl6/perl6.pbc'
 
-    module_path = join '/', handler_key
-    env = new 'Env'
-    $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 = new 'Env'
+    $S0 = $P0['PERL6LIB']
+    find_file_in_path = get_hll_global ['_modparrot'], 'find_file_in_path'
+    mp6_path = find_file_in_path($S0, 'mod_perl6.pm')
     $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
-
-#.sub config
-
-# response handler
-.sub handler
-    .param pmc ctx
-    .param string handler_name
-    .local string handler_sub
-    .local pmc handler
-    .local pmc r
-    .local pmc ap_const
-    .local int status
-
-    # get apache constants
-    ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
-
-    # get the request_rec object
-    r = ctx.'request_rec'()
-
-    # set the default handler sub name
-    handler_sub = 'handler'
-
-    # load the handler
-    push_eh REPORT_ERROR
-        handler = load(handler_name)
-    pop_eh
-
-    # 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
-    goto RETURN_STATUS
-
-REPORT_ERROR:
-    get_results '0,0', $P0, $S0
-    $S1 = handler_name
-    concat $S1, ": "
-    concat $S1, $S0
-    $I0 = ap_const['APLOG_ERR']
-    r.'log_rerror'(handler_name, 0, $I0, $S1)
-    status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
-
-RETURN_STATUS:
-    # return status code
-    .return(status)
-.end
-
-# authen handler
-.sub authen_handler
-    .param pmc ctx
-    .param string handler_name
-    .local string handler_sub
-    .local pmc handler
-    .local pmc r
-    .local pmc ap_const
-    .local int status
-
-    # get apache constants
-    ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
-
-    # get the request_rec object
-    r = ctx.'request_rec'()
-
-    # set the default handler sub name
-    handler_sub = 'handler'
-
-    # load the handler
-    push_eh REPORT_ERROR
-        handler = load(handler_name)
-    pop_eh
-
-    # run the handler, passing in Apache::RequestRec object
-    push_eh REPORT_ERROR
-        status = handler(r)
-    pop_eh
-    goto RETURN_STATUS
-
-REPORT_ERROR:
-    get_results '0,0', $P0, $S0
-    $S1 = handler_name
-    concat $S1, ": "
-    concat $S1, $S0
-    $I0 = ap_const['APLOG_ERR']
-    r.'log_rerror'(handler_name, 0, $I0, $S1)
-    status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
-
-RETURN_STATUS:
-    # return status code
-    .return(status)
+    $P1 = $P0.'evalfiles'(mp6_path)
 .end