On Sun, 17 Sep 2000, Perl6 RFC Librarian 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} :laccess :raccess = undef;
> $self->{age} :laccess :raccess = undef;
> $self->{peers} :laccess :raccess = [];
> return bless $self;
> }
Would these attributes carry if you copied the whole array? For that matter,
can you even copy an object an automagically copy the blessing as well?
Urgh. I don't know enough about perl to know if this is doable, or even
desireable. But something like this might be nice:
package Person;
use strict;
# Construct an archtype to make copies of when
# new is invoked
my $archtype = {};
$archtype->{name} :laccess :raccess = undef;
$archtype>{age} :laccess :raccess = undef;
$archtype->{peers} :laccess :raccess = [];
bless $archtype;
##################################################
## the object constructor (simplistic version) ##
##################################################
sub new {
return copy_of($archtype);
}
Hmmm. If this is desireable, but not doable, I suppose it would take another
RFC.