Data::Object::Cast
Data Type Casting for Perl 5
package main; use Data::Object::Cast; local $Data::Object::Cast::To = 'Test::Object'; # Data::Object::Cast::Deduce([1..4]); # Test::Object::Array
This package provides functions for casting native data types to objects and the reverse.
This package uses type constraints from:
Types::Standard
This package implements the following functions:
Deduce(Any $value) : Object
The Deduce function returns the argument as a data type object.
# given: synopsis Data::Object::Cast::Deduce([1..4]) # $array
# given: synopsis Data::Object::Cast::Deduce(sub { shift }) # $code
# given: synopsis Data::Object::Cast::Deduce(1.23) # $float
# given: synopsis Data::Object::Cast::Deduce({1..4}) # $hash
# given: synopsis Data::Object::Cast::Deduce(123) # $number
# given: synopsis Data::Object::Cast::Deduce(qr/.*/) # $regexp
# given: synopsis Data::Object::Cast::Deduce(\'abc') # $scalar
# given: synopsis Data::Object::Cast::Deduce('abc') # $string
# given: synopsis Data::Object::Cast::Deduce(undef) # $undef
DeduceDeep(Any @args) : (Object)
The DeduceDeep function returns any arguments as data type objects, including nested data.
# given: synopsis Data::Object::Cast::DeduceDeep([1..4]) # $array <$number>
# given: synopsis Data::Object::Cast::DeduceDeep({1..4}) # $hash <$number>
Detract(Any $value) : Any
The Detract function returns the argument as native Perl data type value.
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( [1..4] ) ) # $arrayref
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( sub { shift } ) ) # $coderef
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( 1.23 ) ) # $number
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( {1..4} ) ) # $hashref
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( 123 ) ) # $number
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( qr/.*/ ) ) # $regexp
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( \'abc' ) ) # $scalarref
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( 'abc' ) ) # $string
# given: synopsis Data::Object::Cast::Detract( Data::Object::Cast::Deduce( undef ) ) # $undef
DetractDeep(Any @args) : (Any)
The DetractDeep function returns any arguments as native Perl data type values, including nested data.
# given: synopsis Data::Object::Cast::DetractDeep( Data::Object::Cast::DeduceDeep( [1..4] ) )
# given: synopsis Data::Object::Cast::DetractDeep( Data::Object::Cast::DeduceDeep( {1..4} ) )
TypeName(Any $value) : Maybe[Str]
The TypeName function returns the name of the value's data type.
# given: synopsis Data::Object::Cast::TypeName([1..4]) # 'ARRAY'
# given: synopsis Data::Object::Cast::TypeName(sub { shift }) # 'CODE'
# given: synopsis Data::Object::Cast::TypeName(1.23) # 'FLOAT'
# given: synopsis Data::Object::Cast::TypeName({1..4}) # 'HASH'
# given: synopsis Data::Object::Cast::TypeName(123) # 'NUMBER'
# given: synopsis Data::Object::Cast::TypeName(qr/.*/) # 'REGEXP'
# given: synopsis Data::Object::Cast::TypeName(\'abc') # 'STRING'
# given: synopsis Data::Object::Cast::TypeName('abc') # 'STRING'
# given: synopsis Data::Object::Cast::TypeName(undef) # 'UNDEF'
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To install Data::Object::Cast, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Object::Cast
CPAN shell
perl -MCPAN -e shell install Data::Object::Cast
For more information on module installation, please visit the detailed CPAN module installation guide.