Documentation for method line assembled from the following pages:

Class: CallFrame §

From CallFrame

(CallFrame) method line §

method line()

This is a shortcut for looking up the line annotation. For example, the following two calls are identical.

say callframe(1).line;
say callframe(1).annotations<line>;

Role: X::Comp §

From X::Comp

(X::Comp) method line §

The line number in which the compilation error occurred.

Class: Backtrace::Frame §

From Backtrace::Frame

(Backtrace::Frame) method line §

Defined as:

method line(Backtrace::Frame:D --> Int)

Returns the line number (line numbers start counting from 1).

my $bt = Backtrace.new;
my $btf = $bt[0];
say $btf.line;

Class: Code §

From Code

(Code) method line §

Defined as

method line(Code:D: --> Int:D)

Returns the line number in the source code at which the code object's declaration begins.

say &infix:<+>.line;   # OUTPUT: «208␤»

If the code object was generated automatically (and thus not declared in the source code), then line returns the line on which the enclosing scope's declaration begins. For example, when called on an automatically generated accessor method produced by the has $.name syntax, line returns the line on which the method's class's declaration begins.

For example, if you have the following source file:

class Food {                # Line 1 
    has $.ingredients;      # Line 2 
                            # Line 3 
    method eat {};          # Line 4 
}                           # Line 5

Then the line method would give you the following output:

say Food.^lookup('eat').line;          # OUTPUT: «4␤» 
say Food.^lookup('ingredients').line;  # OUTPUT: «1␤» 

Class: Label §

From Label

(Label) method line §

Returns the line where the label has been defined.