Steven Haryanto > Perinci-Sub-GetArgs-Array > Perinci::Sub::GetArgs::Array

Download:
Perinci-Sub-GetArgs-Array-0.14.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.14   Source  

NAME ^

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

VERSION ^

This document describes version 0.14 of Perinci::Sub::GetArgs::Array (from Perl distribution Perinci-Sub-GetArgs-Array), released on 2014-07-08.

SYNOPSIS ^

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

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

DESCRIPTION ^

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

FUNCTIONS ^

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.

Example:

    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}]

Arguments ('*' denotes required arguments):

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.

TODO ^

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.

SEE ALSO ^

Perinci

HOMEPAGE ^

Please visit the project's homepage at https://metacpan.org/release/Perinci-Sub-GetArgs-Array.

SOURCE ^

Source repository is at https://github.com/sharyanto/perl-Perinci-Sub-GetArgs-Array.

BUGS ^

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-GetArgs-Array

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.

AUTHOR ^

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2014 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.

syntax highlighting: