[vox-tech] subroutine arguments with PERL

Troy Arnold troy-vox at zenux.net
Tue Nov 30 11:07:20 PST 2010


On Tue, Nov 30, 2010 at 10:59:32AM -0800, Brian Lavender wrote:
> How do you tell perl to warn or not compile if you are not using
> the correct number of arguments in a subroutine? 

I don't know of a built-in pragma but you could look into Params::Validate:

http://search.cpan.org/dist/Params-Validate/

"The Params::Validate module allows you to validate method or function call
parameters to an arbitrary level of specificity. At the simplest level, it
is capable of validating the required parameters were given and that no
unspecified additional parameters were passed in.

It is also capable of determining that a parameter is of a specific type,
that it is an object of a certain class hierarchy, that it possesses
certain methods, or applying validation callbacks to arguments."

It's not automatic though -- you've gotta maintain a proper call to the
validate() subs in your sub.


-t



More information about the vox-tech mailing list