|
| 1 | +=begin pod |
| 2 | +
|
| 3 | +=head1 Code |
| 4 | +
|
| 5 | + class Code is Any does Callable { ... } |
| 6 | +
|
| 7 | +C<Code> is the ultimate base class of all code objects in Perl 6. It |
| 8 | +exposes functionality that all code objects have. While thunks are |
| 9 | +directly of type C<Code>, most code objects (such as those resulting |
| 10 | +from blocks, subroutines or methods) will be of some subclass of C<Code>. |
| 11 | +
|
| 12 | +
|
| 13 | +=head2 Methods |
| 14 | +
|
| 15 | +=head3 ACCEPTS(Code:D: Mu $topic) |
| 16 | +
|
| 17 | +Usually calls the code object and passes C<$topic> as an argument. |
| 18 | +However, when called on a code object that takes no arguments, the code |
| 19 | +object is invoked with no arguments and C<$topic> is dropped. The |
| 20 | +result of the call is returned. |
| 21 | +
|
| 22 | +=head3 arity(Code:D:) |
| 23 | +
|
| 24 | +Returns the minimum number of positional arguments that must be passed |
| 25 | +in order to call the code object. Any optional or slurpy parameters in the |
| 26 | +code object's C<Signature> do not contribute, nor do named parameters. |
| 27 | +
|
| 28 | + sub argless() { } |
| 29 | + sub args($a, $b?) { } |
| 30 | + sub slurpy($a, $b, *@c) { } |
| 31 | + say &argless.arity; # 0 |
| 32 | + say &args.arity; # 1 |
| 33 | + say &slurpy.arity; # 2 |
| 34 | +
|
| 35 | +=head3 count(Code:D:) |
| 36 | +
|
| 37 | +Returns the maximum number of positional arguments that may be passed |
| 38 | +when calling the code object. For code objects that can accept any |
| 39 | +number of positional arguments (that is, they have a slurpy parameter), |
| 40 | +C<count> will return C<Inf>. Named parameters do not contribute. |
| 41 | +
|
| 42 | + sub argless() { } |
| 43 | + sub args($a, $b?) { } |
| 44 | + sub slurpy($a, $b, *@c) { } |
| 45 | + say &argless.count; # 0 |
| 46 | + say &args.count; # 2 |
| 47 | + say &slurpy.count; # Inf |
| 48 | +
|
| 49 | +=head3 signature(Code:D:) |
| 50 | +
|
| 51 | +Returns the C<Signature> object for this code object, which describes |
| 52 | +its parameters. |
| 53 | +
|
| 54 | +=head3 Str(Code:D:) |
| 55 | +
|
| 56 | +Returns the name of the code object. |
| 57 | +
|
| 58 | + sub marine() { } |
| 59 | + say ~&marine.name; # marine |
| 60 | +
|
| 61 | +=end pod |
0 commit comments