Hey all-

So, a while back I brought up a potential idea for a Module::Interface
module. There was a little discussion of it, Chris Nandor had some good
points about it and h2xs, but then it sort of died down.

Anyways, I'm thinking about it again, mainly because I'm tired of crappy
module iterfaces on CPAN. Otherwise good modules are often crap-ti-fied
by a useless interface, or at least one that's really really annoying.

So, I was thinking of something that would enable a module to easily
parse args sent to it. I'm thinking along the lines of an interface that
follows CGI/DBI:


   function('onearg');
   function(opt => val, opt => val);
   function('ordered', 'args', 'same', 'as');
   fucntion(key1 => 'args', key2 => 'ordered', 
            key3 => 'as', key4 => 'same');


If anyone's worked with Akopia Interchange, you'll know that they have
this problem solved rather nicely. A tag in Interchange allows both
ordered (positional) and unordered arguments, where you can specify the
order. So:

    [tag arg1 arg2 arg3]
    [tag key2=arg2 key3=arg3 key1=arg1]

That is, if you order them, they'll get assigned to key1/2/3
positionally. Or, you can specify them in any random order with the key
you want to assign to explicitly.

I'm thinking a Module::Interface module that allowed CPAN and other
authors to write consistent interfaces could be a pretty big win for
CPAN. An author might use it like:

   use Module::Interface qw(args);

   sub my_function {
       my %args = args(@_);
   }

They could then customize the args() parsing based on what they told it,
for example:

   sub my_function {
       my %args = args [qw(key1 key2 key3)], @_;
   }

So, if the args were positionally specified, then they would be assigned
to key1, key2, and key3. Otherwise, it would be just like the person had
said:

   my %args = @_;

More stuff could be wrapped into this, like case-insentitivity, default
values, required values, and so on.

Thoughts?

-Nate

Reply via email to