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␤» 

Type Graph

Type relations for Metamodel::Stashing
perl6-type-graph Metamodel::Stashing Metamodel::Stashing Mu Mu Any Any Any->Mu Metamodel::Naming Metamodel::Naming Metamodel::Documenting Metamodel::Documenting Metamodel::Versioning Metamodel::Versioning Metamodel::MethodContainer Metamodel::MethodContainer Metamodel::PrivateMethodContainer Metamodel::PrivateMethodContainer Metamodel::MultiMethodContainer Metamodel::MultiMethodContainer Metamodel::AttributeContainer Metamodel::AttributeContainer Metamodel::RoleContainer Metamodel::RoleContainer Metamodel::MultipleInheritance Metamodel::MultipleInheritance Metamodel::TypePretense Metamodel::TypePretense Metamodel::RolePunning Metamodel::RolePunning Metamodel::ParametricRoleHOW Metamodel::ParametricRoleHOW Metamodel::ParametricRoleHOW->Metamodel::Stashing Metamodel::ParametricRoleHOW->Any Metamodel::ParametricRoleHOW->Metamodel::Naming Metamodel::ParametricRoleHOW->Metamodel::Documenting Metamodel::ParametricRoleHOW->Metamodel::Versioning Metamodel::ParametricRoleHOW->Metamodel::MethodContainer Metamodel::ParametricRoleHOW->Metamodel::PrivateMethodContainer Metamodel::ParametricRoleHOW->Metamodel::MultiMethodContainer Metamodel::ParametricRoleHOW->Metamodel::AttributeContainer Metamodel::ParametricRoleHOW->Metamodel::RoleContainer Metamodel::ParametricRoleHOW->Metamodel::MultipleInheritance Metamodel::ParametricRoleHOW->Metamodel::TypePretense Metamodel::ParametricRoleHOW->Metamodel::RolePunning Metamodel::MethodDelegation Metamodel::MethodDelegation Metamodel::ModuleHOW Metamodel::ModuleHOW Metamodel::ModuleHOW->Metamodel::Stashing Metamodel::ModuleHOW->Any Metamodel::ModuleHOW->Metamodel::Naming Metamodel::ModuleHOW->Metamodel::Documenting Metamodel::ModuleHOW->Metamodel::Versioning Metamodel::ModuleHOW->Metamodel::TypePretense Metamodel::ModuleHOW->Metamodel::MethodDelegation Metamodel::BaseType Metamodel::BaseType Metamodel::MROBasedMethodDispatch Metamodel::MROBasedMethodDispatch Metamodel::MROBasedTypeChecking Metamodel::MROBasedTypeChecking Metamodel::BUILDPLAN Metamodel::BUILDPLAN Metamodel::BoolificationProtocol Metamodel::BoolificationProtocol Metamodel::EnumHOW Metamodel::EnumHOW Metamodel::EnumHOW->Metamodel::Stashing Metamodel::EnumHOW->Any Metamodel::EnumHOW->Metamodel::Naming Metamodel::EnumHOW->Metamodel::MethodContainer Metamodel::EnumHOW->Metamodel::MultiMethodContainer Metamodel::EnumHOW->Metamodel::AttributeContainer Metamodel::EnumHOW->Metamodel::RoleContainer Metamodel::EnumHOW->Metamodel::BaseType Metamodel::EnumHOW->Metamodel::MROBasedMethodDispatch Metamodel::EnumHOW->Metamodel::MROBasedTypeChecking Metamodel::EnumHOW->Metamodel::BUILDPLAN Metamodel::EnumHOW->Metamodel::BoolificationProtocol Metamodel::PackageHOW Metamodel::PackageHOW Metamodel::PackageHOW->Metamodel::Stashing Metamodel::PackageHOW->Any Metamodel::PackageHOW->Metamodel::Naming Metamodel::PackageHOW->Metamodel::Documenting Metamodel::PackageHOW->Metamodel::TypePretense Metamodel::PackageHOW->Metamodel::MethodDelegation Metamodel::Finalization Metamodel::Finalization Metamodel::DefaultParent Metamodel::DefaultParent Metamodel::C3MRO Metamodel::C3MRO Metamodel::Trusting Metamodel::Trusting Metamodel::Mixins Metamodel::Mixins Metamodel::ClassHOW Metamodel::ClassHOW Metamodel::ClassHOW->Metamodel::Stashing Metamodel::ClassHOW->Any Metamodel::ClassHOW->Metamodel::Naming Metamodel::ClassHOW->Metamodel::Documenting Metamodel::ClassHOW->Metamodel::Versioning Metamodel::ClassHOW->Metamodel::MethodContainer Metamodel::ClassHOW->Metamodel::PrivateMethodContainer Metamodel::ClassHOW->Metamodel::MultiMethodContainer Metamodel::ClassHOW->Metamodel::AttributeContainer Metamodel::ClassHOW->Metamodel::RoleContainer Metamodel::ClassHOW->Metamodel::MultipleInheritance Metamodel::ClassHOW->Metamodel::MROBasedMethodDispatch Metamodel::ClassHOW->Metamodel::MROBasedTypeChecking Metamodel::ClassHOW->Metamodel::BUILDPLAN Metamodel::ClassHOW->Metamodel::BoolificationProtocol Metamodel::ClassHOW->Metamodel::Finalization Metamodel::ClassHOW->Metamodel::DefaultParent Metamodel::ClassHOW->Metamodel::C3MRO Metamodel::ClassHOW->Metamodel::Trusting Metamodel::ClassHOW->Metamodel::Mixins Metamodel::NativeHOW Metamodel::NativeHOW Metamodel::NativeHOW->Metamodel::Stashing Metamodel::NativeHOW->Any Metamodel::NativeHOW->Metamodel::Naming Metamodel::NativeHOW->Metamodel::Documenting Metamodel::NativeHOW->Metamodel::Versioning Metamodel::NativeHOW->Metamodel::MultipleInheritance Metamodel::NativeHOW->Metamodel::MROBasedMethodDispatch Metamodel::NativeHOW->Metamodel::MROBasedTypeChecking Metamodel::NativeHOW->Metamodel::C3MRO Metamodel::ParametricRoleGroupHOW Metamodel::ParametricRoleGroupHOW Metamodel::ParametricRoleGroupHOW->Metamodel::Stashing Metamodel::ParametricRoleGroupHOW->Any Metamodel::ParametricRoleGroupHOW->Metamodel::Naming Metamodel::ParametricRoleGroupHOW->Metamodel::TypePretense Metamodel::ParametricRoleGroupHOW->Metamodel::RolePunning Metamodel::ParametricRoleGroupHOW->Metamodel::BoolificationProtocol

Expand above chart