1UNIVERSAL::can(3)     User Contributed Perl Documentation    UNIVERSAL::can(3)
2
3
4

NAME

6       UNIVERSAL::can - work around buggy code calling UNIVERSAL::can() as a
7       function
8

SYNOPSIS

10       To use this module, simply:
11
12         use UNIVERSAL::can;
13

DESCRIPTION

15       The UNIVERSAL class provides a few default methods so that all objects
16       can use them.  Object orientation allows programmers to override these
17       methods in subclasses to provide more specific and appropriate
18       behavior.
19
20       Some authors call methods in the UNIVERSAL class on potential invocants
21       as functions, bypassing any possible overriding.  This is wrong and you
22       should not do it.  Unfortunately, not everyone heeds this warning and
23       their bad code can break your good code.
24
25       This module replaces UNIVERSAL::can() with a method that checks to see
26       if the first argument is a valid invocant has its own can() method.  If
27       so, it gives a warning and calls the overridden method, working around
28       buggy code.  Otherwise, everything works as you might expect.
29
30       Some people argue that you must call UNIVERSAL::can() as a function
31       because you don't know if your proposed invocant is a valid invocant.
32       That's silly.  Use blessed() from Scalar::Util if you want to check
33       that the potential invocant is an object or call the method anyway in
34       an "eval" block and check for failure (though check the exception
35       returned, as a poorly-written can() method could break Liskov and throw
36       an exception other than "You can't call a method on this type of
37       invocant").
38
39       Just don't break working code.
40

AUTHOR

42       chromatic, "<chromatic@wgz.org>"
43

BUGS

45       Please report any bugs or feature requests to
46       "bug-universal-can@rt.cpan.org", or through the web interface at
47       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=UNIVERSAL-can>.  This
48       will contact me, hold onto patches so I don't drop them, and will
49       notify you of progress on your request as I make changes.
50

ACKNOWLEDGEMENTS

52       Inspired by UNIVERSAL::isa by Yuval Kogman, Autrijus Tang, and myself.
53
54       Adam Kennedy has tirelessly made me tired by reporting potential bugs
55       and suggesting ideas that found actual bugs.
56
57       Mark Clements helped to track down an invalid invocant bug.
58
59       Curtis "Ovid" Poe finally provided the inspiration I needed to clean up
60       the interface.
61
62       Peter du Marchie van Voorthuysen identified and fixed a problem with
63       calling "SUPER::can".
64
65       Daniel LeWarne found and fixed a deep recursion error.
66
67       Norbert Buchmüller fixed an overloading bug in blessed invocants.
68
69       The Perl QA list had a huge... discussion... which inspired my
70       realization that this module needed to do what it does now.
71
73       Copyright (c) 2005 - 2014, chromatic. This module is made available
74       under the same terms as Perl 5.12.
75
76
77
78perl v5.36.0                      2023-01-20                 UNIVERSAL::can(3)
Impressum