Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Some initial documentation for type Stash
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| =begin pod | ||
| =TITLE class Stash | ||
| =SUBTITLE Tables for "our"-scoped symbols | ||
| class Stash is Hash { } | ||
| A C<Stash> is a hash that is used for symbol tables at the package scoped in | ||
| Perl 6. | ||
| To get a Stash, you can all the C<.WHO> pseudo method on a package (because it | ||
| answers the question I<who lives here?>), or if you write the package name as | ||
| a literal, append two colons: | ||
| class Boring { | ||
| class Nested { }; | ||
| our sub package_sub { } | ||
| my sub lexical { }; | ||
| method a_method() { } | ||
| } | ||
| say Boring::.^name; # Stash | ||
| say Boring.WHO === Boring::; # True | ||
| Since it inherits from L<Hash|/type/Hash>, you can use all the usual hash | ||
| functionality: | ||
| say Boring::.keys.sort; # &package_sub Nested | ||
| say Boring::<Nested>; # (Nested) | ||
| As the example above shows, lexicals and methods are not included in a Stash, | ||
| since they do not live in the package table. (Methods have a separate method | ||
| table, and are accessible through method calls or C<.can> and C<.^methods>, | ||
| and lexicals live in a separate lexical pad, which is only from inside the | ||
| scope). | ||
| =end pod |