in reply to Re^6: Perl OO and accessors
in thread Perl OO and accessors
The same goes for lvalue+tie. As I said in another post there's Class::Accessor::Lvalue. Personally I use my own home brew module which lets me say
package Circle; use Fergal::MM qw( Radius Area ); # this creates # setRadius, getRadius, Radius # setArea, getArea, Area # # All are created in Circle::Accessors and Circle's @ISA # is updated to include Circle::Accessors. # This makes overriding easy. # now override the Area ones sub setArea { my ($self, $area) = @_; $self->Radius = sqrt($area/PI); } sub getArea { my ($self, $area) = @_; my $r = $self->Radius; return PI * $r * $r; }
This removes all but one of Ovid's complaints - it's probably slow but if you really need speed then you can just ignore the lvalue interface and use the set/get methods directly. I think I benchmarked it as a factor of 10 slower but how much of your code is accessor calls? If you really need speed, Perl OO is probably not what you want.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Perl OO and accessors
by sauoq (Abbot) on Nov 29, 2005 at 13:48 UTC | |
by fergal (Chaplain) on Nov 29, 2005 at 16:04 UTC | |
by herveus (Prior) on Nov 29, 2005 at 22:33 UTC | |
by fergal (Chaplain) on Nov 30, 2005 at 00:17 UTC | |
by herveus (Prior) on Nov 30, 2005 at 15:30 UTC | |
| |
by sauoq (Abbot) on Nov 29, 2005 at 22:13 UTC | |
by dragonchild (Archbishop) on Nov 29, 2005 at 22:34 UTC | |
by sauoq (Abbot) on Nov 30, 2005 at 02:55 UTC |