lib/TWiki/Configure/Item.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 # ======================================================================
    19 # Abstract base class of all configuration components. A configuration
    20 # component may be a collection item (a ConfigSection) or an individual Value.
    21 #
    22 # Objects of this class are intended to form a tree with references in
    23 # both directions, circular references ahead.  But configure isn't
    24 # supposed to be run in a persistent environment anyway.
    25 package TWiki::Configure::Item;
    26 
    27 use strict;
    28 
    29 sub new {
    30     my $class = shift;
    31 
    32     my $this = bless({}, $class);
    33     $this->{parent} = undef;
    34     $this->{desc} = '';
    35     $this->{errors} = 0;
    36     $this->{warnings} = 0;
    37 
    38     return $this;
    39 }
    40 
    41 sub getDepth {
    42     my $depth = 0;
    43     my $mum = shift;
    44 
    45     while ($mum) {
    46         $depth++;
    47         $mum = $mum->{parent};
    48     }
    49     return $depth;
    50 }
    51 
    52 sub addToDesc {
    53     my ($this, $desc) = @_;
    54 
    55     $this->{desc} .= "$desc\n";
    56 }
    57 
    58 sub isExpertsOnly {
    59     return 0;
    60 }
    61 
    62 sub haveSettingFor {
    63     die "Implementation required";
    64 }
    65 
    66 
    67 # Purpose
    68 #     Accept an attribute setting for this item (e.g. a key name).
    69 #     Sort of a generic write accessor.
    70 sub set {
    71     my ($this, %params) = @_;
    72     foreach my $k (keys %params) {
    73         $this->{$k} = $params{$k};
    74     }
    75 }
    76 
    77 
    78 # Purpose
    79 #     Increase a numeric value, recursing up to a parentless item
    80 # Assumptions
    81 #     All item levels have $key defined and initialized
    82 #     (intended for use with 'warnings' and 'errors')
    83 #     Parents of items are items (or precisely: can inc())
    84 sub inc {
    85     my ($this, $key) = @_;
    86 
    87     $this->{$key}++;
    88     $this->{parent}->inc($key) if $this->{parent};
    89 }
    90 
    91 
    92 sub getSectionObject {
    93     return undef;
    94 }
    95 
    96 sub getValueObject {
    97     return undef;
    98 }
    99 
   100 1;