X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FBase.pm;h=5d796d80a32b434bba40f20dc1dad41352070fb8;hb=12db405291947c6b02c2555051c3dc52f3995cbc;hp=2db4969b17299081a1b146ef40a3a4c2610d00f9;hpb=1d562536b9c6135697a468ae572cb4afce36db34;p=videosite.git diff --git a/videosite/Base.pm b/videosite/Base.pm index 2db4969..5d796d8 100644 --- a/videosite/Base.pm +++ b/videosite/Base.pm @@ -1,14 +1,14 @@ # (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 -package Base; +package videosite::Base; use strict; use Data::Dumper; sub new { my $class = shift; - my $self = {'_DEBUG' => 0, '_OUT' => sub {}}; + my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}}; bless($self, $class); @@ -23,7 +23,7 @@ sub error { $t = sprintf(shift(@_), @_); $t =~ s/%/%%/g; - $self->{'_OUT'}->($t); + $self->{'_OUT'}($t); } sub debug { @@ -111,6 +111,30 @@ sub getconfstr { 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"; @@ -125,7 +149,16 @@ sub gethelpstr { 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;