Todd W. writes:
> I have a question/request concerning perl6 object properties.
Rather, attributes. Properties are out-of-band data attached to a
particular object.
> 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
>
> This allows proper encapsulation of object properties while providing a very
> clean interface. A corollary feature is that properties can map to arbitrary
> values. I've written object property definitions that read and write
> directly to relational databases, and Ive written read only properties that
> abstract XPath queries to config files.
>
> My main interest in the feature is using the assignment operator to assign
> to object properties.
Okay, this has been thought through. It's the way lvalue subs are going
to be pulled off in the more complex cases.
I can't remember the exact syntax, but it goes something like:
sub assign_to_me() is rw {
my $ret is class { STORE { print "I was assigned to!\n" } }
}
(Note that ret is both being created and returned in the same
expression)
Admittedly, that's a bit of a kludge, so there may be some syntax to
sugar it up. I'd suggest an omitted C<do> property, with two additional
properties: C<fetch> and C<store>.
sub assign_to_me() is rw
will fetch { print "I was read from!\n" }
will store { print "I was assigned to!\n" }
{...}
Not to worry, as this is a nice thing to be able to do, it will be easy.
Luke
> I posted a question to CLPM on how to do this with perl5 and we decided to
> use an 'lvalue' attribute on the subroutine and then make the returned
> lvalue in the sub a tied variable to intercept read/writes:
>
> http://groups.google.com/groups?th=5489106ee6715c8e
>
> It works, but its obviously slow and can get confusing for anything
> moderately complex.
>
> I just thought I would share this and see if anything similar can fit in the
> perl6 OO syntax.
>
> Todd W.