Skip to content

Commit 5be43cf

Browse files
committed
Document "has" (sortof) and "anon" declarators
1 parent 12ec453 commit 5be43cf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/Language/variables.pod

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,27 @@ introduce an alias into the symbol table.
417417
418418
=head2 The C<has> Declarator
419419
420+
C<has> scopes attributes to instances of a class or role, and methods to
421+
classes or roles. C<has> is implied for methods, so C<has method x() {}>
422+
and C<method x() {}> do the same thing.
423+
424+
See L<object orientation|/language/objects> for more documentation and some
425+
examples.
426+
420427
=head2 The C<anon> Declarator
421428
422-
=comment TODO
429+
The C<anon> declarator prevents a symbol from getting installed in the lexical
430+
scope, the method table and everywhere else.
431+
432+
For example you can use it to declare subroutines which know their own name,
433+
but still aren't installed in a scope:
434+
435+
my %operations =
436+
half => anon sub half($x) { $x / 2 },
437+
square => anon sub square($x) { $x * $x },
438+
;
439+
say %operations<square>.name; # square
440+
say %operations<square>(8); # 64
423441
424442
=head2 The C<state> Declarator
425443

0 commit comments

Comments
 (0)