NAME
Util::Underscore::References - Functions for introspecting and manipulating references
VERSION
version v1.4.2
FUNCTION REFERENCE
$int = _::ref_addr $reference
$int = _::ref_addr
-
wrapper for
Scalar::Util::refaddr
This is mostly equivalent to the numification of a reference:
0+$ref
. However, that fails for objects which have overloaded addition, which is why you should use this function instead.The ref address denotes identity: two references with the same address are the same object. However, the same address might be reused later, so storing the address is not useful. Use weak references instead.
$reference: the reference to obtain the address of. If omitted, uses
$_
.returns: an integer representing ther reference address if the input is any kind of reference (plain reference or object). If the input is not a reference,
undef
is returned. $str = _::ref_type $reference
$str = _::ref_type
-
wrapper for
Scalar::Util::reftype
Accesses the type of the bare reference:
SCALAR
,REF
,ARRAY
,HASH
,CODE
,GLOB
,REGEXP
. Unfortunately, regexes are special, so_::ref_type qr//
isREGEXP
whileref qr//
isRegexp
.$reference: the reference to obtain the type of. If omitted, uses
$_
.returns: the type of the reference. For blessed references, this will not be the class, but the type of the blessed reference. If the input is not a reference,
undef
is returned. _::ref_weaken $reference
_::ref_weaken
-
Turns the reference into a weak reference.
wrapper for
Scalar::Util::weaken
$reference: the reference to weaken. If omitted, uses
$_
.returns: n/a
_::ref_unweaken $reference
_::ref_unweaken
-
Turns a weak reference into a normal reference.
wrapper for
Scalar::Util::unweaken
$reference: the reference to unweaken. If omitted, uses
$_
.returns: n/a
$bool = _::ref_is_weak $reference
$bool = _::ref_is_weak
-
Checks whether the given reference is a weak reference.
wrapper for
Scalar::Util::isweak
$reference: the reference to check. If omitted, uses
$_
.returns: a boolean indicating whether the given
$reference
was a weak reference.
Type Validation
These are inspired from Params::Util
and Data::Util
.
The reference validation routines take one argument (or $_
) and return a boolean value. They return true when the value is intended to be used as a reference of that kind: either ref_type $arg
is of the requested type, or it is an overloaded object that can be used as a reference of that kind. It will not be checked that an object claims to perform an appropriate role (e.g. $arg->DOES('ARRAY')
).
_::is_ref
(any nonblessed reference)_::is_scalar_ref
(also references to references)_::is_array_ref
_::is_hash_ref
_::is_code_ref
_::is_glob_ref
_::is_regex
(note that regexes are blessed objects, not plain references)
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.