Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

universal::can(3) [centos man page]

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

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>. 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 Buchmueller 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 Copyright (c) 2005 - 2011, chromatic. This module is made available under the same terms as Perl 5.12. POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 146: Non-ASCII character seen before =encoding in 'Buchmueller'. Assuming UTF-8 perl v5.16.3 2012-07-26 UNIVERSAL::can(3)

Check Out this Related Man Page

Check::ISA(3pm) 					User Contributed Perl Documentation					   Check::ISA(3pm)

NAME
Check::ISA - DWIM, correct checking of an object's class SYNOPSIS
use Check::ISA; if ( obj($foo, "SomeClass") ) { $foo->some_method; } # instead of one of these methods: UNIVERSAL::isa($foo, "SomeClass") # WRONG ref $obj eq "SomeClass"; # VERY WRONG $foo->isa("SomeClass") # May die local $@; eval { $foo->isa("SomeClass") } # too long DESCRIPTION
This module provides several functions to assist in testing whether a value is an object, and if so asking about its class. FUNCTIONS
obj $thing, [ $class ] This function tests if $thing is an object. If $class is provided, it also tests tests whether "$thing->isa($class)". $thing is considered an object if it's blessed, or if it's a "GLOB" with a valid "IO" slot (the "IO" slot contains a FileHandle object which is the actual invocant). This corresponds directly to "gv_fetchmethod". obj_does $thing, [ $class_or_role ] Just like "obj" but uses "DOES" in UNIVERSAL instead of "isa" in UNIVERSAL. "DOES" in UNIVERSAL is just like "isa", except it's use is encouraged to query about an interface, as opposed to the object structure. If "DOES" is not overridden by th ebject, calling it is semantically identical to calling "isa". This is probably reccomended over "obj" for interoperability, but can be slower on Perls before 5.10. Note that "DOES" in UNIVERSAL inv $thing, [ $class_or_role ] Just like "obj_does", but also returns true for classes. Note that this method is slower, but is supposed to return true for any value you can call methods on (class, object, filehandle, etc). Look into autobox if you would like to be able to call methods on all values. obj_can $thing, $method inv_can $thing, $method Checks if $thing is an object or class, and calls "can" on $thing if appropriate. SEE ALSO
UNIVERSAL, Params::Util, autobox, Moose, asa VERSION CONTROL
This module is maintained using Darcs. You can get the latest version from <http://nothingmuch.woobling.org/code>, and use "darcs send" to commit changes. AUTHOR
Yuval Kogman <nothingmuch@woobling.org> COPYRIGHT
Copyright (c) 2008 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2008-07-25 Check::ISA(3pm)
Man Page