On 27 Jun 2001 [EMAIL PROTECTED] wrote:
> dougm 01/06/27 10:30:22
>
> Modified: Apache-Test MANIFEST
> Apache-Test/lib/Apache TestHarness.pm
> Added: Apache-Test/lib/Apache TestSort.pm
> Log:
> move sort routines into their own module, might be useful elsewhere
[snip]
> 1.1 modperl-2.0/Apache-Test/lib/Apache/TestSort.pm
>
> Index: TestSort.pm
> ===================================================================
> package Apache::TestSort;
>
[snip]
> sub run {
> my($self, $list, $args) = @_;
>
> my $times = $args->{times} || 1;
> my $order = $args->{order} || 'rotate';
> my $sort = \&{$order};
>
> # re-shuffle the list according to the requested order
> if (defined &$sort) {
> $sort->($list, $times);
what happens if $args->{order} is defined, but is none of
rotate|random|repeat when somebody mistypes the value or --order? This
code will die. My original code was just silently ignoring this option if
it's an unknown one.
I've tried to add the checking at GetOptions stage:
my %order = map { $_ => 1} qw(random rotate repeat);
GetOptions(\%opts,
...
('order' => sub {
die "invalid $_[0] value: $_[1]"
unless $_[1] && $order{$_[1]};
}),
....
);
but this doesn't seem to work. It's advertised to work with non %opts call
style and I didn't find an alternative with %opts style in the manpage.
Another alternative would be to do the checking after GetOptions:
my %order = map { $_ => 1} qw(random rotate repeat);
if ($opts{order} && !$order{ $opts{order} }){
warning "invalid order: $opts{order}";
delete $opts{order};
}
of course %order, should be set only once on the top of the code and used
here and %usage.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]