in reply to Re: $foo->bar = 14;
in thread $foo->bar = 14;
One problem with the approach you set forth is that it doesn't survive subclassing.
Eh?
use strict; use warnings; { package Foo; sub new { bless {}, shift }; BEGIN { no strict 'refs'; for my $property (qw/foo bar/) { *$property = sub : lvalue { $_[0]->{$property} }; } } } { package Bar; use base qw(Foo); BEGIN { no strict 'refs'; for my $property (qw/fribble ni/) { *$property = sub : lvalue { $_[0]->{$property} }; } } }; my $o = Bar->new; $o->foo=1; $o->bar=2; $o->fribble=3; $o->ni=4; print join(', ', $o->foo, $o->bar, $o->fribble, $o->ni), "\n"; # produces # 1, 2, 3, 4
or am I missing something?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re^2: $foo->bar = 14;
by dws (Chancellor) on Dec 30, 2002 at 18:52 UTC | |
by adrianh (Chancellor) on Dec 30, 2002 at 20:53 UTC |
In Section
Meditations