Permalink
Browse files

[variables] document the . twigil

  • Loading branch information...
1 parent ab2d5be commit 65a3a7282b4cd6a051a88679f789110e589dc304 @felher felher committed Aug 29, 2012
Showing with 32 additions and 0 deletions.
  1. +32 −0 lib/variables.pod
View
@@ -137,6 +137,38 @@ such constants.
For a list of those special variables see L<Compile-time "constants">.
+=head2 .
+
+The C<.> twigil isn't really for variables at all. In fact, something along the
+lines of
+
+ class Point {
+ has $.x;
+ has $.y;
+
+ method Str() {
+ "($.x, $.y)" # note that we use the . instead of ! this time
+ }
+ }
+
+just calls the methods C<x> and C<y> on C<self>, which are automatically
+generated for you because you used the C<.> twigil as you declared your
+attributes. Note, however, that subclasses may override those methods. If you
+don't want this to happen, use C<$!x> and C<$!y> instead.
+
+The fact that the C<.> twigil just does a method call also implies that the
+following is possible too.
+
+ class SaySomething {
+ method a() { say "a"; }
+ method b() { $.a; }
+ }
+
+ SaySomething.a; # prints "a"
+
+For more details on objects, classes and their attributes and methods see
+L<objects>.
+
=head1 Special Variables
=head2 Often-Used Variables

0 comments on commit 65a3a72

Please sign in to comment.