Kirrily Robert wrote:
> I also think there's too much overhead in learning (and remembering)
> each library's quirks.  My most common mistakes when using CPAN or core
> modules occur when the modules have inconsistent interfaces and I forget
> which ones take hashes and which take hashrefs, etc.  Sure a quick RTFM
> sorts it out, but it's still annoying.

Absolutely. I've tossed around on [EMAIL PROTECTED] the idea of a
"Module::Interface" that would provide a common interface for module
authors, but nobody's bitten really. The idea would be to provide 2-3
very common, drop-in argument handlers so people don't have to write
buggy custom code. It would handle common stuff like:

   $obj = Class->new($required, $args, {opt => val, opt => val});

   $job = param(-name => 'job');

And allow flexible calling styles. For example, you might say:

   # import args() for argument validation
   use Module::Interface qw/args/;

   sub my_func (@) {
       my %args = args({ positional => [qw/name email phone/] }, @_);

Which would allow you to call your function two different ways:

   my_func($name, $email, $phone);
   my_func(name => $name, email => $email, phone => $phone);

Of course, you wouldn't have to specify the "positional" parameter, this
would just be one of several options.

In addition, I've thought that you could create a clean new() and other
OO function implementations and let people say:

   use base 'Module::Interface';

To get rolling, with the understanding that their object would then have
things predefined in a certain way, that would hopefully get 80% of the

Thoughts? If there's interest I can whip this up and stick it on CPAN.


Reply via email to