Skip to content

Commit

Permalink
Item689: Link %TWiki::cfg to %Foswiki::cfg in TWikiCompatibility plug…
Browse files Browse the repository at this point in the history
…in, and fix configure to handle %TWiki::cfg

git-svn-id: http://svn.foswiki.org/trunk@1836 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Jan 7, 2009
1 parent 6d01404 commit d43ed59
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions TWikiCompatibilityPlugin/lib/TWiki.pm
Expand Up @@ -11,5 +11,6 @@ sub TWiki::new {
}

%TWiki::regex = %Foswiki::regex;
%TWiki::cfg = %Foswiki::cfg;

1;
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Configure/FoswikiCfg.pm
Expand Up @@ -200,9 +200,9 @@ sub _parse {
$open = new Foswiki::Configure::Value( typename => $1, opts => $2 );
}

elsif ( $l =~ /^#?\s*\$(Foswiki::)?cfg([^=\s]*)\s*=(.*)$/ ) {
my $keys = $2;
my $tentativeVal = $3;
elsif ( $l =~ /^#?\s*\$(?:(?:Fosw|TW)iki::)?cfg([^=\s]*)\s*=(.*)$/ ) {
my $keys = $1;
my $tentativeVal = $2;
if ( $open && $open->isa('SectionMarker') ) {
pusht( \@settings, $open );
$open = undef;
Expand Down
57 changes: 57 additions & 0 deletions core/lib/Foswiki/Configure/Load.pm
Expand Up @@ -149,6 +149,63 @@ sub readDefaults {
_loadDefaultsFrom( "$dir/TWiki/Plugins", $root, \%read, \@errors );
_loadDefaultsFrom( "$dir/TWiki/Contrib", $root, \%read, \@errors );
}
if ( defined %TWiki::cfg ) {

# We had some TWiki plugins, need to map their config to Foswiki
sub mergeHash {

# Merges the keys in the right hashref to the ones in the left hashref
my ( $left, $right, $errors ) = @_;
while ( my ( $key, $value ) = each %$right ) {
if ( exists $left->{$key} ) {
if ( ref($value) ne ref( $left->{$key} ) ) {
push @$errors,
'Trying to overwrite $Foswiki::cfg{'
. $key
. '} with its $TWiki::cfg version ('
. $value . ')';
}
elsif ( ref($value) eq 'SCALAR' ) {
$left->{$key} = $value;
}
elsif ( ref($value) eq 'HASH' ) {
$left->{$key} =
mergeHash( $left->{$key}, $value, $errors );
}
elsif ( ref($value) eq 'ARRAY' ) {

# It's an array. try to be smart
# SMELL: Ideally, it should keep order too
foreach my $item (@$value) {
unless ( grep /^$item$/, @{ $left->{$key} } ) {

# The item isn't in the current list, add it at the end
unshift @{ $left->{$key} }, $item;
}
}
}
else {

# It's something else (GLOB, coderef, ...)
push @$errors,
'$TWiki::cfg{'
. $key
. '} is a reference to a'
. ref($value)
. '. No idea how to merge that, sorry.';
}
}
else {

# We don't already have such a key in the Foswiki scope
$left->{$key} = $value;
}
}
return $left;
}
mergeHash \%Foswiki::cfg, \%TWiki::cfg, \@errors;
} # define %TWiki::cfg

return \@errors;
}

Expand Down

0 comments on commit d43ed59

Please sign in to comment.