On Wed, 24 Sep 2003, Todd W. wrote:

> I have a question/request concerning perl6 object properties.
> 
> I've done some work with .NET and They have come up with a really slick way
> to handle object properties.
> 
> A typical property definition in VB.NET looks like:
> 
> Public Property description() As String
>   Get
>     return aString
>   End Get
>   Set(ByVal Value As String)
>     ' set value
>   End Set
> End Property
> 
> You can use it like this:
> 
> oObj.description = sDescr ' calls setter
> sDescr = oObj.description ' calls getter

Perl 6 will do something similar. Attributes (aka slot variables, aka 
properties, aka "those thingies in the object") will, if you tell perl, 
automatically get an lvalue method of the same name created for them. So 
if you have a class that looks like (Excuse the syntax, I'm an internals 
guy):

  class Foo {
    my $.attr1 is rw;
  }

and an object of class Foo:

  my Foo $bar;

then you can read and write that attribute with code like:

  $bar.attr1 = "fooey";
  print $bar.attr1, " to you!";

This has the nice property of allowing you to override the access to the 
attribute if you want by defining an lvalue method with the same name as 
the attribute, in which case that method will be called instead.

                                Dan

Reply via email to