Params::Style - Perl module to allow named parameters in perl_style or javaStyle
use Params::Style; my_sub( FooBar => 1, foo_baz => "bravo"); sub my_sub { my %opt: ParamsStyle = @_; print "$opt{foobar} - $opt{foobaz}\n"; }
or (using a hashref to pass named parameters)
my_sub( $toto, $tata, { FooBar => 1, foo_baz => 0 }); sub my_sub { my( $foo, $bar, $opt)= @_; my %opt : ParamsStyle( 'JavaStyle')= %$opt; print "$opt{FooBar} - $opt{FooBaz}\n"; }
or (with the functional interface);
use Params::Style qw( perl_style_params); ... my_sub( $arg, camelCasedOption => 'fooBar', hideousIMHO => 1, badBADBad => 'foo'); ... sub my_sub { my( $arg, @opts)= @_; my %opts= perl_style_params( @opts); # %opts is now: # camel_case_option => 'fooBar', # hideous_IMHO => 1, # bad_BAD_bad => 'foo' ... }
Params::Style offers functions to convert named parameters from perl_style to javaStyle nad nostyle and vice-versa
<params>
Converts the keys in <params> into perl_style keys
<params<gt> can be either an array, an array reference or a hash reference
<params<gt
The return value as the same type as <params>:
my @params= perl_style_params( myArg1 => 1, myArg2 => 1); my %params= perl_style_params( myArg1 => 1, myArg2 => 1); my $params= perl_style_params( [myArg1 => 1, myArg2 => 1]); # $params is an array reference my $params= perl_style_params( {myArg1 => 1, myArg2 => 1}); # $params is a hash reference
Converts the keys of <params> into javaStyle keys
Converts the keys of <params> into JavaStyle keys
Converts the jeys of <params> into nostyle keys
<coderef>
Applies <coderef> to the keys in <params>
The following filters are already defined:
used by JavaStyleParams
used by javaStyleParams
used by perl_style_params
used by nostyleparams
None by default.
Exports perl_style_params, javaStyleParams, JavaStyleParams, nostyleparams and replace_keys
Instead of calling a function it is also possible to use an autotied hash, in which all the keys will be converted to the proper style:
sub foo { my %params: ParamsStyle( 'perl_style')= @_; ... }
The extra parameter to tie is either the name of a style (perl_style, nostyle, javaStyle or JavaStyle) or a code reference, that will be applied to all keys to the hash.
tie
perl_style
nostyle
javaStyle
JavaStyle
By default (if the style is not given) the style will be perstyle.
perstyle
perl
Michel Rodriguez, <mirod@cpan.org>
Copyright 2003-2005 by Michel Rodriguez
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Params::Style, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Params::Style
CPAN shell
perl -MCPAN -e shell install Params::Style
For more information on module installation, please visit the detailed CPAN module installation guide.