NAME

Sub::Spec::Examples - Various spec'ed functions, for examples and testing

VERSION

version 0.03

SYNOPSIS

use Sub::Spec::Examples qw(delay);
delay();

DESCRIPTION

This module and its submodules contain an odd mix of various functions, mostly simple ones, each with its Sub::Spec spec. Mostly used for testing spec or various Sub::Spec modules.

FUNCTIONS

None are exported by default, but they are exportable.

delay(%args) -> [STATUS_CODE, ERR_MSG, RESULT]

Sleep, by default for 10 seconds.

Can be used to test time_limit clause.

Returns a 3-element arrayref. STATUS_CODE is 200 on success, or an error code between 3xx-5xx (just like in HTTP). ERR_MSG is a string containing error message, RESULT is the actual result.

Arguments (* denotes required arguments):

  • n* => int (default 10)

    Number of seconds to sleep.

  • per_second* => bool (default 0)

    Whether to sleep(1) for n times instead of sleep(n).

dies(%args) -> [STATUS_CODE, ERR_MSG, RESULT]

Dies tragically.

Can be used to test exception handling.

Returns a 3-element arrayref. STATUS_CODE is 200 on success, or an error code between 3xx-5xx (just like in HTTP). ERR_MSG is a string containing error message, RESULT is the actual result.

No known arguments at this time.

err(%args) -> [STATUS_CODE, ERR_MSG, RESULT]

Return error response.

Returns a 3-element arrayref. STATUS_CODE is 200 on success, or an error code between 3xx-5xx (just like in HTTP). ERR_MSG is a string containing error message, RESULT is the actual result.

Arguments (* denotes required arguments):

  • code* => int (default 500)

    Error code to return.

gen_array(%args) -> [STATUS_CODE, ERR_MSG, RESULT]

Generate an array of specified length.

Returns a 3-element arrayref. STATUS_CODE is 200 on success, or an error code between 3xx-5xx (just like in HTTP). ERR_MSG is a string containing error message, RESULT is the actual result.

Arguments (* denotes required arguments):

  • len* => int

    Array length.

gen_hash(%args) -> [STATUS_CODE, ERR_MSG, RESULT]

Generate a hash with specified number of pairs.

Returns a 3-element arrayref. STATUS_CODE is 200 on success, or an error code between 3xx-5xx (just like in HTTP). ERR_MSG is a string containing error message, RESULT is the actual result.

Arguments (* denotes required arguments):

  • pairs* => int

    Number of pairs.

noop(%args) -> [STATUS_CODE, ERR_MSG, RESULT]

Do nothing, return original argument.

Returns a 3-element arrayref. STATUS_CODE is 200 on success, or an error code between 3xx-5xx (just like in HTTP). ERR_MSG is a string containing error message, RESULT is the actual result.

This function is declared as pure, meaning it does not change any external state or have any side effects.

Arguments (* denotes required arguments):

  • arg* =>

    Argument.

randlog(%args) -> [STATUS_CODE, ERR_MSG, RESULT]

Produce some random Log::Any log messages.

Returns a 3-element arrayref. STATUS_CODE is 200 on success, or an error code between 3xx-5xx (just like in HTTP). ERR_MSG is a string containing error message, RESULT is the actual result.

Arguments (* denotes required arguments):

  • n* => int (default 10)

    Number of log messages to produce.

  • min_level* => str (default "fatal")

    Value must be one of:

    ["trace", "info", "warn", "debug", "error", "fatal"]

    Minimum level.

  • max_level* => str (default "trace")

    Value must be one of:

    ["trace", "info", "warn", "debug", "error", "fatal"]

    Maximum level.

SEE ALSO

Sub::Spec

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

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