Michel Rodriguez > Params-Style-0.06 > Params::Style

Download:
Params-Style-0.06.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.06   Source  

NAME ^

Params::Style - Perl module to allow named parameters in perl_style or javaStyle

SYNOPSIS ^

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

ABSTRACT ^

Params::Style offers functions to convert named parameters from perl_style to javaStyle nad nostyle 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

nostyleparams <params>

Converts the jeys of <params> into nostyle keys

replace_keys <coderef> <params>

Applies <coderef> to the keys in <params>

The following filters are already defined:

JavaStyle

used by JavaStyleParams

javaStyle

used by javaStyleParams

perl_style

used by perl_style_params

nostyle

used by nostyleparams

EXPORT

None by default.

:all

Exports perl_style_params, javaStyleParams, JavaStyleParams, nostyleparams 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: 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.

By default (if the style is not given) the style will be perstyle.

SEE ALSO ^

perl

AUTHOR ^

Michel Rodriguez, <mirod@cpan.org>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: