Fellow mod_perlers, I followed the instructions in the Server Configuration Customization guide to create a custom Apache configuration directive like so:
my $foo; sub foo { $foo = $_[2] } Apache2::Module::add(__PACKAGE__, [ { name => 'MyFoo', func => __PACKAGE__ . '::foo' }, ]); sub handler { my $r = shift; $r->print($foo); return OK; } This works pretty well; I can now set the MyFoo directive in my httpd.conf. But it feels a little hinky to set up package globals that get set on every request like this. It feels like it would make more sense if they were getting passed to an object method, but foo() is called as a function here; the first parameter is the class name, not an object. Also, I tried to use an anonymous sub in the add call: my $foo; Apache2::Module::add(__PACKAGE__, [ { name => 'MyFoo', func => sub { $foo = $_[2] }, ]); But that didn’t work either; mod_perl complained that it couldn’t find a function named “CODE(0x1d5e988P)” in the package. I was surprised by this since the docs say: > The func attribute expects a reference to a function or a function name. https://perl.apache.org/docs/2.0/user/config/custom.html#C_func_ So none of this feels quite right to me. Anyone got a point to best practices for setting up custom configuration directives? Or is this close to what everyone does anyway? Thanks, David
smime.p7s
Description: S/MIME cryptographic signature