NAME
Venus::Type - Type Class
ABSTRACT
Type Class for Perl 5
SYNOPSIS
package main;
use Venus::Type;
my $type = Venus::Type->new([]);
# $type->code;
DESCRIPTION
This package provides methods for casting native data types to objects and the reverse.
INHERITS
This package inherits behaviors from:
INTEGRATES
This package integrates behaviors from:
METHODS
This package provides the following methods:
code
code() (string | undef)
The code method returns the name of the value's data type.
Since 0.01
- code example 2
-
package main; use Venus::Type; my $type = Venus::Type->new(value => {}); my $code = $type->code; # "HASH"
- code example 3
-
package main; use Venus::Type; my $type = Venus::Type->new(value => qr//); my $code = $type->code; # "REGEXP"
coded
coded(string $code) (boolean)
The coded method return true or false if the data type name provided matches the result of "code".
Since 1.23
deduce
deduce() (object)
The deduce methods returns the argument as a data type object.
Since 0.01
- deduce example 1
-
# given: synopsis; my $deduce = $type->deduce; # bless({ value => [] }, "Venus::Array")
- deduce example 2
-
package main; use Venus::Type; my $type = Venus::Type->new(value => {}); my $deduce = $type->deduce; # bless({ value => {} }, "Venus::Hash")
- deduce example 3
-
package main; use Venus::Type; my $type = Venus::Type->new(value => qr//); my $deduce = $type->deduce; # bless({ value => qr// }, "Venus::Regexp")
- deduce example 4
-
package main; use Venus::Type; my $type = Venus::Type->new(value => '1.23'); my $deduce = $type->deduce; # bless({ value => "1.23" }, "Venus::Float")
deduce_deep
deduce_deep() (object)
The deduce_deep function returns any arguments as data type objects, including nested data.
Since 0.01
- deduce_deep example 1
-
package main; use Venus::Type; my $type = Venus::Type->new(value => [1..4]); my $deduce_deep = $type->deduce_deep; # bless({ # value => [ # bless({ value => 1 }, "Venus::Number"), # bless({ value => 2 }, "Venus::Number"), # bless({ value => 3 }, "Venus::Number"), # bless({ value => 4 }, "Venus::Number"), # ], # }, "Venus::Array")
- deduce_deep example 2
-
package main; use Venus::Type; my $type = Venus::Type->new(value => {1..4}); my $deduce_deep = $type->deduce_deep; # bless({ # value => { # 1 => bless({ value => 2 }, "Venus::Number"), # 3 => bless({ value => 4 }, "Venus::Number"), # }, # }, "Venus::Hash")
detract
detract() (any)
The detract method returns the argument as native Perl data type value.
Since 0.01
- detract example 1
-
package main; use Venus::Type; use Venus::Hash; my $type = Venus::Type->new(Venus::Hash->new({1..4})); my $detract = $type->detract; # { 1 => 2, 3 => 4 }
- detract example 2
-
package main; use Venus::Type; use Venus::Array; my $type = Venus::Type->new(Venus::Array->new([1..4])); my $detract = $type->detract; # [1..4]
- detract example 3
-
package main; use Venus::Type; use Venus::Regexp; my $type = Venus::Type->new(Venus::Regexp->new(qr/\w+/)); my $detract = $type->detract; # qr/\w+/
- detract example 4
-
package main; use Venus::Type; use Venus::Float; my $type = Venus::Type->new(Venus::Float->new('1.23')); my $detract = $type->detract; # "1.23"
detract_deep
detract_deep() (any)
The detract_deep method returns any arguments as native Perl data type values, including nested data.
Since 0.01
- detract_deep example 1
-
package main; use Venus::Type; use Venus::Hash; my $type = Venus::Type->new(Venus::Hash->new({1..4})); my $detract_deep = Venus::Type->new($type->deduce_deep)->detract_deep; # { 1 => 2, 3 => 4 }
- detract_deep example 2
-
package main; use Venus::Type; use Venus::Array; my $type = Venus::Type->new(Venus::Array->new([1..4])); my $detract_deep = Venus::Type->new($type->deduce_deep)->detract_deep; # [1..4]
identify
identify() (boolean, boolean, string)
The identify method returns the value's data type, or "code", in scalar context. In list context, this method will return a tuple with (defined, blessed, and data type) elements. Note: For globs and file handles this method will return "scalar" as the data type.
Since 1.23
- identify example 1
-
# given: synopsis package main; my ($defined, $blessed, $typename) = $type->identify; # (1, 0, 'ARRAY')
- identify example 2
-
package main; use Venus::Type; my $type = Venus::Type->new(value => {}); my ($defined, $blessed, $typename) = $type->identify; # (1, 0, 'HASH')
- identify example 3
-
package main; use Venus::Type; my $type = Venus::Type->new(value => qr//); my ($defined, $blessed, $typename) = $type->identify; # (1, 1, 'REGEXP')
- identify example 4
-
package main; use Venus::Type; my $type = Venus::Type->new(value => bless{}); my ($defined, $blessed, $typename) = $type->identify; # (1, 1, 'OBJECT')
package
package() (string)
The code method returns the package name of the objectified value, i.e. ref()
.
Since 0.01
- package example 2
-
package main; use Venus::Type; my $type = Venus::Type->new(value => {}); my $package = $type->package; # "Venus::Hash"
AUTHORS
Awncorp, awncorp@cpan.org
LICENSE
Copyright (C) 2022, Awncorp, awncorp@cpan.org
.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.