1# Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/ 2# 3# Copyright (C) 2000-2018 Peter Thoeny, peter[at]thoeny.org 4# and TWiki Contributors. All Rights Reserved. TWiki Contributors 5# are listed in the AUTHORS file in the root of this distribution. 6# NOTE: Please extend that file, not this notice. 7# 8# Additional copyrights apply to some or all of the code in this 9# file as follows: 10# 11# This program is free software; you can redistribute it and/or 12# modify it under the terms of the GNU General Public License 13# as published by the Free Software Foundation; either version 3 14# of the License, or (at your option) any later version. For 15# more details read LICENSE in the root of this distribution. 16# 17# This program is distributed in the hope that it will be useful, 18# but WITHOUT ANY WARRANTY; without even the implied warranty of 19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20# 21# As per the GPL, removal of this notice is prohibited. 22 23package TWiki::Configure::Value; 24 25use strict; 26 27use base 'TWiki::Configure::Item'; 28 29use TWiki::Configure::Type; 30 31# The opts are additional parameters, and by convention may 32# be a number (for a string length), a comma separated list of values 33# (for a select) and may also have an M for mandatory, or a H for hidden. 34sub new { 35 my $class = shift; 36 37 my $this = bless($class->SUPER::new('TWiki::Configure::UIs::Value'), $class); 38 39 $this->{keys} = ''; 40 $this->{opts} = ''; 41 $this->{expertsOnly} = 0; 42 $this->set(@_); 43 44 if (defined $this->{opts}) { 45 $this->{mandatory} = ($this->{opts} =~ /(\b|^)M(\b|$)/); 46 $this->{hidden} = ($this->{opts} =~ /(\b|^)H(\b|$)/); 47 $this->{expertsOnly} = 1 48 if ($this->{opts} =~ s/\bEXPERT\b//); 49 } 50 51 return $this; 52} 53 54sub isExpertsOnly { 55 my $this = shift; 56 return $this->{expertsOnly}; 57} 58 59sub getKeys { 60 my $this = shift; 61 return $this->{keys}; 62} 63 64sub getType { 65 my $this = shift; 66 unless ($this->{type}) { 67 $this->{type} = 68 TWiki::Configure::Type::load($this->{typename} || 'UNKNOWN'); 69 } 70 return $this->{type}; 71} 72 73sub visit { 74 my ($this, $visitor) = @_; 75 return 0 unless $visitor->startVisit($this); 76 return 0 unless $visitor->endVisit($this); 77 return 1; 78} 79 80sub getValueObject { 81 my ($this, $keys) = @_; 82 83 return $this if ($this->{keys} && $keys eq $this->{keys}); 84 return undef; 85} 86 87# See if this value is changed from the default. The comparison 88# is done according to the rules for the type of the value. 89sub needsSaving { 90 my ($this, $valuer) = @_; 91 92 my $curval = $valuer->currentValue($this); 93 my $defval = $valuer->defaultValue($this); 94 95 return 0 if $this->getType()->equals($curval, $defval); 96 #print STDERR "TEST $this->{keys} D'",($defval||'undef'),"' C'",($curval||'undef'),"'\n"; 97 return 1; 98} 99 1001; 101