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