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 Keyword Functions

SYNOPSIS

  use Data::Object::Export;

  my $num = cast 123; # Data::Object::Number
  my $str = cast 123, 'string'; # Data::Object::String

DESCRIPTION

This package is an exporter that provides a few simple keyword functions to every calling package.

EXPORTS

This package can export the following functions.

all

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

The all export tag will export the exportable functions, i.e. cast, const, do, is_false, is_true, false, true, and raise.

INHERITANCE

This package inherits behaviors from:

Exporter

FUNCTIONS

This package implements the following functions.

cast

  cast(Any $arg1, Str $type) : Any

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

cast example
  # given 123

  my $num = cast(123); # Data::Object::Number
  my $str = cast(123, 'string'); # Data::Object::String

do

  do(Str $arg1, Any @args) : Any

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

do example
  # given file syntax

  do 'file.pl'

  # given block syntax

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

  # given func-args syntax

  do('array', [1..4]); # Data::Object::Array

dump

  dump(Any $value) : Str

The dump function uses Data::Dumper to return a string representation of the argument provided. This function is not exported but can be access via the super-do function.

dump example
  # given $value

  my $str = do('dump', $value);

false

  false() : BooleanObject

The false function returns a falsy boolean object.

false example
  my $false = false;

is_false

  is_false(Any $arg) : BooleanObject

The is_false function with no argument returns a falsy boolean object, otherwise, returns a boolean object based on the value of the argument provided.

is_false example
  my $bool;

  $bool = is_false; # false
  $bool = is_false 1; # false
  $bool = is_false {}; # false
  $bool = is_false bless {}; # false
  $bool = is_false 0; # true
  $bool = is_false ''; # true
  $bool = is_false undef; # true

is_true

  is_true(Any $arg) : BooleanObject

The is_true function with no argument returns a truthy boolean object, otherwise, returns a boolean object based on the value of the argument provided.

is_true example
  my $bool;

  $bool = is_true; # true
  $bool = is_true 1; # true
  $bool = is_true {}; # true
  $bool = is_true bless {}; # true
  $bool = is_true 0; # false
  $bool = is_true ''; # false
  $bool = is_true undef; # false

keyraise

  keyraise(Str $message, Any $context, Num $offset) : ()

The keyraise function is used internally by function keywords to "raise" exceptions from the persepective of the caller and not the keyword itself.

keyraise example
  keyraise($message, $context, $offset);

load

  load(Str $arg1) : ClassName

The load function attempts to dynamically load a module and either raises an exception or returns the package name of the loaded module. This function is not exported but can be access via the super-do function.

load example
  # given 'List::Util';

  $package = do('load', 'List::Util'); # List::Util

raise

  raise(Any @args) : Object

The raise function will dynamically load and raise an exception object. This function takes all arguments accepted by the Data::Object::Exception class.

raise example
  # given $message;

  raise $message; # Exception! thrown in -e at line 1

true

  true() : BooleanObject

The true function returns a truthy boolean object.

true example
  my $true = true;

CREDITS

Al Newkirk, +309

Anthony Brummett, +10

Adam Hopkins, +2

José Joaquín Atria, +1

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

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

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues

SEE ALSO

To get the most out of this distribution, consider reading the following:

Do

Data::Object

Data::Object::Class

Data::Object::ClassHas

Data::Object::Role

Data::Object::RoleHas

Data::Object::Library