Package Info

perl-UNIVERSAL-can


work around buggy code calling UNIVERSAL::can() as a function


Development/Libraries/Perl

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 the Scalar::Util manpage 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.


License: Artistic-1.0 or GPL-1.0+
URL: http://search.cpan.org/dist/UNIVERSAL-can/

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
1.20140328-bp156.3.1 info GA Release 2023-07-22 15 SP6
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can
1.20140328-bp155.2.12 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can
1.20140328-bp154.1.36 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can
1.20140328-bp153.1.17 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can
1.20140328-bp152.3.20 info GA Release 2020-04-16 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can
1.20140328-bp151.3.1 info GA Release 2019-07-16 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can
1.20140328-bp151.2.14 info GA Release 2019-05-18 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can
1.20140328-bp150.2.4 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-UNIVERSAL-can