From: Ralf Ertzinger Date: Sun, 7 Dec 2008 22:55:24 +0000 (+0100) Subject: Merge branch 'master' of ssh://sun@ryoko:22003/home/sun/GIT/quotesite X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=quotesite.git;a=commitdiff_plain;h=20af9b1c4f051c0830ba35b8d3d15439c499e119;hp=-c Merge branch 'master' of ssh://sun@ryoko:22003/home/sun/GIT/quotesite --- 20af9b1c4f051c0830ba35b8d3d15439c499e119 diff --combined quotesite/Base.pm index f0fa439,4445389..08897c9 --- a/quotesite/Base.pm +++ b/quotesite/Base.pm @@@ -8,7 -8,7 +8,7 @@@ use Data::Dumper sub new { my $class = shift; - my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}}; + my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}, '_OUTSTACK' => []}; bless($self, $class); @@@ -91,6 -91,23 +91,23 @@@ sub setio $self->{'_OUT'} = $io; } + sub pushio { + my $self = shift; + my $io = shift; + + push(@{$self->{'_OUTSTACK'}}, $self->{'_OUT'}); + $self->setio($io); + } + + sub popio { + my $self = shift; + my $io = pop(@{$self->{'_OUTSTACK'}}); + + if (defined($io)) { + $self->setio($io); + } + } + sub getconfstr { my $self = shift; my $s = 'Options for ' . $self->{'NAME'} . ":\n"; @@@ -111,30 -128,6 +128,30 @@@ return $s; } +# Return a list of the parameters supported by the module +# Does not return the 'enabled' parameter +sub getparamlist { + my $self = shift; + my $word = shift; + + return grep {$_ ne 'enabled' && /^$word/} keys %{$self->{'_PARAMS'}}; +} + +# Return a list of valid parameter values, if the parameter has +# such a list. +sub getparamvalues { + my $self = shift; + my $param = shift; + my $word = shift; + + unless(exists($self->{'_PARAMS'}->{$param}->[2])) { + return (); + } else { + return grep {/^$word/} keys %{$self->{'_PARAMS'}->{$param}->[2]}; + } +} + + sub gethelpstr { my $self = shift; my $s = 'Help for ' . $self->{'NAME'} . ":\n"; @@@ -149,16 -142,7 +166,16 @@@ foreach $k (keys(%{$self->{'_CONFIG'}->{'option'}})) { $p = $self->{'_PARAMS'}->{$k}->[0]; $p =~ s/%/%%/g; - $s .= sprintf(" %s: %s (default: %s)\n", $k, $self->{'_PARAMS'}->{$k}->[1], $p); + if (exists($self->{'_PARAMS'}->{$k}->[2])) { + # The parameter has a list of allowed values. Add the keys and their help + $s .= sprintf(" %s: %s (default: %s)\n", $k, $self->{'_PARAMS'}->{$k}->[1], $p); + foreach (sort keys(%{$self->{'_PARAMS'}->{$k}->[2]})) { + $s .= sprintf(" %s: %s\n", $_, $self->{'_PARAMS'}->{$k}->[2]->{$_}); + } + } else { + # The parameter just has a default value and a help text + $s .= sprintf(" %s: %s (default: %s)\n", $k, $self->{'_PARAMS'}->{$k}->[1], $p); + } } return $s;