Hi all,
I ran in to a problem using NameWithVirtualHost because I used Rewrite rules based on the host name inside a single virtual host and so ended up with, in my case:
http://www.interarchy.com/main/index.pl and http://www.stairways.com/main/index.pl
going to different files in the file system, but both in the same virtual host (because they share most of the site, only the main entry is different).
Anyway, the Apache::Registry bases the cache/Package name on the virtual host name and the path of the URL. I don't really know why it isn't based on the full disk pathname, but anyway, this wasn't sufficient for my purposes, so I added support for using the hostname instead of the virtual server name:
--- Registry.pm.orig Tue Jun 15 20:55:32 2004 +++ Registry.pm Wed Jun 16 21:02:38 2004 @@ -20,6 +20,9 @@ unless (defined $Apache::Registry::NameWithVirtualHost) { $Apache::Registry::NameWithVirtualHost = 1; } +unless (defined $Apache::Registry::HostNameWithVirtualHost) { + $Apache::Registry::HostNameWithVirtualHost = 0; +} unless (defined $Apache::Registry::MarkLine) { $Apache::Registry::MarkLine = 1; } @@ -75,7 +78,10 @@
$script_name =~ s:/+$:/__INDEX__:;
- if ($Apache::Registry::NameWithVirtualHost && $r->server->is_virtual) {
+ if ($Apache::Registry::HostNameWithVirtualHost && $r->server->is_virtual) {
+ my $name = $r->hostname;
+ $script_name = join "", $name, $script_name if $name;
+ } elsif ($Apache::Registry::NameWithVirtualHost && $r->server->is_virtual) {
my $name = $r->get_server_name;
$script_name = join "", $name, $script_name if $name;
}
This is for mod_perl 1.0. I saw that mod_perl 2.0 does things slightly differently, but essentially has this same functionality. Anyway, I'm sending this to for consideration. The downside of by-host is that hosts like www.interarchy.com and interarchy.com would be treated differently. The upside is it works even in the case I've got. It'd be nice not to have to patch mod_perl with each install I do, so if this might be generally useful then perhaps it could be incorporated.
If using the full pathname works, there is no point adding extra functionality, which as you yourself mentioned above is not quite perfect. I can't remember now why the full pathname wasn't used, you can find the reason in the maillist archives. But it had something to do with not working on certain setups.
The solution is use a subclass of Apache::RegistryNG or Apache::PerlRun, which uses the filepath for the cache. I think the archives has the code that does that. It's about time someone released that subclass on CPAN.
As for mp2, it already uses the full filepath by default and provides a method that you can use to use the mp1-like uri based cache entry.
From: ModPerl-Registry/lib/ModPerl/RegistryCooker.pm
######################################################################### # func: namespace_from # dflt: namespace_from_filename # desc: returns a partial raw package name based on filename, uri, else # args: $self - registry blessed object # rtrn: a unique string #########################################################################
*namespace_from = \&namespace_from_filename;
# return a package name based on $r->filename only sub namespace_from_filename { my $self = shift;
my ($volume, $dirs, $file) = File::Spec::Functions::splitpath($self->{FILENAME}); my @dirs = File::Spec::Functions::splitdir($dirs); return join '_', grep { defined && length } $volume, @dirs, $file; }
# return a package name based on $r->uri only sub namespace_from_uri { my $self = shift;
my $path_info = $self->{REQ}->path_info; my $script_name = $path_info && $self->{URI} =~ /$path_info$/ ? substr($self->{URI}, 0, length($self->{URI}) - length($path_info)) : $self->{URI};
if ($ModPerl::RegistryCooker::NameWithVirtualHost && $self->{REQ}->server->is_virtual) { my $name = $self->{REQ}->get_server_name; $script_name = join "", $name, $script_name if $name; }
$script_name =~ s:/+$:/__INDEX__:;
return $script_name; }
-- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html