Let's say I have a class with some attributes:

    class Dog;

    has $.name is rw;
    has $.age is rw;
    has $.gender is rw;

I initially decide to accept the default accessors.

    $dog.name = 'Ralph';
    print $dog.age;

This works well for a while, but then I decide to update Dog so that setting
the name also sets the gender.

    $dog.name = 'Susie'; # also sets $dog.gender to 'female'

How do I write such a name() method?  Do I just check the arg, set the
gender, and then return $.name as an "lvalue" or something?

If so, what happens if, some time down the road, the $.name attribute goes
away entirely?  I can't return it as an lvalue now, can I?

Basically, I'm wondering how much of the object's internals I'm exposing by
accepting the default accessors.

-John

Reply via email to