# NAME

Data::Object - Data Type Object Orientation for Perl 5

# VERSION

version 0.36

# SYNOPSIS

    package Person;

    use Data::Object ':core';

    use Data::Object::Class;
    use Data::Object::Class::Syntax;

    extends 'Entity';
    with    'Identity';

    has firstname => is required, ro;
    has lastname  => is required, ro;

    has address1  => is required, rw;
    has address2  => is optional, rw;

    has ['city', 'state', 'zip'] => is required, rw;

    def city  => 'San Franscisco';
    def state => 'CA';

    has country => is required, rw, default 'US';

    1;

# DESCRIPTION

Data::Object is a framework for writing structured and highly object-oriented
Perl 5 software programs. This distribution contains classes which wrap Perl 5
native data types and provides methods for operating on the data.

# EXPORTS

## all

    use Data::Object qw(:all);

The all export tag will export all exportable functions.

## core

    use Data::Object qw(:core);

The core export tag will export the exportable functions `alias`, `deduce`,
`deduce_deep`, `detract`, `detract_deep`, `load`, and `throw` exclusively.

## data

    use Data::Object qw(:data);

    data_undef;

The data export tag will export all exportable functions whose names are
prefixed with the word "data".

## type

    use Data::Object qw(:type);

    type_undef;

The type export tag will export all exportable functions whose names are
prefixed with the word "type".

# FUNCTIONS

## alias

    # given 'Exception::Type::Unknown';

    alias 'TypeUnknown' => 'Exception::Type::Unknown'; # TypeUnknown

The alias function returns an alias to the package specified. An alias is a
string representing the name of a fully-qualified constant function which
returns the specified package name.

## data\_array

    # given [2..5];

    $object = data_array [2..5];
    $object->isa('Data::Object::Array');

The data\_array function returns a [Data::Object::Array](https://metacpan.org/pod/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.

## data\_code

    # given sub { 1 };

    $object = data_code sub { 1 };
    $object->isa('Data::Object::Code');

The data\_code function returns a [Data::Object::Code](https://metacpan.org/pod/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.

## data\_float

    # given 5.25;

    $object = data_float 5.25;
    $object->isa('Data::Object::Float');

The data\_float function returns a [Data::Object::Float](https://metacpan.org/pod/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.

## data\_hash

    # given {1..4};

    $object = data_hash {1..4};
    $object->isa('Data::Object::Hash');

The data\_hash function returns a [Data::Object::Hash](https://metacpan.org/pod/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.

## data\_integer

    # given -100;

    $object = data_integer -100;
    $object->isa('Data::Object::Integer');

The data\_integer function returns a [Data::Object::Object](https://metacpan.org/pod/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.

## data\_number

    # given 100;

    $object = data_number 100;
    $object->isa('Data::Object::Number');

The data\_number function returns a [Data::Object::Number](https://metacpan.org/pod/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.

## data\_regexp

    # given qr/test/;

    $object = data_regexp qr/test/;
    $object->isa('Data::Object::Regexp');

The data\_regexp function returns a [Data::Object::Regexp](https://metacpan.org/pod/Data::Object::Regexp) instance which wraps
the provided data type and can be used to perform operations on the data. The
`type_regexp` function is an alias to this function.

## data\_scalar

    # given qr/\w+/;

    $object = data_scalar qr/\w+/;
    $object->isa('Data::Object::Scalar');

The data\_scalar function returns a [Data::Object::Scalar](https://metacpan.org/pod/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.

## data\_string

    # given 'abcdefghi';

    $object = data_string 'abcdefghi';
    $object->isa('Data::Object::String');

The data\_string function returns a [Data::Object::String](https://metacpan.org/pod/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.

## data\_undef

    # given undef;

    $object = data_undef undef;
    $object->isa('Data::Object::Undef');

The data\_undef function returns a [Data::Object::Undef](https://metacpan.org/pod/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.

## data\_universal

    # given 0;

    $object = data_universal 0;
    $object->isa('Data::Object::Universal');

The data\_universal function returns a [Data::Object::Universal](https://metacpan.org/pod/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.

## deduce

    # 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.

## deduce\_deep

    # 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.

## deduce\_type

    # 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.

## detract

    # 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.

## detract\_deep

    # 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.

## load

    # 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.

## throw

    # given $message;

    throw $message; # An exception (...) was thrown in -e at line 1

The throw function will dynamically load and throw an exception object. This
function takes all arguments accepted by the [Data::Object::Exception](https://metacpan.org/pod/Data::Object::Exception) class.

# SEE ALSO

- [Data::Object::Array](https://metacpan.org/pod/Data::Object::Array)
- [Data::Object::Class](https://metacpan.org/pod/Data::Object::Class)
- [Data::Object::Class::Syntax](https://metacpan.org/pod/Data::Object::Class::Syntax)
- [Data::Object::Code](https://metacpan.org/pod/Data::Object::Code)
- [Data::Object::Float](https://metacpan.org/pod/Data::Object::Float)
- [Data::Object::Hash](https://metacpan.org/pod/Data::Object::Hash)
- [Data::Object::Integer](https://metacpan.org/pod/Data::Object::Integer)
- [Data::Object::Number](https://metacpan.org/pod/Data::Object::Number)
- [Data::Object::Role](https://metacpan.org/pod/Data::Object::Role)
- [Data::Object::Role::Syntax](https://metacpan.org/pod/Data::Object::Role::Syntax)
- [Data::Object::Regexp](https://metacpan.org/pod/Data::Object::Regexp)
- [Data::Object::Scalar](https://metacpan.org/pod/Data::Object::Scalar)
- [Data::Object::String](https://metacpan.org/pod/Data::Object::String)
- [Data::Object::Undef](https://metacpan.org/pod/Data::Object::Undef)
- [Data::Object::Universal](https://metacpan.org/pod/Data::Object::Universal)
- [Data::Object::Autobox](https://metacpan.org/pod/Data::Object::Autobox)
- [Data::Object::Library](https://metacpan.org/pod/Data::Object::Library)
- [Data::Object::Signatures](https://metacpan.org/pod/Data::Object::Signatures)

# AUTHOR

Al Newkirk <anewkirk@ana.io>

# CONTRIBUTOR

Anthony Brummett <abrummet@genome.wustl.edu>

# COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Al Newkirk.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
