role Metamodel::Stashing

Metarole for type stashes
role Metamodel::Stashing { }

Warning: this role is part of the Rakudo implementation, and is not a part of the language specification.

Types may have a stash associated with them, which is a named hash containing our-scoped symbols for that type's package. When this is the case, they can be used like namespaces; you can get their stash using their WHO property or with the :: dispatch operator:

module Nested {
    module Namespace {
        constant Symbol = $?MODULE;
    }
}

say Nested::Namespace::Symbol;         # OUTPUT: «(Namespace)␤»
say Nested.WHO<Namespace>.WHO<Symbol>; # OUTPUT: «(Namespace)␤»

Metamodel::Stashing is the metarole that handles creating and setting a stash object for types. Types used with this metarole are expected to support naming, so when writing custom HOWs that do it, ensure they also do Metamodel::Naming.

Methods

method add_stash

method add_stash($type_obj)

Creates and sets a stash for a type, returning $type_obj.

This method is typically called as the last step of creating a new type. For example, this is how it would be used in a minimal HOW that only supports naming and stashing:

class WithStashHOW
    does Metamodel::Naming
    does Metamodel::Stashing
{
    method new_type(WithStashHOW:_: Str:D :$name! --> Mu) {
        my WithStashHOW:D $meta := self.new;
        my Mu             $type := Metamodel::Primitives.create_type: $meta, 'Uninstantiable';
        $meta.set_name: $type, $name;
        self.add_stash: $type
    }
}

my Mu constant WithStash = WithStashHOW.new_type: :name<WithStash>;
say WithStash.WHO; # OUTPUT: «WithStash␤»

See Also

role Metamodel::AttributeContainer

Metaobject that can hold attributes

role Metamodel::C3MRO

Metaobject that supports the C3 method resolution order

role Metamodel::Documenting

Metarole for documenting types.

role Metamodel::Finalization

Metaobject supporting object finalization

role Metamodel::MethodContainer

Metaobject that supports storing and introspecting methods

role Metamodel::Mixins

Metaobject for generating mixins

role Metamodel::MROBasedMethodDispatch

Metaobject that supports resolving inherited methods

role Metamodel::MultipleInheritance

Metaobject that supports multiple inheritance

role Metamodel::Naming

Metaobject that supports named types

role Metamodel::ParametricRoleGroupHOW

Represents a group of roles with different parameterizations

role Metamodel::ParametricRoleHOW

Represents a non-instantiated, parameterized, role.

role Metamodel::PrivateMethodContainer

Metaobject that supports private methods

role Metamodel::RoleContainer

Metaobject that supports holding/containing roles

role Metamodel::RolePunning

Metaobject that supports punning of roles.

role Metamodel::Trusting

Metaobject that supports trust relations between types

role Metamodel::Versioning

Metaobjects that support versioning

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.