SYNOPSIS
use Data::Object 'deduce';
my $object = deduce [1..9];
$object->isa('Data::Object::Array'); # 1
$object->count; # 9
DESCRIPTION
Data::Object provides functions for promoting Perl 5 native data types
to objects which provide common methods for operating on the data.
Note: This is an early release available for testing and feedback and
as such is subject to change.
# given [2..5];
$object = data_array [2..5];
$object->isa('Data::Object::Array');
The data_array function returns a Data::Object::Array instance which
wraps the provided data type and can be used to perform operations on
the data. The type_array function is an alias to this function.
# given sub { 1 };
$object = data_code sub { 1 };
$object->isa('Data::Object::Code');
The data_code function returns a Data::Object::Code instance which
wraps the provided data type and can be used to perform operations on
the data. The type_code function is an alias to this function.
# given 5.25;
$object = data_float 5.25;
$object->isa('Data::Object::Float');
The data_float function returns a Data::Object::Float instance which
wraps the provided data type and can be used to perform operations on
the data. The type_float function is an alias to this function.
# given {1..4};
$object = data_hash {1..4};
$object->isa('Data::Object::Hash');
The data_hash function returns a Data::Object::Hash instance which
wraps the provided data type and can be used to perform operations on
the data. The type_hash function is an alias to this function.
# given -100;
$object = data_integer -100;
$object->isa('Data::Object::Integer');
The data_integer function returns a Data::Object::Object instance which
wraps the provided data type and can be used to perform operations on
the data. The type_integer function is an alias to this function.
# given 100;
$object = data_number 100;
$object->isa('Data::Object::Number');
The data_number function returns a Data::Object::Number instance which
wraps the provided data type and can be used to perform operations on
the data. The type_number function is an alias to this function.
# given qr/\w+/;
$object = data_scalar qr/\w+/;
$object->isa('Data::Object::Scalar');
The data_scalar function returns a Data::Object::Scalar instance which
wraps the provided data type and can be used to perform operations on
the data. The type_scalar function is an alias to this function.
# given 'abcdefghi';
$object = data_string 'abcdefghi';
$object->isa('Data::Object::String');
The data_string function returns a Data::Object::String instance which
wraps the provided data type and can be used to perform operations on
the data. The type_string function is an alias to this function.
# given undef;
$object = data_undef undef;
$object->isa('Data::Object::Undef');
The data_undef function returns a Data::Object::Undef instance which
wraps the provided data type and can be used to perform operations on
the data. The type_undef function is an alias to this function.
# given 0;
$object = data_universal 0;
$object->isa('Data::Object::Universal');
The data_universal function returns a Data::Object::Universal instance
which wraps the provided data type and can be used to perform
operations on the data. The type_universal function is an alias to this
function.
# given 'List::Util';
$package = load 'List::Util'; # List::Util if loaded
The load function attempts to dynamically load a module and either dies
or returns the package name of the loaded module.
# given qr/\w+/;
$object = deduce qr/\w+/;
$object->isa('Data::Object::Scalar');
The deduce function returns a data type object instance based upon the
deduced type of data provided.
# given {1,2,3,{4,5,6,[-1]}}
$deep = deduce_deep {1,2,3,{4,5,6,[-1]}}; # produces ...
# Data::Object::Hash {
# 1 => Data::Object::Number ( 2 ),
# 3 => Data::Object::Hash {
# 4 => Data::Object::Number ( 5 ),
# 6 => Data::Object::Array [ Data::Object::Integer ( -1 ) ],
# },
# }
The deduce_deep function returns a data type object. If the data
provided is complex, this function traverses the data converting all
nested data to objects. Note: Blessed objects are not traversed.
# given qr/\w+/;
$type = deduce_type qr/\w+/; # SCALAR
The deduce_type function returns a data type description for the type
of data provided, represented as a string in capital letters.
# given bless({1..4}, 'Data::Object::Hash');
$object = detract $object; # {1..4}
The detract function returns a value of native type, based upon the
underlying reference of the data type object provided.
# given {1,2,3,{4,5,6,[-1, 99, bless({}), sub { 123 }]}};
my $object = deduce_deep $object;
my $revert = detract_deep $object; # produces ...
# {
# '1' => 2,
# '3' => {
# '4' => 5,
# '6' => [ -1, 99, bless({}, 'main'), sub { ... } ]
# }
# }
The detract_deep function returns a value of native type. If the data
provided is complex, this function traverses the data converting all
nested data type objects into native values using the objects
underlying reference. Note: Blessed objects are not traversed.
SEE ALSO
* Data::Object::Array
* Data::Object::Code
* Data::Object::Float
* Data::Object::Hash
* Data::Object::Integer
* Data::Object::Number
* Data::Object::Scalar
* Data::Object::String
* Data::Object::Undef
* Data::Object::Universal
* Data::Object::Autobox
POD ERRORS
Hey! The above document had some coding errors, which are explained
below:
Around line 19:
Unknown directive: =function
Around line 30:
Unknown directive: =function
Around line 41:
Unknown directive: =function
Around line 52:
Unknown directive: =function
Around line 63:
Unknown directive: =function
Around line 74:
Unknown directive: =function
Around line 85:
Unknown directive: =function
Around line 96:
Unknown directive: =function
Around line 107:
Unknown directive: =function
Around line 118:
Unknown directive: =function
Around line 129:
Unknown directive: =function
Around line 138:
Unknown directive: =function
Around line 148:
Unknown directive: =function
Around line 166:
Unknown directive: =function
Around line 175:
Unknown directive: =function
Around line 184:
Unknown directive: =function