class Backtrace

Snapshot of the dynamic call stack

class Backtrace is List { ... }

A backtrace shows the dynamic call stack, usually leading up to a point where an exception was thrown.

It is a List of Backtrace::Frame objects. Its default stringification excludes backtrace frames that are deemed unnecessary or confusing, for example routines like &die are hidden by default.

Methods

method new

proto method new(*@, *%) {*}
multi method new()

Creates a new backtrace, using its calling location as the origin of the backtrace.

method Str

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

Returns a concise string representation of the backtrace, omitting routines marked as is hidden_from_backtrace, and at the discretion of the implementor, also some routines from the setting.

method full

multi method full(Backtrace:D:) returns Str:D:

Returns a full string representation of the backtrace, including hidden frames, compiler-specific frames and those from the setting.

Type graph

Below you should see an image showing the type relations for Backtrace. If not, try the PNG version.

perl6-type-graph Backtrace Backtrace List List Backtrace->List Mu Mu Any Any Any->Mu Iterable Iterable Iterable->Any Cool Cool Cool->Any Positional Positional List->Iterable List->Cool List->Positional

Methods supplied by class List

Backtrace inherits from class List, which provides the following methods:

method Bool

multi method Bool(List:D:) returns Bool:D

Returns True if the list has at least one element, and False for the empty list.

method Str

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

Stringifies the elements of the list and joins them with spaces (same as .join(' ')).

method Int

multi method Int(List:D:) return Int:D

Returns the number of elements in the list (same as .elems).

method eager

multi method eager(List:D:) returns List:D

Evaluates all elements in the list eagerly, and returns the invocant. If a List signals that it is "known infinite", eager evaluation may stop at the point where the infinity is detected.

Methods supplied by role Positional

Backtrace inherits from class List, which does role Positional, which provides the following methods:

method of

method of()

Returns the type constraint for elements of the positional container. Defaults to Mu.

Methods supplied by class Any

Backtrace inherits from class Any, which provides the following methods:

method ACCEPTS

multi method ACCEPTS(Any:D: Mu $other)

Returns True if $other === self (i.e. it checks object identity).

method any

Interprets the invocant as a list and creates an any-Junction from it.

method all

Interprets the invocant as a list and creates an all-Junction from it.

method one

Interprets the invocant as a list and creates an one-Junction from it.

method none

Interprets the invocant as a list and creates an none-Junction from it.

Methods supplied by class Mu

Backtrace inherits from class Mu, which provides the following methods:

method Str

multi method Str()   returns Str

Returns a string representation of the invocant, intended to be machine readable.

method clone

method clone(*%twiddles)

Creates a shallow clone of the invocant. If named arguments are passed to it, their values are used in every place where an attribute name matches the name of a named argument.

method new

multi method new(*%attrinit)

Default method for constructing (create + initialize) new objects of a class. This method expects only named arguments which are then used to initialize attributes with accessors of the same name.

Classes may provide their own new method to override this default.

method bless

method bless(*%attrinit) returns Mu:D

Lower-level object construction method than new.

Creates a new object of the same type as the invocant, uses the named arguments to initialize attributes, and returns the created object.

You can use this method when writing custom constructors:

class Point {
    has $.x;
    has $.y;
    multi method new($x, $y) {
        self.bless(:$x, :$y);
    }
}
my $p = Point.new(-1, 1);

(Though each time you write a custom constructor, remember that it makes subclassing harder).

method CREATE

method CREATE() returns Mu:D

Allocates a new object of the same type as the invocant, without initializing any attributes.

method print

multi method print() returns Bool:D

Prints value to $*OUT after stringification using .Str method without newline at end.

method say

multi method say() returns Bool:D

Prints value to $*OUT after stringification using .gist method with newline at end.

method ACCEPTS

multi method ACCEPTS(Mu:U: $other)

Performs a type check. Returns True if $other conforms to the invocant (which is always a type object or failure).

This is the method that is triggered on smart-matching against type objects, for example in if $var ~~ Int { ... }.

method WHICH

multi method WHICH() returns ObjAt:D

Returns an object of type ObjAt which uniquely identifies the object. Value types override this method which makes sure that two equivalent objects return the same return value from WHICH.