in reply to Re: Accept user options with defaults and report unknowns.
in thread Accept user options with defaults and report unknowns.

Part of me agree's, and enevitably, part doesn't.

Three lines repeated twice becomes a sub? Use the sub in two modules, it becomes a module in its own right? Then it need pod, and a name and hell, I might as well throw in some validation of the values, so I need an api. Might as well make it OO. Oops! I re-invented Params::Validate.

Now why did I reject Params::Validate above? Oh. because I couldn't see the point in replacing 3 lines with a module and 3 lines.

use My::Params::Validate; my $validator = My::Params::Validate->new( Foo=>[ qw[foo|bar|qux] ], Bar=>[ 100 .. 1000 ], Qux=>[ 2e9, 3e8 ], ); sub myfunction{ my %opts = $validator %defs, @_; ... }

Ah! But now I need some code to validate the arguements to My::Params::Validate.

Should I subclass it? Use a virtual base class? What about exception handling?

OMG - I just re-invented Java:)

I do like delete @args{@unknown} (Note the S. I'll have to see if I can work that in somewhere:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller