lib/TWiki/Configure/Item.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/TWiki/Configure/Item.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +#
     1.5 +# TWiki Enterprise Collaboration Platform, http://TWiki.org/
     1.6 +#
     1.7 +# Copyright (C) 2000-2006 TWiki Contributors.
     1.8 +#
     1.9 +# This program is free software; you can redistribute it and/or
    1.10 +# modify it under the terms of the GNU General Public License
    1.11 +# as published by the Free Software Foundation; either version 2
    1.12 +# of the License, or (at your option) any later version. For
    1.13 +# more details read LICENSE in the root of this distribution.
    1.14 +#
    1.15 +# This program is distributed in the hope that it will be useful,
    1.16 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1.18 +#
    1.19 +# As per the GPL, removal of this notice is prohibited.
    1.20 +#
    1.21 +# ======================================================================
    1.22 +# Abstract base class of all configuration components. A configuration
    1.23 +# component may be a collection item (a ConfigSection) or an individual Value.
    1.24 +#
    1.25 +# Objects of this class are intended to form a tree with references in
    1.26 +# both directions, circular references ahead.  But configure isn't
    1.27 +# supposed to be run in a persistent environment anyway.
    1.28 +package TWiki::Configure::Item;
    1.29 +
    1.30 +use strict;
    1.31 +
    1.32 +sub new {
    1.33 +    my $class = shift;
    1.34 +
    1.35 +    my $this = bless({}, $class);
    1.36 +    $this->{parent} = undef;
    1.37 +    $this->{desc} = '';
    1.38 +    $this->{errors} = 0;
    1.39 +    $this->{warnings} = 0;
    1.40 +
    1.41 +    return $this;
    1.42 +}
    1.43 +
    1.44 +sub getDepth {
    1.45 +    my $depth = 0;
    1.46 +    my $mum = shift;
    1.47 +
    1.48 +    while ($mum) {
    1.49 +        $depth++;
    1.50 +        $mum = $mum->{parent};
    1.51 +    }
    1.52 +    return $depth;
    1.53 +}
    1.54 +
    1.55 +sub addToDesc {
    1.56 +    my ($this, $desc) = @_;
    1.57 +
    1.58 +    $this->{desc} .= "$desc\n";
    1.59 +}
    1.60 +
    1.61 +sub isExpertsOnly {
    1.62 +    return 0;
    1.63 +}
    1.64 +
    1.65 +sub haveSettingFor {
    1.66 +    die "Implementation required";
    1.67 +}
    1.68 +
    1.69 +
    1.70 +# Purpose
    1.71 +#     Accept an attribute setting for this item (e.g. a key name).
    1.72 +#     Sort of a generic write accessor.
    1.73 +sub set {
    1.74 +    my ($this, %params) = @_;
    1.75 +    foreach my $k (keys %params) {
    1.76 +        $this->{$k} = $params{$k};
    1.77 +    }
    1.78 +}
    1.79 +
    1.80 +
    1.81 +# Purpose
    1.82 +#     Increase a numeric value, recursing up to a parentless item
    1.83 +# Assumptions
    1.84 +#     All item levels have $key defined and initialized
    1.85 +#     (intended for use with 'warnings' and 'errors')
    1.86 +#     Parents of items are items (or precisely: can inc())
    1.87 +sub inc {
    1.88 +    my ($this, $key) = @_;
    1.89 +
    1.90 +    $this->{$key}++;
    1.91 +    $this->{parent}->inc($key) if $this->{parent};
    1.92 +}
    1.93 +
    1.94 +
    1.95 +sub getSectionObject {
    1.96 +    return undef;
    1.97 +}
    1.98 +
    1.99 +sub getValueObject {
   1.100 +    return undef;
   1.101 +}
   1.102 +
   1.103 +1;