SYNOPSIS use Data::Object; # returns a code object my $object = Data::Object->new(sub{ join ' ', @_ }); # returns true $object->isa('Data::Object::Code'); # returns a string object my $string = $code->call('Hello', 'World'); # returns a new string object $string = $string->split('')->reverse->join('')->uppercase; # returns a number object (returns true) and outputs "DLROW OLLEH" my $result = $string->say; # returns true $result->isa('Data::Object::Number'); DESCRIPTION Data::Object is a framework for writing structured and highly object-oriented Perl 5 software programs. Additionally, this distribution provides classes which wrap Perl 5 native data types and provides methods for operating on the data. use Data::Object qw(:all); The all export tag will export all exportable functions. use Data::Object qw(:core); The core export tag will export the exportable functions const, deduce, deduce_deep, detract, detract_deep, immutable, load, prototype, reify, and throw exclusively. use Data::Object qw(:data); The data export tag will export all exportable functions whose names are prefixed with the word "data". use Data::Object qw(:type); The type export tag will export all exportable functions whose names are prefixed with the word "type". # given 1.098765; const VERSION => 1.098765; The const function creates a constant function using the name and expression supplied to it. A constant function is a function that does not accept any arguments and whose result(s) are deterministic. # 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/test/; $object = data_regexp qr/test/; $object->isa('Data::Object::Regexp'); The data_regexp function returns a 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. # given \*main; $object = data_scalar \*main; $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 qr/\w+/; $object = deduce qr/\w+/; $object->isa('Data::Object::Regexp'); 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]}}; # 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+/; # REGEXP 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. # given [1,2,3]; $object = immutable data_array [1,2,3]; $object->isa('Data::Object::Array); # via Data::Object::Immutable The immutable function makes the data type object provided immutable. This function loads Data::Object::Immutable and returns the object provided as an argument. # 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 ('$name' => [is => 'ro']); my $proto = data_prototype '$name' => [is => 'ro']; my $class = $proto->create; # via Data::Object::Prototype my $object = $class->new(name => '...'); The prototype function returns a prototype object which can be used to generate classes, objects, and derivatives. This function loads Data::Object::Prototype and returns an object based on the arguments provided. # given [1..9]; $array = reify [1..9]; # Data::Object::Array The reify function will determine the type of the value provided and return it as a data type object. This method is an alias to the deduce_deep function. # 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 class. SEE ALSO * Data::Object::Array * Data::Object::Class * Data::Object::Class::Syntax * Data::Object::Code * Data::Object::Float * Data::Object::Hash * Data::Object::Integer * Data::Object::Number * Data::Object::Role * Data::Object::Role::Syntax * Data::Object::Regexp * Data::Object::Scalar * Data::Object::String * Data::Object::Undef * Data::Object::Universal * Data::Object::Autobox * Data::Object::Immutable * Data::Object::Library * Data::Object::Prototype * Data::Object::Signatures POD ERRORS Hey! The above document had some coding errors, which are explained below: Around line 32: Unknown directive: =export Around line 38: Unknown directive: =export Around line 46: Unknown directive: =export Around line 53: Unknown directive: =export Around line 60: Unknown directive: =function Around line 70: Unknown directive: =function Around line 81: Unknown directive: =function Around line 92: Unknown directive: =function Around line 103: Unknown directive: =function Around line 114: Unknown directive: =function Around line 125: Unknown directive: =function Around line 136: Unknown directive: =function Around line 147: Unknown directive: =function Around line 158: Unknown directive: =function Around line 169: Unknown directive: =function Around line 180: Unknown directive: =function Around line 191: Unknown directive: =function Around line 201: Unknown directive: =function Around line 219: Unknown directive: =function Around line 228: Unknown directive: =function Around line 237: Unknown directive: =function Around line 257: Unknown directive: =function Around line 268: Unknown directive: =function Around line 277: Unknown directive: =function Around line 290: Unknown directive: =function Around line 299: Unknown directive: =function