Data::Sah::Util::Type - Utility functions related to types
This document describes version 0.46 of Data::Sah::Util::Type (from Perl distribution Data-Sah-Util-Type), released on 2016-12-09.
use Data::Sah::Util::Type qw( get_type is_type is_simple is_numeric is_collection is_ref ); say get_type("int"); # -> int say get_type("int*"); # -> int say get_type([int => min=>0]); # -> int say get_type("foo"); # -> foo (doesn't check type is known) say is_type("int*"); # -> 1 say is_type("foo"); # -> 0 say is_simple("int"); # -> 1 say is_simple("array"); # -> 0 say is_simple([any => of => ["float", "str"]); # -> 1 say is_simple("re"); # -> 1 say is_simple("foo"); # -> 0 say is_collection("array*"); # -> 1 say is_collection(["hash", of=>"int"]); # -> 1 say is_collection("str"); # -> 0 say is_collection("foo"); # -> 0 say is_ref("code*"); # -> 1 say is_ref("array"); # -> 1 say is_ref("str"); # -> 0 say is_ref("foo"); # -> 0 say is_numeric(["int", min=>0]); # -> 1 say is_numeric("str"); # -> 0 say is_numeric("foo"); # -> 0
This module provides some secondary utility functions related to Sah and Data::Sah. It is deliberately distributed separately from the Data-Sah main distribution to be differentiated from Data::Sah::Util which contains "primary" utilities and is distributed with Data-Sah.
Reference table for simple/collection/ref/numeric criteria of builtin types:
+----------+-----------+---------------+--------+------------+ | type | is_simple | is_collection | is_ref | is_numeric | +----------+-----------+---------------+--------+------------+ | array | | 1 | 1 | | | bool | 1 | | | | | buf | 1 | | | | | cistr | 1 | | | | | code | | | 1 | | | date | 1 | | | | | duration | 1 | | | | | float | 1 | | | 1 | | hash | | 1 | 1 | | | int | 1 | | | 1 | | num | 1 | | | 1 | | obj | | | 1 | | | re | 1 | | 1 | | | str | 1 | | | | | undef | 1 | | | | +----------+-----------+---------------+--------+------------+
None exported by default, but they are exportable.
Return type name.
Return type name if type in schema is known, or undef.
Simple means "scalar" or can be represented as a scalar. This is currently used to determine if a builtin type can be specified as an argument or option value in command-line.
This includes re, bool, as well as date and duration.
re
bool
date
duration
If type is all, then for this routine to be true all of the mentioned types must be simple. If type is any, then for this routine to be true at least one of the mentioned types must be simple.
all
any
Options:
schema_is_normalized => BOOL
Collection means array or hash.
array
hash
If type is all, then for this routine to be true all of the mentioned types must be collection. If type is any, then for this routine to be true at least one of the mentioned types must be collection.
"Ref" means generally a reference in Perl. But date and duration are not regarded as "ref". Regular expression on the other hand is regarded as a ref.
If type is all, then for this routine to be true all of the mentioned types must be "ref". If type is any, then for this routine to be true at least one of the mentioned types must be "ref".
Currently, only num, int, and float are numeric.
num
int
float
If type is all, then for this routine to be true all of the mentioned types must be numeric. If type is any, then for this routine to be true at least one of the mentioned types must be numeric.
Please visit the project's homepage at https://metacpan.org/release/Data-Sah-Util-Type.
Source repository is at https://github.com/perlancar/perl-Data-Sah-Util-Type.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah-Util-Type
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.
Data::Sah
perlancar <perlancar@cpan.org>
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Sah::Util::Type, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Sah::Util::Type
CPAN shell
perl -MCPAN -e shell install Data::Sah::Util::Type
For more information on module installation, please visit the detailed CPAN module installation guide.