NAME
Venus::What - What Class
ABSTRACT
What Class for Perl 5
SYNOPSIS
package main;
use Venus::What;
my $what = Venus::What->new([]);
# $what->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::What; my $what = Venus::What->new(value => {}); my $code = $what->code; # "HASH"
- code example 3
-
package main; use Venus::What; my $what = Venus::What->new(value => qr//); my $code = $what->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 = $what->deduce; # bless({ value => [] }, "Venus::Array")
- deduce example 2
-
package main; use Venus::What; my $what = Venus::What->new(value => {}); my $deduce = $what->deduce; # bless({ value => {} }, "Venus::Hash")
- deduce example 3
-
package main; use Venus::What; my $what = Venus::What->new(value => qr//); my $deduce = $what->deduce; # bless({ value => qr// }, "Venus::Regexp")
- deduce example 4
-
package main; use Venus::What; my $what = Venus::What->new(value => '1.23'); my $deduce = $what->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::What; my $what = Venus::What->new(value => [1..4]); my $deduce_deep = $what->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::What; my $what = Venus::What->new(value => {1..4}); my $deduce_deep = $what->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::What; use Venus::Hash; my $what = Venus::What->new(Venus::Hash->new({1..4})); my $detract = $what->detract; # { 1 => 2, 3 => 4 }
- detract example 2
-
package main; use Venus::What; use Venus::Array; my $what = Venus::What->new(Venus::Array->new([1..4])); my $detract = $what->detract; # [1..4]
- detract example 3
-
package main; use Venus::What; use Venus::Regexp; my $what = Venus::What->new(Venus::Regexp->new(qr/\w+/)); my $detract = $what->detract; # qr/\w+/
- detract example 4
-
package main; use Venus::What; use Venus::Float; my $what = Venus::What->new(Venus::Float->new('1.23')); my $detract = $what->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::What; use Venus::Hash; my $what = Venus::What->new(Venus::Hash->new({1..4})); my $detract_deep = Venus::What->new($what->deduce_deep)->detract_deep; # { 1 => 2, 3 => 4 }
- detract_deep example 2
-
package main; use Venus::What; use Venus::Array; my $what = Venus::What->new(Venus::Array->new([1..4])); my $detract_deep = Venus::What->new($what->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, $whatname) = $what->identify; # (1, 0, 'ARRAY')
- identify example 2
-
package main; use Venus::What; my $what = Venus::What->new(value => {}); my ($defined, $blessed, $whatname) = $what->identify; # (1, 0, 'HASH')
- identify example 3
-
package main; use Venus::What; my $what = Venus::What->new(value => qr//); my ($defined, $blessed, $whatname) = $what->identify; # (1, 1, 'REGEXP')
- identify example 4
-
package main; use Venus::What; my $what = Venus::What->new(value => bless{}); my ($defined, $blessed, $whatname) = $what->identify; # (1, 1, 'OBJECT')
new
new(any @args) (Venus::What)
The new method constructs an instance of the package.
Since 4.15
- new example 1
-
package main; use Venus::What; my $new = Venus::What->new; # bless(..., "Venus::What")
- new example 2
-
package main; use Venus::What; my $new = Venus::What->new('hello world'); # bless(..., "Venus::What")
- new example 3
-
package main; use Venus::What; my $new = Venus::What->new(value => 'hello world'); # bless(..., "Venus::What")
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::What; my $what = Venus::What->new(value => {}); my $package = $what->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.