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.
In reply to Re: Acessing an object's variable
by Perl Mouse
in thread Acessing an object's variable
by gmantz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |