class RakuAST::Type::Enum { }

The RakuAST::Type::Enum class represents an enum specification.

Object introspection§

RakuAST::Type::Enum object is typically created when parsing Raku Programming Language code. So most developers will only need to know how to introspect the objects created.

name§

say $enum.name;  # RakuAST::Name.from-identifier("Foo")

Returns the L<RakuAST::Name>|/type/RakuAST::Name object of this RakuAST::Type::Enum object.

of§

say $enum.of;  # RakuAST::Type::Simple.from-identifier("Int")

Returns the RakuAST::Type object of this RakuAST::Type::Enum to which the enum values are constrained.

scope§

say $enum.scope;  # my

Returns the scope of the RakuAST::Type::Enum object as a string. Usually "our", but can also be "my" or "anon".

term§

dd $enum.term;  # <a b c>

Returns the RakuAST::Expression object that represents the names and values of this enum.

traits§

dd $enum.traits.head;  # of Str

Returns a (possibly empty) list of RakuAST::Trait object that were applied to the enum.

Object creation§

There is only one way to create a RakuAST::Type::Enum object.

new§

my $enum = RakuAST::Type::Enum.new(
  scope  => "my",
  name   => RakuAST::Name.from-identifier("Foo"),
  of     => RakuAST::Type::Simple.from-identifier("Int"),
  traits => (
    RakuAST::Trait::Of.new(
      RakuAST::Type::Simple.from-identifier("Str")
    ),
  ),
  term   => RakuAST::QuotedString.new(
    processors => <words val>,
    segments   => (
      RakuAST::StrLiteral.new("a b c"),
    )
  )
);
dd $enum;  # my Int enum Foo <a b c>

Creates a RakuAST::Type::Enum object from the given named arguments.

  • scope - string indicating scope (my/our/anon), default: "our"

  • name - RakuAST::Name object with the name of the enum, default: ""

  • term - RakuAST::Expression with listing of keys/values (required)

  • traits - List of RakuAST::Trait objects, default: none

  • of - RakuAST::Type object constraining values, default: none