in reply to RFC - Parameter Objects
I've used the approach where every set of parameters has its own class.
After which you can douse Attribute::Property; { package Param::function; sub new : New; # XXX - Both need anchors? sub type : Property { /Order|Return/ } sub month : Property { grep /$_[1]/, 1 .. 12 } } sub function { my $self = shift; ... }
But I dislike param objects. The idea is great, but it's too much work in practice. Not because I created many classes, but because it's just too much work to create objects every time you want to pass parameters. I ended up usingmy %params = ( type => qr/Order|Return/, month => sub { my $month = shift; return grep { /$month/ } (1 .. 1 +2) } ); my $param = Param::function->new(\%params); $param->type = 'Return'; $param->month = 3; print $param->type; # prints 'Return' print $param->month; # prints 3 # the following two method calls will fail (croaking) $param->type = 'Ovid'; $param->month = 13;
everywhere and not actually using the parameter classes.my $param = @_ == 1 ? shift : Param::function->new({ @_ });
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: RFC - Parameter Objects
by Ovid (Cardinal) on May 15, 2003 at 15:35 UTC |