mirror of
https://git.FreeBSD.org/ports.git
synced 2024-12-20 04:02:27 +00:00
2cfe6ef857
Approved by: tobez (implicit)
27 lines
1.4 KiB
Plaintext
27 lines
1.4 KiB
Plaintext
The Class:Multimethod module exports a subroutine (&multimethod) that can
|
|
be used to declare other subroutines that are dispatched using a algorithm
|
|
different from the normal Perl subroutine or method dispatch mechanism.
|
|
|
|
Normal Perl subroutines are dispatched by finding the appropriately-named
|
|
subroutine in the current (or specified) package and calling that. Normal
|
|
Perl methods are dispatched by attempting to find the appropriately-named
|
|
subroutine in the package into which the invoking object is blessed or,
|
|
failing that, recursively searching for it in the packages listed in the
|
|
appropriate @ISA arrays.
|
|
|
|
Class::Multimethods multimethods are dispatched quite differently. The
|
|
dispatch mechanism looks at the classes or types of each argument to the
|
|
multimethod (by calling ref on each) and determines the "closest" matching
|
|
variant of the multimethod, according to the argument types specified in
|
|
the variants' definitions (see "Finding the "nearest" multimethod" for a
|
|
definition of "closest").
|
|
|
|
The result is something akin to C++'s function overloading, but more
|
|
intelligent, since multimethods take the inheritance relationships of each
|
|
argument into account. Another way of thinking of the mechanism is that it
|
|
performs polymorphic dispatch on every argument of a method, not just the
|
|
first.
|
|
|
|
WWW: http://search.cpan.org/dist/Class-Multimethods
|
|
Author: Damian Conway <damian@conway.org>
|