The isa routine

Combined from primary sources listed below.

In class Mu ( Type/Mu )§

See primary docmentation in context for routine isa.

routine isa§

multi method isa(Mu $type     --> Bool:D)
multi method isa(Str:D $type  --> Bool:D)

Returns True if the invocant is an instance of class $type, a subset type or a derived class (through inheritance) of $type. does is similar, but includes roles.

my $i = 17;
say $i.isa("Int");   # OUTPUT: «True␤»
say $i.isa(Any);     # OUTPUT: «True␤»
role Truish {};
my $but-true = 0 but Truish;
say $but-true.^name;        # OUTPUT: «Int+{Truish}␤»
say $but-true.does(Truish); # OUTPUT: «True␤»
say $but-true.isa(Truish);  # OUTPUT: «False␤»

In module Test ( Type/Test )§

See primary docmentation in context for sub isa.

sub isa-ok§

multi isa-ok(Mu $var, Mu $type, $desc = "The object is-a '$type.raku()'")

Marks a test as passed if the given object $var is, or inherits from, the given $type. For convenience, types may also be specified as a string. The function accepts an optional description of the test, which defaults to a string that describes the object.

class Womble {}
class GreatUncleBulgaria is Womble {}
my $womble = GreatUncleBulgaria.new;

isa-ok $womble, Womble, "Great Uncle Bulgaria is a womble";
isa-ok $womble, 'Womble';     # equivalent

Note that, unlike isa, isa-ok also matches Roles:

say 42.isa(Numeric); # OUTPUT: «False␤»
isa-ok 42, Numeric;  # OUTPUT: «ok 1 - The object is-a 'Numeric'␤»