/
Also.pm6
65 lines (45 loc) · 1.38 KB
/
Also.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use v6.c;
module Method::Also:ver<0.0.1>:auth<cpan:ELIZABETH> {
multi sub trait_mod:<is>(Method:D \meth, :$also!) is export {
if $also {
if $also ~~ List {
meth.package.^add_method($_,meth) for @$also;
}
else {
meth.package.^add_method($also.Str,meth);
}
}
}
}
=begin pod
=head1 NAME
Method::Also - add "is also" trait to Methods
=head1 SYNOPSIS
use Method::Also;
class Foo {
has $.foo;
method foo() is also<bar bazzy> { $!foo }
}
Foo.new(foo => 42).bar; # 42
Foo.new(foo => 42).bazzy; # 42
# separate multi methods can have different aliases
class Bar {
multi method foo() is also<bar> { 42 }
multi method foo($foo) is also<bazzy> { $foo }
}
Bar.foo; # 42
Bar.foo(666); # 666
Bar.bar; # 42
Bar.bazzy(768); # 768
=head1 DESCRIPTION
This module adds a C<is also> trait to C<Method>s, allowing you to specify
other names for the same method.
=head1 AUTHOR
Elizabeth Mattijsen <liz@wenzperl.nl>
Source can be located at: https://github.com/lizmat/Method-Also .
Comments and Pull Requests are welcome.
=head1 COPYRIGHT AND LICENSE
Copyright 2018 Elizabeth Mattijsen
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
=end pod
# vim: ft=perl6 expandtab sw=4