NAME

Util::Underscore::Objects - Functions for introspecting and manipulating objects and classes

VERSION

version v1.4.2

FUNCTION REFERENCE

$str = _::blessed $obj
$str = _::blessed
$str = _::class $obj
$str = _::class

Accesses the class of the provided object.

Wrapper for Scalar::Util::blessed.

$obj: the object of which the class is to be determined. If omitted, uses $_.

returns: The class of $obj if that is a blessed scalar, else returns undef.

$bool = _::is_object $scalar
$bool = _::is_object

Checks that the argument is a blessed object. It's just an abbreviation for defined _::blessed $scalar.

$scalar: the scalar which may or may not be a blessed object.

returns: a boolean indicating whether the $scalar is a blessed object.

$bool = _::class_isa $class, $supertype

Checks that the $class inherits from the given $supertype, both given as strings. In most cases, one should use _::class_does instead.

$class: the name of the class.

$supertype: the name of another class.

returns: a boolean indicating whether $class inherits from $supertype.

$bool = _::class_does $class, $role

Checks that the $class performs the given $role, both given as strings. This means that the $class has a compatible interface to the $role. However, this does not require that the $class inherits from the $role.

$class: the name of the class.

$role: the name of a role.

returns: a boolean indicating whether $class conforms to the $role.

$bool = _::isa $object, $class

Checks that the $object inherits from the given class. In most cases, one should use _::does or _::is_instance instead.

$object: a scalar possibly containing an object.

$class: the name of a class:

returns: a boolean indicating whether the $object inherits from the given $class. Returns false if the $object parameter isn't actually an object.

$code = _::can $object, $method

Checks that the object can perform the given method.

if (my $code = _::can $object, $method) {
    $object->$method(@args);
}

$object: a scalar.

$method: the name of the method to search.

returns: if the $object can perform the $method, this returns a reference to that method. A false value is returned in all other cases (the object doesn't know about that method, or the $object argument doesn't actually hold an object).

$bool = _::is_instance $object, $role
$bool = _::does $object, $role

Checks that the given $object can perform the $role.

$object: a scalar possibly containing an object.

$role: the name of a role.

returns: a boolean value indicating whether the given $object conforms to the $role.

any = $maybe_object->_::safecall(method => @args)

This will call the method only if the $maybe_object is a blessed object. We do not check that the object can perform the method, so this might still raise an exception.

Context is propagated correctly to the method call. If the $maybe_object is not an object, this will simply return. In scalar context, this evaluates to undef, in list context this is the empty list.

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/latk/p5-Util-Underscore/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Lukas Atkinson (cpan: AMON) <amon@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Lukas Atkinson.

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