Like Getopt::Foo but for sub parameter passing? 
Author Message
 Like Getopt::Foo but for sub parameter passing?

I kinda like the hash way of passing parameters, because this way
parameters can be named.  But I'm quickly growing tried of writing the
same parameter checking code over and over again.

Then I remembered that there is Getopt::Long (and others) where I just
specify which options are required and which are optional, and what
type they're supposed to have.  Very convenient.

So, is there something that can be used for parameter passing to subs?

/----[ hypothetical pseudo-noncode from wishful thinking ]
| package Bla;
| use Keywords::Args;
|
| sub foo {
|     my $self = shift;
|     my %parms = keyword_args(foo => ['required', 'string'],
|                              bar => ['optional', 'int']);
|     ... code which uses $parms{foo} and $parms{bar} ...
| }
\----

kai
--
Be indiscrete.  Do it continuously.



Mon, 01 Sep 2003 06:22:31 GMT  
 Like Getopt::Foo but for sub parameter passing?

Quote:

>I kinda like the hash way of passing parameters, because this way
>parameters can be named.  But I'm quickly growing tried of writing the
>same parameter checking code over and over again.

[...]

>So, is there something that can be used for parameter passing to subs?

Dave Rolsky has been working on a recent module Params::Validate,
available on CPAN.  He'd probably be interested in your feedback.


Fri, 05 Sep 2003 11:29:15 GMT  
 Like Getopt::Foo but for sub parameter passing?
[courtesy cc of this posting sent to cited author via email]


:Then I remembered that there is Getopt::Long (and others) where I just
:specify which options are required and which are optional, and what
:type they're supposed to have.  Very convenient.
:
:So, is there something that can be used for parameter passing to subs?

Try Getargs::Long.

        use Getargs::Long;

        sub f {

                ...
        }

        f(-z => "foo", -x => ['a', 'b'], -y => 1);

(Disclaimer: it's in my CPAN directory)

Raphael



Mon, 15 Sep 2003 04:44:28 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Access from CD-ROM

2. How to find data in tables? - newbie

3. Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?

4. How to pass hash as sub parameter?

5. sub passing parameter other than $_

6. Passing named and unnamed parameters to subs

7. Problem (?) with FINDKEY - Please help if possible

8. binary tree

9. DBimage with zoom capabilities ?

10. anonymous sub as a parameter to a sub?

11. WHY support $foo @foo %foo ?

12. Missing sub parameters

 

 
Powered by phpBB® Forum Software