in reply to Acessing an object's variable
To make object level variables, you need to use the reference (the object itself) in some way. Traditional is it to stuff the attribute (the object variable) inside the reference, but that's considered bad by some programmers (including myself).
A technique would be to use inside-out objects:
This prevents directly accessing the object variables - and that's considered a good thing.package LaLa; use strict; use warnings; use Scalar::Util 'refaddr'; my %name; sub newlala { # No point in using prototypes for methods. my $class = shift; return bless \do {my $var}, $class; # Always use two-arg bless } sub setname { my $self = shift; $name{refaddr $self} = shift; } sub getname { my $self = shift; return $name{refaddr $self} } sub DESTROY { my $self = shift; delete $name{refaddr $self} } 1;
You could do that with tradional OO programming. No doubt someone else will show you the dark way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Acessing an object's variable
by gmantz (Initiate) on Dec 13, 2005 at 11:00 UTC | |
by Perl Mouse (Chaplain) on Dec 13, 2005 at 11:49 UTC | |
by JohnMG (Beadle) on Dec 13, 2005 at 17:00 UTC | |
by Perl Mouse (Chaplain) on Dec 13, 2005 at 22:04 UTC |