1
# See bottom of file for license and copyright information
4
# This class is used to refer to two hashes of configuration values.
5
# The first is a hash of default values, and the second (which will
6
# have mostly the same keys) contains the *current* value (i.e. the
7
# value after edits have been applied).
9
# $defaults is a reference to the hash of defaults
10
# $values is a reference to the hash of current values
11
package Foswiki::Configure::Valuer;
15
use Foswiki::Configure::Type;
18
my ( $class, $defaults, $values ) = @_;
20
my $this = bless( {}, $class );
21
$this->{defaults} = $defaults;
22
$this->{values} = $values;
27
# Get a value from one of the value sets (defaults or values)
29
my ( $this, $value, $set ) = @_;
30
my $keys = $value->getKeys();
31
my $var = '$this->{' . $set . '}->' . $keys;
33
eval '$val = ' . $var . ' if exists(' . $var . ')';
36
# SMELL: Really shouldn't do this unless we are sure it's an RE,
37
# but the probability of this string occurring elsewhere than an
38
# RE is so low that we can afford to take the risk.
39
while ( $val =~ s/^\(\?-xism:(.*)\)$/$1/ ) { }
44
# get the current value
46
my ( $this, $value ) = @_;
47
return $this->_getValue( $value, 'values' );
50
# get the default value
52
my ( $this, $value ) = @_;
53
return $this->_getValue( $value, 'defaults' );
56
# Get changed values from CGI. Each parameter is identified by a
57
# TYPEOF: param that specifies the keys e.g. ?TYPEOF:{Kiss}=Smooch. The
58
# type is used to determine if the value of {Kiss} in CGI is different to
59
# the value known to the Valuer (i.e. has been updated). If it is, the keys
60
# are added to the $updated hash.
62
my ( $this, $query, $updated ) = @_;
66
# Each config param has an associated TYPEOF: param, so we only
67
# pick up those things that we really want
68
foreach $param ( $query->param ) {
70
# the - (and therefore the ' and ") is required for languages
71
# e.g. {Languages}{'zh-cn'}.
72
next unless $param =~ /^TYPEOF:((?:{[-\w'"]+})*)/;
75
# The value of TYPEOF: is the type name
76
my $typename = $query->param($param);
78
$typename = $1; # check and untaint
79
my $type = Foswiki::Configure::Type::load($typename);
80
my $newval = $type->string2value( $query->param($keys) );
81
my $xpr = '$this->{values}->' . $keys;
82
my $curval = eval $xpr;
83
if ( !$type->equals( $newval, $curval ) ) {
85
#print "<br>$typename $keys '$newval' != '$curval'\n";
86
eval $xpr . ' = $newval';
88
$updated->{$keys} = 1;
97
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
99
# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.
100
# Foswiki Contributors are listed in the AUTHORS file in the root
101
# of this distribution. NOTE: Please extend that file, not this notice.
103
# Additional copyrights apply to some or all of the code in this
106
# Copyright (C) 2000-2006 TWiki Contributors. All Rights Reserved.
107
# TWiki Contributors are listed in the AUTHORS file in the root
108
# of this distribution. NOTE: Please extend that file, not this notice.
110
# This program is free software; you can redistribute it and/or
111
# modify it under the terms of the GNU General Public License
112
# as published by the Free Software Foundation; either version 2
113
# of the License, or (at your option) any later version. For
114
# more details read LICENSE in the root of this distribution.
116
# This program is distributed in the hope that it will be useful,
117
# but WITHOUT ANY WARRANTY; without even the implied warranty of
118
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
120
# As per the GPL, removal of this notice is prohibited.