Steven Haryanto
and 1 contributors


Perinci::Sub::GetArgs::Array - Get subroutine arguments from array


version 0.11


 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.

This module uses Log::Any for logging framework.

This module has Rinci metadata.


None are exported by default, but they are exportable.

None are exported by default, but they are exportable.

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

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 'getargsfrom_array(array=>[2, 3], meta=>$meta)' will produce:

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

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

Return value:

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.


I am not particularly happy with the duplication of functionality between this and the 'args_as' handler in Perinci::Sub::Wrapper. But the later is a code to generate code, so I guess it's not so bad for now.




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.


Steven Haryanto <>


This software is copyright (c) 2013 by Steven Haryanto.

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