Course of Raku / Advanced / Introspection with MOP


VAR is a pseudo-method that retuns the underlying container object. The .VAR call returns a Scalar object of the container.


After calling .VAR, you can further get the name of its class by calling .^name on it.

Examine the following program:

my $var1 = 42;
my $var2 = '42';

say $var1.^name;     # Int
say $var1.VAR.^name; # Scalar

say $var2.^name;     # Str
say $var2.VAR.^name; # Scalar

Here, two variables are filled with an integer and a string. The .^name meta-object method returns the name of the type, which is correspondently Int or Str.


The default method returns the default value of the variable.

my Str $language is default('Raku');
say $language.VAR.default; # Raku

If the default value is not defined explicitly, you see the name of the class of the value kept in the container:

my $language = 'Raku';
say $language.VAR.default; # (Str)

Or its type constraint:

my Str $language;
say $language.VAR.default; # (Str)


The name method returns the name of the container, including the sigil.

my $language;
say $; # $language

Make sure to not mix ^name and name.

Course navigation

Introspection with MOP / WHAT and ^name   |