Skip to content

Commit

Permalink
Item9345: much cleaner implementation
Browse files Browse the repository at this point in the history
Thanks to Foswiki:Main/OlivierRaginel for the tip



git-svn-id: http://svn.foswiki.org/trunk/VirtualHostingContrib@9825 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AntonioTerceiro authored and AntonioTerceiro committed Nov 2, 2010
1 parent 37208b2 commit c3664d0
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions lib/Foswiki/Contrib/VirtualHostingContrib/VirtualHost.pm
Expand Up @@ -74,26 +74,9 @@ sub run {

local $Foswiki::Contrib::VirtualHostingContrib::VirtualHost::CURRENT = $self->hostname;

$self->_run_with_local_configuration($code, { %{$self->{config}} });
}
local @Foswiki::cfg{keys %{$self->{config}}} = map { _merge_config($Foswiki::cfg{$_}, $self->{config}->{$_}) } (keys %{$self->{config}});

# Recursive method; consumes the local configuration, updates Foswiki global
# configuration with local() and runs the code inside the virtualhost. This
# method needs to be recursive because if the configurations were set in a
# loop, the local() declarations would lose their scope just after the loop.
#
# Note that $config will be consumed in recursive calls, so make sure you pass
# a copy of your actual data.
sub _run_with_local_configuration {
my ($self, $code, $config) = @_;
if (scalar(%$config)) {
my $key = (keys(%$config))[0];
local $Foswiki::cfg{$key} = _merge_config($Foswiki::cfg{$key}, $config->{$key});
delete $config->{$key};
$self->_run_with_local_configuration($code, $config);
} else {
&$code();
}
&$code();
}

sub _merge_config {
Expand Down

0 comments on commit c3664d0

Please sign in to comment.