UNIVERSAL::can(3)
πΈ NAME πΈ
okay so bestie, welcome to UNIVERSAL::can(3) from the User Contributed Perl Documentation collection π
. This page is all about UNIVERSAL::can β it's here to work around buggy code calling UNIVERSAL::can() as a function π.
β¨ SYNOPSIS β¨
To use this module, simply:
use UNIVERSAL::can;
π DESCRIPTION π
The UNIVERSAL class hands every object a few default methods so they can all use them. Object orientation lets programmers 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 whether the first argument is a valid invocant with 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::isaby 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" Poefinally 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 BuchmΓΌller 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 - 2014, chromatic. This module is made available under the same terms as Perl 5.12 π.
π and that's the page, bestie β source/version perl v5.42.0, dated 2014-07-25, and yes this is UNIVERSAL::can(3). bye! π
π¦ where this page comes from
- opensuse-leap 16.0: perl-UNIVERSAL-can 1.20140328-bp160.1.12 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms