On Mon, 19 Mar 2001, Johan Vromans wrote:
> Sorry for the delay...
>
> [Quoting Dave Rolsky, on March 18 2001, 10:51, in "2nd request: Params:"]
> > Name: Params::Validate
> > DSLI: bdpf
> > Author: DROLSKY
> > Description: Validate subroutine parameters based on type, class, or
> > interface
>
> Can you indicate the differences between Params::Validate and
> Getargs::Long?
Good question. I didn't even know Getargs::Long existed. It looks like
it was released after Params::Validate so that explains how I missed it.
Anyway, having looked at it, I think I'd probably want to continue using
and maintaining my module. The two do fairly similar things but the
interfaces look quite different, and IMHO mine is significantly more
readable.
For example, doing this in Getargs::Long
my ($port, $server) = getargs( \@_, qw( port=i server=HTTP::Server ) );
would be written this way for my module:
validate( @_, { port => { type => SCALAR },
server => { isa => 'HTTP::Server' } } );
my %params = @_;
There isn't a one hundred percent overlap as there is no way to specify
that a scalar should be an integer vs. being a float or string. I also
don't plan to do this as in Perl I don't feel this can be meaningully
done. However, my module does allow a callbacks interface so the very
anal could do:
validate( @_, { port => { type => SCALAR,
callbacks => { 'is integer' =>
{ sub { shift =~ /^[\d.]$/ } } },
} } );
This, while somewhat ugly, is fairly self-documenting. To me, one of the
main purposes of my module is to help people write self-documenting code,
along with being a sanity checker.
In addition, my module can be used to validate positional arguments as
well (via the validate_pos sub) which is quite useful for me, since I have
code that uses both (positional for very simple methods, named for more
complex).
-dave
/*==================
www.urth.org
We await the New Sun
==================*/