Following the How to make an object method read named parameters? discussion on how to read named parameter hashes, I've been thinking about the rather non-intuitive nature of the various parameter processing techniques.
In essence, all of them are more-or-less workarounds for a lack of syntactic support in Perl itself for named parameter hashes.
Worse - they are all (with the exception of raw my %args = @_) very slow.
So, for consideration, here is a proposal for a module that uses source filters to add syntactic support for hash parameters (the code for this has been written and has tested to work all the way back to Perl 5.005_04):
use Sub::Parms; # Case insensitive function parms sub my_function { FunctionParms : %args; my ($a_name, $another_name) = @args{'a_name', 'another_name'}; # ... } # Case sensitive function parms sub my_other_function { CSFunctionParms : %args; my ($a_name, $another_name) = @args{'a_name', 'another_name'}; # ... } # Case insensitive method parms sub my_method { MethodParms : $self, %args; my ($a_name, $another_name) = @args{'a_name', 'another_name'}; # ... } # Case sensitive parms sub my_other_method { CSMethodParms : $self, %args; my ($a_name, $another_name) = @args{'a_name', 'another_name'}; # ... }
The difference the 'CSxxxx' versions handle is that the default mode is case insensitive processing of parameter names (they are all folded to lowercase), but the 'CSxxxx' versions are not folded to lowercase (and hence are Case-Sensitive).
The method declarations also handle the declaration of the class invokation parameter for the OO inclined
The thought is that the declarations could be extended in the future with more parameters to handle validation, defaults and variable binding options.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RFC named parameter syntactic sugar
by BUU (Prior) on Oct 15, 2005 at 19:50 UTC | |
by snowhare (Friar) on Oct 15, 2005 at 20:28 UTC | |
|
Re: RFC named parameter syntactic sugar
by diotalevi (Canon) on Oct 17, 2005 at 15:45 UTC | |
by snowhare (Friar) on Oct 19, 2005 at 14:10 UTC | |
by diotalevi (Canon) on Oct 19, 2005 at 15:32 UTC | |
by dragonchild (Archbishop) on Oct 19, 2005 at 14:51 UTC | |
by diotalevi (Canon) on Oct 19, 2005 at 15:36 UTC | |
by xdg (Monsignor) on Oct 19, 2005 at 15:57 UTC |