On Sat, 26 Aug 2000, James Mastros wrote:
> This example shows how much easier it would have been to write the
> example on line 170 of perltoot.pod:
>
> package Person;
> use strict;
>
> ##################################################
> ## the object constructor (simplistic version) ##
> ##################################################
> sub new {
> my $self = {};
> $self->{name} :accessible('rw') = undef;
> $self->{age} :accessible('rw') = undef;
> $self->{peers}:accessible('rw') = [];
> bless($self); # but see below
> return $self;
> }
This is an interesting idea. I would think that ideally it would be
combined with pre-declared limited keyspace hashes (which we currently
have in a semi-crippled way with pseudohashes). I'd much prefer that
these declarations happen outside the contructor, more like this maybe.
Also I really dislike 'rw' and such. Let's be a little clearer:
And this way we could drop the whole :accessible thing. How about this:
use fields qw(
name :read :write
age :read :write
peers :read :write
birth_date :read
);
Of course, what I think I really want is the ability to do a sort of
auto-tie so that instead of Perl generating accessors, it ties my
attributes directly to my own accessor function. That could be
incorporated into this syntax perhaps? Mayb as:
use fields qw(
name :read => \&name :write => \&name
age :read => \&get_age :write => \&set_age
);
Just some thoughts.
-dave
/*==================
www.urth.org
We await the New Sun
==================*/