The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Object::Export

ABSTRACT

Data-Object Exportable Functions

SYNOPSIS

  use Data::Object::Export 'cast';

  my $array = cast []; # Data::Object::Array

DESCRIPTION

Data::Object::Export is an exporter that provides various useful utility functions and function-bundles.

EXPORTS

This package can export the following functions.

all

  use Data::Object::Export ':all';

The all export tag will export all exportable functions.

core

  use Data::Object::Export ':core';

The core export tag will export the exportable functions cast, codify, const, deduce, deduce_deep, deduce_type, detract, detract_deep, dispatch, dump, immutable, load, prototype, and throw exclusively.

data

  use Data::Object::Export ':data';

The data export tag will export the exportable functions data_any, data_array, data_code, data_float, data_hash, data_integer, data_number, data_regexp, data_scalar, data_string, and data_undef.

plus

  use Data::Object::Export ':plus';

The plus export tag will export the exportable functions carp, confess cluck croak, class_file, class_name, class_path, library, namespace, path_class, path_name, registry, and reify.

type

  use Data::Object::Export ':type';

The type export tag will export the exportable functions type_any, type_array, type_code, type_float, type_hash, type_integer, type_number, type_regexp, type_scalar, type_string, and type_undef.

vars

  use Data::Object::Export ':vars';

The vars export tag will export the exportable variable $dispatch.

FUNCTIONS

This package implements the following functions.

do

  # given file syntax

  do 'file.pl'

  # given block syntax

  do { @{"${class}::ISA"} }

  # given func-args syntax

  do('any', [1..4]); # Data::Object::Any

The do function is a special constructor function that is automatically exported into the consuming package. It overloads and extends the core do function, supporting the core functionality and adding a new feature, and exists to dispatch to exportable Data-Object functions and other dispatchers.

data_json

  # given $string

  my $data = data_json($string);

  # given $data

  my $string = data_json($data);

The data_json function encodes Perl data to JSON or decodes JSON strings to Perl.

data_path

  # given $filepath

  my $path = data_path($filepath);

The data_path function returns a Data::Object::Path object for the given path.

data_tmpl

  # given ($content, $variables)

  my $tmpl = data_tmpl;

  my $data = $tmpl->render($content, $variables);

The data_tmpl function returns a Data::Object::Template object.

data_yaml

  # given $string

  my $data = data_yaml($string);

  # given $data

  my $string = data_yaml($data);

The data_yaml function encodes Perl data to YAML or decodes YAML strings to Perl.

data_any

  # given 0;

  $object = data_any 0;
  $object->isa('Data::Object::Any');

The data_any function returns a Data::Object::Any instance which wraps the provided data type and can be used to perform operations on the data. The type_any function is an alias to this function.

data_array

  # given [2..5];

  $data = data_array [2..5];
  $data->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.

data_code

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

data_data

  # given Foo::Bar;

  $object = data_data 'Foo::Bar';
  $object->isa('Data::Object::Data');

The data_data function returns a Data::Object::Data instance which parses pod-ish data in files and packages.

data_dispatch

  # given Foo::Bar;

  $object = data_dispatch 'Foo::Bar';
  $object->isa('Data::Object::Dispatch');

The data_dispatch function returns a Data::Object::Dispatch instance which extends Data::Object::Code and dispatches to routines in the given package.

data_exception

  # given {,...};

  $object = data_exception {,...};
  $object->isa('Data::Object::Exception');

The data_exception function returns a Data::Object::Exception instance which can be thrown.

data_float

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

data_hash

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

data_integer

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

data_number

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

data_regexp

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

data_scalar

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

data_space

  # given Foo::Bar;

  $object = data_space 'Foo::Bar';
  $object->isa('Data::Object::Space');

The data_space function returns a Data::Object::Space instance which provides methods for operating on package and namespaces.

data_string

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

data_undef

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

immutable

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

library

  library; # Type::Library

The library function returns the default Type::Library object where all core type constraints are registered.

prototype

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

registry

  registry; # Data::Object::Registry

The registry function returns the registry singleton object where mapping between namespaces and type libraries are registered.

reify

  # given 'Str';

  $type = reify 'Str'; # Type::Tiny

The reify function will construct a Type::Tiny type constraint object for the type expression provided.

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

cast

  # given [1..4]

  my $array = cast([1..4]); # Data::Object::Array

The cast function returns a Data::Object for the data provided. If the data passed is blessed then that same object will be returned.

const

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

codify

  my $coderef = codify('$a + $b + $c', 1, 2);

  # $coderef->(3) returns 6

The codify function returns a parameterized coderef from a string.

dispatch

  my $dispatch = dispatch('main');

  # $dispatch->('run') calls main::run

The dispatch function return a Data::Object::Dispatch object which is a handle that let's you call into other packages.

dump

  # given {1..8}

  say dump {1..8};

The dump function returns a string representation of the data passed.

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.

namespace

  # given Types::Standard

  namespace('App', 'Types::Standard');

The namespace function registers a type library with a namespace in the registry so that typed operations know where to look for type context-specific constraints.

deduce

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

deduce_defined

  # given $data

  deduce_defined($data);

The deduce_defined function returns truthy if the argument is defined.

deduce_blessed

  # given $data

  deduce_blessed($data);

The deduce_blessed function returns truthy if the argument is blessed.

deduce_references

  # given $data

  deduce_references($data);

The deduce_references function returns a Data::Object object based on the type of argument reference provided.

deduce_numberlike

  # given $data

  deduce_numberlike($data);

The deduce_numberlike function returns truthy if the argument is numberlike.

deduce_stringlike

  # given $data

  deduce_stringlike($data);

The deduce_stringlike function returns truthy if the argument is stringlike.

deduce_deep

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

deduce_type

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

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.

class_file

  # given 'Foo::Bar'

  class_file('Foo::Bar'); # foo_bar

The class_file function convertss a class name to a class file.

class_name

  # given 'foo-bar'

  class_name('foo-bar'); # Foo::Bar

The class_name function converts a string to a class name.

class_path

  # given 'Foo::BarBaz'

  class_path('Foo::BarBaz'); 'Foo/BarBaz.pm'

The class_path function converts a class name to a class file.

path_class

  # given 'foo/bar_baz'

  path_class('foo/bar_baz'); # Foo::BarBaz

The path_class function converts a path to a class name.

path_name

  # given 'Foo::BarBaz'

  path_name('Foo::BarBaz'); # foo-bar_baz

The path_name function converts a class name to a path.