SYNOPSIS 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 DESCRIPTION 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: # CODE: my $tm = $Data::Sah::Util::Type::type_metas; my @res; for (grep {$_ ne 'any' && $_ ne 'all'} sort keys %$tm) { push @res, {type=>$_, is_simple=>Data::Sah::Util::Type::is_simple($_) ? 1:"", is_numeric=>Data::Sah::Util::Type::is_numeric($_) ? 1:"", is_collection=>Data::Sah::Util::Type::is_collection($_) ? 1:"", is_ref=>Data::Sah::Util::Type::is_ref($_) ? 1:"" } } require Perinci::Result::Format::Lite; Perinci::Result::Format::Lite::format([200, "OK", \@res, {'table.fields'=>[qw/type is_simple is_collection is_ref is_numeric/]}], "text-pretty"); FUNCTIONS None exported by default, but they are exportable. get_type($sch) => STR Return type name. is_type($sch) => STR Return type name if type in schema is known, or undef. is_simple($sch[, \%opts]) => BOOL 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. 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. Options: * schema_is_normalized => BOOL is_collection($sch[, \%opts]) => BOOL Collection means array or 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. is_ref($sch[, \%opts]) => BOOL "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". is_numeric($sch[, \%opts]) => BOOL Currently, only num, int, and float are numeric. 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. SEE ALSO Data::Sah