The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Params::Style - Perl extension for converting named parameters to perl_style or javaStyle

SYNOPSIS

  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'
      ...
    }

  or

  sub my_sub
    { my $arg= shift;
      my %opts : ParamsStyle( 'perl_style')= @_;
      ...
    }

ABSTRACT

Params::Style offers functions to convert named parameters from perl_style to javaStyle and vice-versa

DESCRIPTION

Functional Interface

perl_style_params <params>

Converts the keys in <params> into perl_style keys

<params<gt> can be either an array, an array reference or a hash reference

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
javaStyleParams <params>

Converts the keys of <params> into javaStyle keys

JavaStyleParams <params>

Converts the keys of <params> into JavaStyle keys

replace_keys <coderef> <params>

Applies <coderef> to the keys in <params>

EXPORT

None by default.

:all

Exports perl_style_params, javaStyleParams, JavaStyleParams and replace_keys

Autotied hash interface

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: ParamStyle( 'perl_style')= @_;
    }

The extra parameter to tie is either the name of a style (perl_style, javaStyle or JavaStyle) or a code reference, that will be applied to all keys to the hash.

SEE ALSO

perl

AUTHOR

Michel Rodriguez, <mirod@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2003 by Michel Rodriguez

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.