>>httpd -DTRANS_REALLY_LAST -DRESPONSE_REALLY_FIRST
>>
>>etc...
>>
>>so it would be neither a compile time option, nor a configuration
>>option, but a program define.

well this was the harder of the two (compile time vs configure time) to
implement, so I started with it :)

attached is a rough patch.  options are:

  -DMODPERL_HOOK_ALL_LAST

  -DMODPERL_HOOK_FIXUP_FIRST
  -DMODPERL_HOOK_FIXUP_REALLY_FIRST
  -DMODPERL_HOOK_FIXUP_MIDDLE
  -DMODPERL_HOOK_FIXUP_LAST
  -DMODPERL_HOOK_FIXUP_REALLY_LAST

  (likewise for each request handler except content generation, which isn't
an issue).

the default is still APR_HOOK_REALLY_FIRST for all of them, which is why
there is no -D option for it.  and MODPERL_HOOK_ALL_MIDDLE is just too
strange to provide a shortcut.  the loner, MODPERL_HOOK_ALL_LAST really
shifts all handlers to APR_HOOK_ALL_REALLY_LAST, since I figured that in one
stroke you would either want them really first (default) or really last -
for everything else you can tweak each handler manually.

the implementation allows specific handlers to override
-DMODPERL_HOOK_ALL_LAST, so if you have both -DMODPERL_HOOK_ALL_LAST and
-DMODPERL_HOOK_FIXUP_REALLY_FIRST everything will run last except fixups.

also attached is the test suite I used to play around with it, though you'll
need a patched A-T to run it (defines.patch included in the dist).

anyway, I'm not entirely convinced that -D switches are the way to go with
this (imagine the jumble trying to shift just a few phases), but it's
something to chew on over the weekend :)

--Geoff
Index: lib/ModPerl/Code.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/lib/ModPerl/Code.pm,v
retrieving revision 1.117
diff -u -r1.117 Code.pm
--- lib/ModPerl/Code.pm 20 Feb 2004 14:11:31 -0000      1.117
+++ lib/ModPerl/Code.pm 20 Feb 2004 20:30:39 -0000
@@ -208,7 +208,7 @@
 sub generate_handler_hooks {
     my($self, $h_fh, $c_fh) = @_;
 
-    my @register_hooks;
+    my (@register_hooks, @order_imp);
 
     while (my($class, $prototype) = each %{ $self->{hook_proto} }) {
         my $callback = canon_func('callback', $class);
@@ -222,11 +222,17 @@
             if (my $hook = $hooks{$handler}) {
                 next if $not_ap_hook{$hook};
 
-                my $order = $not_request_hook{$hook} ? 'APR_HOOK_FIRST'
-                                                     : 'APR_HOOK_REALLY_FIRST';
+                my $uc_hook = uc($hook);
+
+                my $order = $not_request_hook{$hook} ? 
+                                'APR_HOOK_FIRST'     :
+                                "MODPERL_HOOK_${uc_hook}_ORDER()";
 
                 push @register_hooks,
                   "    ap_hook_$hook($name, NULL, NULL, $order);";
+
+                push @order_imp, "MODPERL_HOOK_SET_ORDER_IMP(${uc_hook})"
+                    unless $not_request_hook{$hook};
             }
 
             my($protostr, $pass) = canon_proto($prototype, $name);
@@ -253,7 +259,38 @@
     local $" = "\n";
     my $hooks_proto = 'void modperl_register_handler_hooks(void)';
     my $h_add = "$hooks_proto;\n";
-    my $c_add = "$hooks_proto [EMAIL PROTECTED]";
+
+    # ok, so this is ugly...
+    my $c_add = <<'EOF';
+#define MODPERL_HOOK_SET_ORDER_IMP(phase) \
+static int MODPERL_HOOK_##phase##_ORDER(void) \
+{ \
+    int order = APR_HOOK_REALLY_FIRST; \
+    if (ap_exists_config_define("MODPERL_HOOK_ALL_LAST")) { \
+        order = APR_HOOK_REALLY_LAST; \
+    } \
+    if (ap_exists_config_define("MODPERL_HOOK_" #phase "_FIRST")) { \
+        order = APR_HOOK_FIRST; \
+    } \
+    else if (ap_exists_config_define("MODPERL_HOOK_" #phase "_REALLY_FIRST")) { \
+        order = APR_HOOK_REALLY_FIRST; \
+    } \
+    else if (ap_exists_config_define("MODPERL_HOOK_" #phase "_MIDDLE")) { \
+        order = APR_HOOK_MIDDLE; \
+    } \
+    else if (ap_exists_config_define("MODPERL_HOOK_" #phase "_LAST")) { \
+        order = APR_HOOK_LAST; \
+    } \
+    else if (ap_exists_config_define("MODPERL_HOOK_" #phase "_REALLY_LAST")) { \
+        order = APR_HOOK_REALLY_LAST; \
+    } \
+    return order; \
+}
+EOF
+
+    $c_add .= "[EMAIL PROTECTED]";
+
+    $c_add .= "\n$hooks_proto [EMAIL PROTECTED]";
 
     $self->handler_desc(\$h_add, \$c_add);
 

Attachment: hook_order_test-mp2.tar.gz
Description: GNU Zip compressed data

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to