develooper Front page | perl.perl6.language | Postings from June 2006

[svn:perl6-synopsis] r9462 - doc/trunk/design/syn

From:
larry
Date:
June 3, 2006 19:14
Subject:
[svn:perl6-synopsis] r9462 - doc/trunk/design/syn
Message ID:
20060604021311.6C93DCBA47@x12.develooper.com
Author: larry
Date: Sat Jun  3 19:13:10 2006
New Revision: 9462

Modified:
   doc/trunk/design/syn/S12.pod

Log:
Clarified scoping of "has $x" and friends.


Modified: doc/trunk/design/syn/S12.pod
==============================================================================
--- doc/trunk/design/syn/S12.pod	(original)
+++ doc/trunk/design/syn/S12.pod	Sat Jun  3 19:13:10 2006
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall <larry@wall.org>
   Date: 27 Oct 2004
-  Last Modified: 8 May 2006
+  Last Modified: 3 Jun 2006
   Number: 12
-  Version: 15
+  Version: 16
 
 =head1 Overview
 
@@ -360,14 +360,26 @@
 Public attributes have a secondary sigil of "dot", indicating
 the automatic generation of an accessor method of the same name.
 Private attributes use an exclamation to indicate that no public accessor is
-generated.  The exclamation is optional, so these are identical in effect:
+generated.
 
         has $!brain;
-        has $brain;
 
-And any later references to the private variable may either use or
-omit the exclamation, as you wish to emphasize or ignore the privacy
-of the variable.
+The "true name" of the private variable always has the exclamation, but
+much like with C<our> variables, you may declare a lexically scoped alias
+to the private variable by saying:
+
+        has $brain;	# also declares $!brain;
+
+And any later references to the private variable within the same block
+may either use or omit the exclamation, as you wish to emphasize or
+ignore the privacy of the variable.  Outside the block, you must use
+the C<!> form.  If you declare with the C<!> form, you must use that
+form consistently everywhere.  If you declare with the C<.> form, you
+also get the private C<!> form as a non-virtual name for the actual
+storage location, and you may use either C<!> or C<.> form anywhere
+within the class, even if the class is reopened.  Outside the class
+you must use the public C<.> form, or rely on a method call (which
+can be a private method call, but only for trusted classes).
 
 For public attributes, some traits are copied to the accessor method.
 The C<rw> trait causes the generated accessor to be declared C<rw>,



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About