Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

universal::can(3pm) [debian man page]

UNIVERSAL::can(3pm)					User Contributed Perl Documentation				       UNIVERSAL::can(3pm)

NAME
UNIVERSAL::can - work around buggy code calling UNIVERSAL::can() as a function SYNOPSIS
To use this module, simply: use UNIVERSAL::can; DESCRIPTION
The UNIVERSAL class provides a few default methods so that all objects can use them. Object orientation allows programmers to override these methods in subclasses to provide more specific and appropriate behavior. Some authors call methods in the UNIVERSAL class on potential invocants as functions, bypassing any possible overriding. This is wrong and you should not do it. Unfortunately, not everyone heeds this warning and their bad code can break your good code. This module replaces "UNIVERSAL::can()" with a method that checks to see if the first argument is a valid invocant has its own "can()" method. If so, it gives a warning and calls the overridden method, working around buggy code. Otherwise, everything works as you might expect. Some people argue that you must call "UNIVERSAL::can()" as a function because you don't know if your proposed invocant is a valid invocant. That's silly. Use "blessed()" from Scalar::Util if you want to check that the potential invocant is an object or call the method anyway in an "eval" block and check for failure (though check the exception returned, as a poorly-written "can()" method could break Liskov and throw an exception other than "You can't call a method on this type of invocant"). Just don't break working code. AUTHOR
chromatic, "<chromatic@wgz.org>" BUGS
Please report any bugs or feature requests to "bug-universal-can@rt.cpan.org", or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=UNIVERSAL-can <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=UNIVERSAL-can>. This will contact me, hold onto patches so I don't drop them, and will notify you of progress on your request as I make changes. ACKNOWLEDGEMENTS
Inspired by UNIVERSAL::isa by Yuval Kogman, Autrijus Tang, and myself. Adam Kennedy has tirelessly made me tired by reporting potential bugs and suggesting ideas that found actual bugs. Mark Clements helped to track down an invalid invocant bug. Curtis "Ovid" Poe finally provided the inspiration I needed to clean up the interface. Peter du Marchie van Voorthuysen identified and fixed a problem with calling "SUPER::can". Daniel LeWarne found and fixed a deep recursion error. Norbert BuchmA~Xller fixed an overloading bug in blessed invocants. The Perl QA list had a huge... discussion... which inspired my realization that this module needed to do what it does now. COPYRIGHT &; LICENSE Artistic License 2.0, copyright (c) 2005 - 2011 chromatic. Some rights reserved. perl v5.12.3 2011-06-13 UNIVERSAL::can(3pm)

Check Out this Related Man Page

UNIVERSAL(3pm)						 Perl Programmers Reference Guide					    UNIVERSAL(3pm)

NAME
UNIVERSAL - base class for ALL classes (blessed references) SYNOPSIS
$is_io = $fd->isa("IO::Handle"); $is_io = Class->isa("IO::Handle"); $sub = $obj->can("print"); $sub = Class->can("print"); use UNIVERSAL qw( isa can VERSION ); $yes = isa $ref, "HASH" ; $sub = can $ref, "fandango" ; $ver = VERSION $obj ; DESCRIPTION
"UNIVERSAL" is the base class which all bless references will inherit from, see perlobj. "UNIVERSAL" provides the following methods and functions: $obj->isa( TYPE ), CLASS->isa( TYPE ), isa( VAL, TYPE ) C<TYPE> is a package name $obj is a blessed reference or a string containing a package name C<CLASS> is a package name C<VAL> is any of the above or an unblessed reference When used as an instance or class method ("$obj-"isa( TYPE )>), "isa" returns true if $obj is blessed into package "TYPE" or inherits from package "TYPE". When used as a class method ("CLASS-"isa( TYPE )>; sometimes referred to as a static method), "isa" returns true if "CLASS" inherits from (or is itself) the name of the package "TYPE" or inherits from package "TYPE". When used as a function, like use UNIVERSAL qw( isa ) ; $yes = isa $h, "HASH"; $yes = isa "Foo", "Bar"; or require UNIVERSAL ; $yes = UNIVERSAL::isa $a, "ARRAY"; , "isa" returns true in the same cases as above and also if "VAL" is an unblessed reference to a perl variable of type "TYPE", such as "HASH", "ARRAY", or "Regexp". $obj->can( METHOD ), CLASS->can( METHOD ), can( VAL, METHOD ) "can" checks if the object or class has a method called "METHOD". If it does then a reference to the sub is returned. If it does not then undef is returned. This includes methods inherited or imported by $obj, "CLASS", or "VAL". "can" cannot know whether an object will be able to provide a method through AUTOLOAD, so a return value of undef does not necessarily mean the object will not be able to handle the method call. To get around this some module authors use a forward declaration (see perl- sub) for methods they will handle via AUTOLOAD. For such 'dummy' subs, "can" will still return a code reference, which, when called, will fall through to the AUTOLOAD. If no suitable AUTOLOAD is provided, calling the coderef will cause an error. "can" can be called as a class (static) method, an object method, or a function. When used as a function, if "VAL" is a blessed reference or package name which has a method called "METHOD", "can" returns a reference to the subroutine. If "VAL" is not a blessed reference, or if it does not have a method "METHOD", undef is returned. VERSION ( [ REQUIRE ] ) "VERSION" will return the value of the variable $VERSION in the package the object is blessed into. If "REQUIRE" is given then it will do a comparison and die if the package version is not greater than or equal to "REQUIRE". "VERSION" can be called as either a class (static) method, an object method or or a function. These subroutines should not be imported via "use UNIVERSAL qw(...)". If you want simple local access to them you can do *isa = &UNIVERSAL::isa; to import isa into your package. perl v5.8.0 2002-06-01 UNIVERSAL(3pm)
Man Page