Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Best CPAN library for named subroutine arguments/parameters

by salva (Abbot)
on Oct 26, 2011 at 10:10 UTC ( #933854=note: print w/replies, xml ) Need Help??


in reply to Best CPAN library for named subroutine arguments/parameters

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://933854]
help
Chatterbox?
[LanX]: :)
[LanX]: Yesterday I made B::Concise produce a nested AoH of the optree instead of text
LanX chacka!!!
[LanX]: whats the correct way to make a perlbug report for perldoc?
[erix]: chacka
[LanX]: with a diff? which perldoc version should I take from where?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-04-24 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (442 votes). Check out past polls.