UNIVERSAL::DOES - Provides UNIVERSAL::DOES() method for older perls
This document describes UNIVERSAL::DOES version 0.005.
# if you require UNIVERSAL::DOES, you can say the following: require UNIVERSAL::DOES unless defined &UNIVERSAL::DOES; # you can call DOES() in any perls $class->DOES($role); $object->DOES($role); # also, this provides a does() function use UNIVERSAL::DOES qw(does); # use does($thing, $role), instead of UNIVERSAL::isa($thing, $role) does($thing, $role); # $thing can be non-invocant does($thing, 'ARRAY'); # also ok, $think may have overloaded @{}
UNIVERSAL::DOES provides a UNIVERSAL::DOES() method for compatibility with perl 5.10.x.
UNIVERSAL::DOES
UNIVERSAL::DOES()
This module also provides a does() function that checks something does some roles, suggested in perltodo.
does()
does($thing, $role)
does checks if $thing performs the role $role. If the thing is an object or class, it simply checks $thing->DOES($role). Otherwise it tells whether the thing can be dereferenced as an array/hash/etc.
does
$thing->DOES($role)
Unlike UNIVERSAL::isa(), it is semantically correct to use does for something unknown and to use it for reftype.
UNIVERSAL::isa()
reftype
This function handles overloading. For example, does($thing, 'ARRAY') returns true if the thing is an array reference, or if the thing is an object with overloaded @{}.
does($thing, 'ARRAY')
@{}
This is not exported by default.
The following description is just copied from UNIVERSAL in perl 5.10.1.
$obj->DOES( $ROLE )
CLASS->DOES( $ROLE )
DOES checks if the object or class performs the role ROLE. A role is a named group of specific behavior (often methods of particular names and signatures), similar to a class, but not necessarily a complete class by itself. For example, logging or serialization may be roles.
DOES
ROLE
DOES and isa are similar, in that if either is true, you know that the object or class on which you call the method can perform specific behavior. However, DOES is different from isa in that it does not care how the invocant performs the operations, merely that it does. (isa of course mandates an inheritance relationship. Other relationships include aggregation, delegation, and mocking.)
isa
By default, classes in Perl only perform the UNIVERSAL role, as well as the role of all classes in their inheritance. In other words, by default DOES responds identically to isa.
UNIVERSAL
There is a relationship between roles and classes, as each class implies the existence of a role of the same name. There is also a relationship between inheritance and roles, in that a subclass that inherits from an ancestor class implicitly performs any roles its parent performs. Thus you can use DOES in place of isa safely, as it will return true in all places where isa will return true (provided that any overridden DOES and isa methods behave appropriately).
The UNIVERSAL class has a new method, DOES(). It has been added to solve semantic problems with the isa() method. isa() checks for inheritance, while DOES() has been designed to be overridden when module authors use other types of relations between classes (in addition to inheritance).
DOES()
isa()
Like ref(), only useful. It would call the DOES method on objects; it would also tell whether something can be dereferenced as an array/hash/etc., or used as a regexp, etc. http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2007-03/msg00481.html
Perl 5.5.3 or later.
No bugs have been reported.
Please report any bugs or feature requests to the author.
Goro Fuji (gfx) <gfuji(at)cpan.org>
UNIVERSAL.
Copyright (c) 2009, Goro Fuji (gfx). Some rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install UNIVERSAL::DOES, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UNIVERSAL::DOES
CPAN shell
perl -MCPAN -e shell install UNIVERSAL::DOES
For more information on module installation, please visit the detailed CPAN module installation guide.