[svn:mod_parrot] r479 - mod_parrot/trunk/languages/perl6/lib

[email protected] Tue, 4 Nov 2008 11:24:52 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Tue Nov  4 11:24:51 2008
New Revision: 479

Modified:
   mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm

Log:
implement Perl6Module


Modified: mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm
==============================================================================
--- mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm	(original)
+++ mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm	Tue Nov  4 11:24:51 2008
@@ -20,8 +20,6 @@
 use ModParrot::Const;
 use Apache::Const;
 
-our @preloaded_modules = ();
-our @postconfig_requires = ();
 our %loaded_modules;
 
 sub load($handler)
@@ -35,6 +33,8 @@
 sub server_create()
 {
     my %cfg;
+    %cfg<preloaded_modules> = [];
+    %cfg<postconfig_requires> = [];
     return %cfg;
 }
 
@@ -49,14 +49,14 @@
     my $r = $ctx.request_rec();
 
     unless ($r.handler() ~~ any(<modperl6 perl6-script>)) {
-        return $Apache::Const::DECLINED
+        return $Apache::Const::DECLINED;
     }
 
     my %cfg = ModParrot::Apache::Module::get_config("modparrot_perl6_module");
     my %dircfg = ModParrot::Apache::Module::get_config("modparrot_perl6_module",
         $r.per_dir_config());
 
-    my $handler = %dircfg{'response_handler'};
+    my $handler = %dircfg<response_handler>;
     load($handler);
 
     $r.content_type('text/html');
@@ -64,26 +64,29 @@
     return $status;
 }
 
-sub post_config_handler($ctx, $handler)
+sub post_config_handler($ctx)
 {
     #my $conf_pool = $ctx.conf_pool();
     #my $log_pool = $ctx.log_pool();
     #my $temp_pool = $ctx.temp_pool();
     #my $s = $ctx.server_rec();
+    my %cfg = ModParrot::Apache::Module::get_config("modparrot_perl6_module");
 
     # preload modules
-    for @preloaded_modules -> $m {
-        # XXX fix when namespace interpolation works
-        # use ::($m);
-        eval "use $m";
+    for %cfg<preloaded_modules> -> $m {
+        use $m;
     }
 
     # load postconfig requires
-    for @postconfig_requires -> $r {
-        # XXX does this work???
+    for %cfg<postconfig_requires> -> $r {
         require $r;
     }
 
+    my $handler = %cfg<post_config_handler>;
+    unless ($handler) {
+        return $Apache::Const::OK;
+    }
+
     # run the postconfig handler
     load($handler);
     #my $status = ::($handler)::handler($conf_pool, $log_pool, $temp_pool, $s);
@@ -93,12 +96,25 @@
 
 sub cmd_perl6responsehandler(%dircfg, @args)
 {
-    %dircfg{'response_handler'} = @args[0];
+    %dircfg<response_handler> = @args[0];
+}
+
+sub cmd_perl6module(%mconfig, @args)
+{
+    my %cfg := ModParrot::Apache::Module::get_config("modparrot_perl6_module");
+    push(%cfg<preloaded_modules>, @args[0]);
 }
 
 # register configuration directives
 my @cmds = (
     {
+        'name' => 'Perl6Module',
+        'args_how' => $Apache::Const::TAKE1,
+        'func' => &cmd_perl6module,
+        'req_override' => $Apache::Const::RSRC_CONF,
+        'errmsg' => 'usage: Perl6Module module'
+    },
+    {
         'name' => 'Perl6ResponseHandler',
         'args_how' => $Apache::Const::TAKE1,
         'func' => &cmd_perl6responsehandler,
@@ -109,6 +125,7 @@
 
 # register hooks
 my @hooks = (
+    $ModParrot::Const::MP_HOOK_POST_CONFIG,
     $ModParrot::Const::MP_HOOK_RESPONSE
 );