File Coverage

blib/lib/Acme/CPANModules/MultipleDispatch.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Acme::CPANModules::MultipleDispatch;
2              
3 1     1   273824 use strict;
  1         2  
  1         32  
4 1     1   3 use warnings;
  1         2  
  1         81  
5 1     1   469 use Acme::CPANModulesUtil::Misc;
  1         429  
  1         139  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-07-01'; # DATE
9             our $DIST = 'Acme-CPANModules-MultipleDispatch'; # DIST
10             our $VERSION = '0.001'; # VERSION
11              
12             my $text = <<'MARKDOWN';
13             **About multiple dispatch**
14              
15             Multiple dispatch is a technique where you can define /multiple/ functions (or
16             methods) of the same name but with different signatures (e.g. different type of
17             arguments, different number of arguments) and the runtime will choose
18             (/dispatch/) the correct function by matching the signature of the caller to
19             that of the defined functions.
20              
21             This technique has several benefits, mostly simplifying user code particularly
22             when dealing with different types/arguments, because you are deferring the
23             checks to the runtime. For example, if you create a function to concat two
24             strings:
25              
26             function combine(Str a, Str b) {
27             a + b;
28             }
29              
30             and later wants to support some other types, instead of peppering the original
31             function with `if` statements, you can just supply additional functions with the
32             same name but with different arguments you want to support:
33              
34             function combine(Num a, Num b) {
35             a.as_str() + b.as_str();
36             }
37              
38             function combine(File a, File b) {
39             a.open().read() + b.open().read();
40             }
41              
42             Some languages, particularly strongly-typed ones, support multiple dispatch:
43             Julia, C#, Common Lisp, Groovy. Raku (Perl 6) also supports multiple dispatch.
44              
45             Perl 5 does not. But some modules will allow you to fake it.
46              
47              
48             **Modules**
49              
50             . By DCONWAY.
51              
52             . Also by DCONWAY. An object system which supports multiple dispatch.
53              
54             . Older module by DCONWAY.
55              
56              
57             **Keywords**
58              
59             multi dispatch, multisub, multimethod.
60              
61             MARKDOWN
62              
63             our $LIST = {
64             summary => 'List of modules to do smart matching',
65             description => $text,
66             tags => ['task'],
67             };
68              
69             Acme::CPANModulesUtil::Misc::populate_entries_from_module_links_in_description;
70              
71             1;
72             # ABSTRACT: List of modules to do smart matching
73              
74             __END__