The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Sub::Params - Handle function arguments

SYNOPSIS

   use Sub::Params qw[ named_or_positional_arguments ];

   sub foo {
      my ($self, @args) = @_;
          my %args = named_or_positional_arguments(
         args => \@args,
         names => [qw[ foo bar baz]],
      )
   }

   # following calls are equivalent in behavior
   foo( 1, 2, 3 );
   foo( foo => 1, bar => 2, baz => 3 );
   foo( { foo => 1, bar => 2, baz => 3 });

DESCRIPTION

Module contains functions helping dealing with parameters.

named_or_positional_arguments( args => [], names => [] )

Helps coversion from positional to named arguments.

Use it only for minimal transition period, it is not intended for permanent usage.

Takes reference to actual function arguments and names in order of positional interface.

Parameters:

args

Reference to argument array

names

Positional argument names in form used in named arguments call

Function recognizes named arguments when:

every odd parameter is name from names list
first and only argument is hashref with keys from names list

Uses Hash::Util::lock_keys to detect valid names.

ACKNOWLEDGMENTS

Thanks GoodData for supporting open-source contribution

SUPPORT

This module comes with no warranty and is distributed as is.

To participate please use discussions using project's github issues.

REPOSITORY

https://github.com/gooddata/perl-sub-params

LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0