in reply to Re: Gratuitous use of Perl Prototypes
in thread Gratuitous use of Perl Prototypes
So if you need the first parameter to be an array ref, put in code to test this precondition -
sub PUSH { my ($aref, @new) = @_; carp "first parameter must be an array reference" unless ref $aref e +q 'ARRAY'; ... }
Even better, use Params::Validate
If your emulating a builtin like push, using the same interface has advantages (in this case positional parameters), but I prefer using named parameters as much as possible - it also can cut out a number of errors if you choose appropriate parameter names e.g.
sub NAMED_PUSH { my(%args) = @_; carp "dest_aref parmeter must be an array reference" unless ref $arg +s{dest_aref} eq 'ARRAY'; ... }
Your POD for this sub (dont give me that puzzled look !!!) should document what keys are expected, and the code checks you have keep your part of the contract.
use brain;
|
|---|