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

NAME

Perinci::Examples - Example modules containing metadata and various example functions

VERSION

version 0.18

SYNOPSIS

 use Perinci::Examples qw(delay);
 delay();

DESCRIPTION

This module and its submodules contain an odd mix of various functions, variables, and other code entities, along with their Rinci metadata. Mostly used for testing Rinci specification and the various Perinci modules.

Example scripts are put in a separate distribution (see Perinci::Examples::Bin) to make dependencies for this distribution minimal (e.g. not depending on Perinci::CmdLine) since this example module(s) are usually used in the tests of other modules.

{en_US A sample description

    verbatim
    line2

Another paragraph with bold, italic text. }

FUNCTIONS

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

{en_US Demonstrate argument default value from default and/or schema}.

Arguments ('*' denotes required arguments):

  • a => int

    {en_US Demonstrate argument default value from default and/or schema}.

  • b => int (default: 2)

    {en_US Demonstrate argument default value from default and/or schema}.

  • c => int (default: 3)

    {en_US Demonstrate argument default value from default and/or schema}.

  • d => int (default: 4)

    {en_US Demonstrate argument default value from default and/or schema}.

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.

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

{en_US Call gen_array()}.

{en_US This is to test nested call (e.g. Log::Any::For::Package). }

Arguments ('*' denotes required arguments):

  • len* => int (default: 10)

    {en_US Call gen_array()}.

    {en_US This is to test nested call (e.g. Log::Any::For::Package). }

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.

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

{en_US Call randlog()}.

{en_US This is to test nested call (e.g. Log::Any::For::Package). }

Arguments ('*' denotes required arguments):

  • max_level => int (default: 6)

    {en_US Call randlog()}.

    {en_US This is to test nested call (e.g. Log::Any::For::Package). }

  • min_level => int (default: 1)

    {en_US Call randlog()}.

    {en_US This is to test nested call (e.g. Log::Any::For::Package). }

  • n => int (default: 10)

    {en_US Call randlog()}.

    {en_US This is to test nested call (e.g. Log::Any::For::Package). }

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.

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

{id_ID Tidur, defaultnya 10 detik}.

{idID Dapat dipakai untuk menguji properti *timelimit*. }

Arguments ('*' denotes required arguments):

  • n => int (default: 10)

    {id_ID Tidur, defaultnya 10 detik}.

    {idID Dapat dipakai untuk menguji properti *timelimit*. }

  • per_second => bool (default: 0)

    {id_ID Tidur, defaultnya 10 detik}.

    {idID Dapat dipakai untuk menguji properti *timelimit*. }

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.

dies() -> [status, msg, result, meta]

{en_US Dies tragically}.

{en_US Can be used to test exception handling. }

No 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.

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

{en_US Return error response}.

{en_US }

Arguments ('*' denotes required arguments):

  • code => int (default: 500)

    {en_US Return error response}.

    {en_US }

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.

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

{en_US Generate an array of specified length}.

{en_US Also tests result schema. }

Arguments ('*' denotes required arguments):

  • len* => int (default: 10)

    {en_US Generate an array of specified length}.

    {en_US Also tests result schema. }

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.

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

{en_US Generate a hash with specified number of pairs}.

{en_US Also tests result schema. }

Arguments ('*' denotes required arguments):

  • pairs => int

    {en_US Generate a hash with specified number of pairs}.

    {en_US Also tests result schema. }

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.

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

{en_US Merge two hashes}.

{en_US This function can be used to test passing nonscalar (hash) arguments. }

Arguments ('*' denotes required arguments):

  • h1* => hash

    {en_US Merge two hashes}.

    {en_US This function can be used to test passing nonscalar (hash) arguments. }

  • h2* => hash

    {en_US Merge two hashes}.

    {en_US This function can be used to test passing nonscalar (hash) 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.

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

{en_US Do nothing, return original argument}.

{en_US }

This function is pure (produce no side effects).

Arguments ('*' denotes required arguments):

  • arg => any

    {en_US Do nothing, return original argument}.

    {en_US }

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.

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

{en_US Produce some random Log::Any log messages}.

{en_US }

Arguments ('*' denotes required arguments):

  • max_level => int (default: 6)

    {en_US Produce some random Log::Any log messages}.

    {en_US }

  • min_level => int (default: 1)

    {en_US Produce some random Log::Any log messages}.

    {en_US }

  • n => int (default: 10)

    {en_US Produce some random Log::Any log messages}.

    {en_US }

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.

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

{en_US Sum numbers in array}.

Examples:

 sum(array => [1, 2, 3]); # -> 6

 sum(array => [1.1, 2.1, 3.1], round => 1); # -> 6

 sum(array => ["a"]); # ERROR 400

 sum();

 sum();

{en_US This function can be used to test passing nonscalar (array) arguments. }

Arguments ('*' denotes required arguments):

  • array* => array

    {en_US Sum numbers in array}.

    {en_US This function can be used to test passing nonscalar (array) arguments. }

  • round => bool (default: 0)

    {en_US Sum numbers in array}.

    {en_US This function can be used to test passing nonscalar (array) 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.

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

{en_US Do nothing, return nothing}.

{en_US This function is used to test argument completion. }

This function is pure (produce no side effects).

Arguments ('*' denotes required arguments):

  • f1 => float

    {en_US Do nothing, return nothing}.

    {en_US This function is used to test argument completion. }

  • i1 => int

    {en_US Do nothing, return nothing}.

    {en_US This function is used to test argument completion. }

  • i2 => int

    {en_US Do nothing, return nothing}.

    {en_US This function is used to test argument completion. }

  • s1 => str

    {en_US Do nothing, return nothing}.

    {en_US This function is used to test argument completion. }

  • s2 => str

    {en_US Do nothing, return nothing}.

    {en_US This function is used to test argument completion. }

  • s3 => str

    {en_US Do nothing, return nothing}.

    {en_US This function is used to test argument completion. }

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.

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

{en_US Does nothing, only here to test # VALIDATE_ARGS}.

Arguments ('*' denotes required arguments):

  • a => int

    {en_US Does nothing, only here to test # VALIDATE_ARGS}.

  • b => str

    {en_US Does nothing, only here to test # VALIDATE_ARGS}.

  • h1 => hash

    {en_US Does nothing, only here to test # VALIDATE_ARGS}.

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.

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

{en_US This function has several undescribed args}.

{en_US Originally added to see how peri-func-usage or Perinci::To::Text will display the usage or documentation for this function. }

Arguments ('*' denotes required arguments):

  • arg1 => any

    {en_US This function has several undescribed args}.

    {en_US Originally added to see how peri-func-usage or Perinci::To::Text will display the usage or documentation for this function. }

  • arg2 => any

    {en_US This function has several undescribed args}.

    {en_US Originally added to see how peri-func-usage or Perinci::To::Text will display the usage or documentation for this function. }

  • arg3 => any

    {en_US This function has several undescribed args}.

    {en_US Originally added to see how peri-func-usage or Perinci::To::Text will display the usage or documentation for this function. }

  • arg4 => any

    {en_US This function has several undescribed args}.

    {en_US Originally added to see how peri-func-usage or Perinci::To::Text will display the usage or documentation for this function. }

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.

SEE ALSO

Perinci

Perinci::Examples::Bin

HOMEPAGE

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

SOURCE

Source repository is at https://github.com/sharyanto/perl-Perinci-Examples.

BUGS

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

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) 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.