Perinci::Sub::GetArgs::Array - Get subroutine arguments (%args) from array


This document describes version 0.16 of Perinci::Sub::GetArgs::Array (from Perl distribution Perinci-Sub-GetArgs-Array), released on 2016-12-10.


 use Perinci::Sub::GetArgs::Array;

 my $res = get_args_from_array(array=>\@ary, meta=>$meta, ...);


This module provides get_args_from_array(). This module is used by, among others, Perinci::Sub::GetArgs::Argv.


get_args_from_array(%args) -> [status, msg, result, meta]

Get subroutine arguments (%args) from array.

Using information in metadata's args property (particularly the pos and greedy arg type clauses), extract arguments from an array into a hash \%args, suitable for passing into subs.


 my $meta = {
     v => 1.1,
     summary => 'Multiply 2 numbers (a & b)',
     args => {
         a => {schema=>'num*', pos=>0},
         b => {schema=>'num*', pos=>1},

then get_args_from_array(array=>[2, 3], meta=>$meta) will produce:

 [200, "OK", {a=>2, b=>3}]

This function is not exported by default, but exportable.

Arguments ('*' denotes required arguments):

  • allow_extra_elems => bool (default: 0)

    Allow extra/unassigned elements in array.

    If set to 1, then if there are array elements unassigned to one of the arguments (due to missing pos, for example), instead of generating an error, the function will just ignore them.

  • array* => array

    NOTE: array will be modified/emptied (elements will be taken from the array as they are put into the resulting args). Copy your array first if you want to preserve its content.

  • meta* => hash

  • meta_is_normalized => bool (default: 0)

    Can be set to 1 if your metadata is normalized, to avoid duplicate effort.

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)


Please visit the project's homepage at


Source repository is at


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.




perlancar <>


This software is copyright (c) 2016 by

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