Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Best CPAN library for named subroutine arguments/parameters

by hermida (Scribe)
on Oct 26, 2011 at 00:45 UTC ( [id://933761]=perlquestion: print w/replies, xml ) Need Help??

hermida has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone, searching CPAN I cannot find a recently maintained library to support named subroutine arguments/parameters. What CPAN library is recommended?

GetArgs::Long
Params::Smart
Sub::NamedParams

others that I haven't found?

  • Comment on Best CPAN library for named subroutine arguments/parameters

Replies are listed 'Best First'.
Re: Best CPAN library for named subroutine arguments/parameters
by salva (Canon) on Oct 26, 2011 at 10:10 UTC
    The overhead introduced by most of these modules is quite significant as they make several subroutine calls for every argument processed under the hood. That may be admissible or not for your particular case.

    This is my preferred way of handling named parameters:

    sub foo { my ($self, %opts) = @_; my $foo = delete $opts{foo} // 'default_foo'; my $bar = delete $opts{bar} // croak "required parameter bar missing +"; ... %opts and croak_bad_args(\%opts); ... }

    It requires some more coding but is cheap.

Re: Best CPAN library for named subroutine arguments/parameters
by Util (Priest) on Oct 26, 2011 at 01:30 UTC
Re: Best CPAN library for named subroutine arguments/parameters
by repellent (Priest) on Oct 26, 2011 at 08:10 UTC
Re: Best CPAN library for named subroutine arguments/parameters
by DrHyde (Prior) on Oct 26, 2011 at 12:20 UTC
    Why would you only be interested in stuff that has been updated recently? If it's old, that is more likely to mean "it just works" than "it's been abandoned and is full of bugs".
      That is absolutely true, just wanted to make sure that when I select a certain CPAN library to use and include in my software distribution that it's not obsolete, or not maintained, etc. But you are right if it just works then I shouldn't care so much :-)
Re: Best CPAN library for named subroutine arguments/parameters
by Arunbear (Prior) on Oct 26, 2011 at 09:39 UTC
      > Smart::Args looks interesting.

      It certainly does, but unfortunately it requires PadWalker. :(

      Cheers Rolf

        What's wrong with PadWalker?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://933761]
Approved by ww
Front-paged by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found