--- nfo/perl/libs/Getopt/Simple.pm 2002/12/23 04:27:03 1.2 +++ nfo/perl/libs/Getopt/Simple.pm 2002/12/27 16:06:55 1.3 @@ -1,7 +1,12 @@ ## ------------------------------------------------------------------------ -## $Id: Simple.pm,v 1.2 2002/12/23 04:27:03 joko Exp $ +## $Id: Simple.pm,v 1.3 2002/12/27 16:06:55 joko Exp $ ## ------------------------------------------------------------------------ ## $Log: Simple.pm,v $ +## Revision 1.3 2002/12/27 16:06:55 joko +## + sub _checkRequired +## + sub getPossibleOptionKeys +## + sub get +## ## Revision 1.2 2002/12/23 04:27:03 joko ## + refactored, more oo-style now ## @@ -38,7 +43,14 @@ bless $self, $class; #my $fields = shift; - my @fields = @_; + my @fields; + foreach (@_) { + if (ref $_ eq 'HASH') { + $self->{__metadata} = $_; + } else { + push @fields, $_; + } + } # build mapping (hash with argument as key and callback (CODEref) as value) $self->{__possible} = []; @@ -66,12 +78,35 @@ # for convenience: store inside object itself, too $self->{$key} = $opt->{$key}; } + + $self->_checkRequired(); + return $self; } +sub _checkRequired { + my $self = shift; + foreach (keys %{$self->{__metadata}->{required}}) { + if (!$self->{__result}->{$_}) { + $self->{__metadata}->{required}->{$_}->($self); + } + } +} + sub getOptions { my $self = shift; return $self->{__result}; } +sub getPossibleOptionKeys { + my $self = shift; + return $self->{__possible}; +} + +sub get { + my $self = shift; + my $key = shift; + return $self->{$key}; +} + 1;