~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Configure/Item.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See bottom of file for license and copyright information
 
2
 
 
3
#
 
4
# ======================================================================
 
5
# Abstract base class of all configuration components. A configuration
 
6
# component may be a collection item (a ConfigSection) or an individual Value.
 
7
#
 
8
# Objects of this class are intended to form a tree with references in
 
9
# both directions, circular references ahead.  But configure isn't
 
10
# supposed to be run in a persistent environment anyway.
 
11
package Foswiki::Configure::Item;
 
12
 
 
13
use strict;
 
14
 
 
15
sub new {
 
16
    my $class = shift;
 
17
 
 
18
    my $this = bless( {}, $class );
 
19
    $this->{parent}   = undef;
 
20
    $this->{desc}     = '';
 
21
    $this->{errors}   = 0;
 
22
    $this->{warnings} = 0;
 
23
 
 
24
    return $this;
 
25
}
 
26
 
 
27
sub getDepth {
 
28
    my $depth = 0;
 
29
    my $mum   = shift;
 
30
 
 
31
    while ($mum) {
 
32
        $depth++;
 
33
        $mum = $mum->{parent};
 
34
    }
 
35
    return $depth;
 
36
}
 
37
 
 
38
sub addToDesc {
 
39
    my ( $this, $desc ) = @_;
 
40
 
 
41
    $this->{desc} .= "$desc\n";
 
42
}
 
43
 
 
44
sub isExpertsOnly {
 
45
    return 0;
 
46
}
 
47
 
 
48
sub haveSettingFor {
 
49
    die "Implementation required";
 
50
}
 
51
 
 
52
# Purpose
 
53
#     Accept an attribute setting for this item (e.g. a key name).
 
54
#     Sort of a generic write accessor.
 
55
sub set {
 
56
    my ( $this, %params ) = @_;
 
57
    foreach my $k ( keys %params ) {
 
58
        $this->{$k} = $params{$k};
 
59
    }
 
60
}
 
61
 
 
62
# Purpose
 
63
#     Increase a numeric value, recursing up to a parentless item
 
64
# Assumptions
 
65
#     All item levels have $key defined and initialized
 
66
#     (intended for use with 'warnings' and 'errors')
 
67
#     Parents of items are items (or precisely: can inc())
 
68
sub inc {
 
69
    my ( $this, $key ) = @_;
 
70
 
 
71
    $this->{$key}++;
 
72
    $this->{parent}->inc($key) if $this->{parent};
 
73
}
 
74
 
 
75
sub getSectionObject {
 
76
    return undef;
 
77
}
 
78
 
 
79
sub getValueObject {
 
80
    return undef;
 
81
}
 
82
 
 
83
1;
 
84
__DATA__
 
85
#
 
86
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
87
#
 
88
# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.
 
89
# Foswiki Contributors are listed in the AUTHORS file in the root
 
90
# of this distribution. NOTE: Please extend that file, not this notice.
 
91
#
 
92
# Additional copyrights apply to some or all of the code in this
 
93
# file as follows:
 
94
#
 
95
# Copyright (C) 2000-2006 TWiki Contributors. All Rights Reserved.
 
96
# TWiki Contributors are listed in the AUTHORS file in the root
 
97
# of this distribution. NOTE: Please extend that file, not this notice.
 
98
#
 
99
# This program is free software; you can redistribute it and/or
 
100
# modify it under the terms of the GNU General Public License
 
101
# as published by the Free Software Foundation; either version 2
 
102
# of the License, or (at your option) any later version. For
 
103
# more details read LICENSE in the root of this distribution.
 
104
#
 
105
# This program is distributed in the hope that it will be useful,
 
106
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
107
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
108
#
 
109
# As per the GPL, removal of this notice is prohibited.