=begin pod

=TITLE class Code

=SUBTITLE Code object

    class Code is Any does Callable { ... }

C<Code> is the ultimate base class of all code objects in Perl 6. It
exposes functionality that all code objects have. While thunks are
directly of type C<Code>, most code objects (such as those resulting
from blocks, subroutines or methods) will be of some subclass of C<Code>.


=head1 Methods

=head2 method ACCEPTS

    multi method ACCEPTS(Code:D: Mu $topic)

Usually calls the code object and passes C<$topic> as an argument.
However, when called on a code object that takes no arguments, the code
object is invoked with no arguments and C<$topic> is dropped. The
result of the call is returned.

=head2 method arity

Defined as:

    method arity(Code:D:) returns Int:D

Usage:

    CODE.arity

Returns the minimum number of positional arguments that must be passed
in order to call the code object. Any optional or slurpy parameters in the
code object's C<Signature> do not contribute, nor do named parameters.

    sub argless() { }
    sub args($a, $b?) { }
    sub slurpy($a, $b, *@c) { }
    say &argless.arity;             # 0
    say &args.arity;                # 1
    say &slurpy.arity;              # 2

=head2 method count

Defined as:

    method count(Code:D:) returns Real:D

Usage:

    CODE.count

Returns the maximum number of positional arguments that may be passed
when calling the code object. For code objects that can accept any
number of positional arguments (that is, they have a slurpy parameter),
C<count> will return C<Inf>. Named parameters do not contribute.

    sub argless() { }
    sub args($a, $b?) { }
    sub slurpy($a, $b, *@c) { }
    say &argless.count;             # 0
    say &args.count;                # 2
    say &slurpy.count;              # Inf

=head2 method signature

Defined as:

    multi method signature(Code:D:) returns Signature:D

Usage:

    CODE.signature

Returns the L<C<Signature>> object for this code object, which describes
its parameters.

=head2 method Str

Defined as:

    multi method Str(Code:D:) returns Str:D

Usage:

    CODE.Str

Returns the name of the code object.

    sub marine() { }
    say ~&marine;   # marine


=head2 method file

Defined as:

    method file(Code:D:) returns Str:D

Usage:

    CODE.Str

Returns the name of the file in which the code object was declared.

    say &infix:<+>.file;

=head2 method line

Defined as

    method line(Code:D:) returns Int:D

Usage:

    CODE.Int

Returns the line number in which the code object was declared.

=end pod
