Metarole for documenting types.
Warning: this role is part of the Rakudo implementation, and is not a part of the language specification.
Type declarations may include declarator blocks (#|
and #=
), which allow you to set the type's documentation. This can then be accessed through the WHY
method on objects of that type:
say Documented.WHY;# OUTPUT:# Documented is an example class for Metamodel::Documenting's documentation.# Take a look at my WHY!
Metamodel::Documenting
is what implements this behavior for types. This example can be rewritten to use its methods explicitly like so:
BEGINsay Documented.HOW.WHY;# OUTPUT:# Documented is an example class for Metamodel::Documenting's documentation.# Take a look at my WHY!
It typically isn't necessary to handle documentation for types directly through their HOW like this, as Metamodel::Documenting
's methods are exposed through Mu via its WHY
and set_why
methods, which are usable on types in most cases.
method set_why()
Sets the documentation for a type to $why
.
method WHY()
Returns the documentation for a type.