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
26       see if the first argument is a valid invocant has its own "can()"
27       method.  If so, it gives a warning and calls the overridden method,
28       working around buggy code.  Otherwise, everything works as you might
29       expect.
30
31       Some people argue that you must call "UNIVERSAL::can()" as a function
32       because you don't know if your proposed invocant is a valid invocant.
33       That's silly.  Use "blessed()" from Scalar::Util if you want to check
34       that the potential invocant is an object or call the method anyway in
35       an "eval" block and check for failure (though check the exception
36       returned, as a poorly-written "can()" method could break Liskov and
37       throw an exception other than "You can't call a method on this type of
38       invocant").
39
40       Just don't break working code.
41

AUTHOR

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

BUGS

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

ACKNOWLEDGEMENTS

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