there have been several requests for the ability to modify the
DocumentRoot, i reckon it's about time we allow that.
caveats:
if you want the DocumentRoot to be reset to the original value after the
request is over, you'll have to do that yourself, something like:
my $old_docroot = $r->document_root;
$r->register_cleanup(sub { shift->document_root($old_docroot) });
the lifetime of conf->ap_document_root is longer than that of r->pool, so
it can't be used to allocate the string copy.
we could use the server pool, which isn't destroyed until the server is
restarted, but then each time you set document_root, the server would
"leak" memory.
to workaround, the new document_root is saved in a Perl variable
$Apache::Server::DocumentRoot
--- src/modules/perl/Apache.xs 2000/04/03 04:48:52 1.92
+++ src/modules/perl/Apache.xs 2000/04/03 05:36:56
@@ -783,8 +783,26 @@
Apache r
const char *
-document_root(r)
+document_root(r, ...)
Apache r
+
+ PREINIT:
+ core_server_config *conf;
+
+ CODE:
+ conf = (core_server_config *)
+ get_module_config(r->server->module_config, &core_module);
+
+ RETVAL = conf->ap_document_root;
+
+ if (items > 1) {
+ SV *doc_root = perl_get_sv("Apache::Server::DocumentRoot", TRUE);
+ sv_setsv(doc_root, ST(1));
+ conf->ap_document_root = SvPVX(doc_root);
+ }
+
+ OUTPUT:
+ RETVAL