in reply to Accessing class/subclass variables
Solution: use constant NAME => 'vB'; Then, you say $class->NAME or $obj->NAME and you'll get the right one.
Solution: You need a place for class data and a method of accessing it. The simplest way would be something like:
The only drawback is that you have to cut'n'paste this code in every class. Furthermore, you have to pre-seed the items in the %data hash. But, it may be sufficient and it is really simple.{ my %data = ( name => 'vB', ); sub access_class_data { my $class = shift; my ($name, $val) = @_; return $class->SUPER::access_class_data( @_ ) unless exists $data{ $name }; if ( @_ > 1 ) { $data{ $name } = $val; } return $data{ $name }; } }
Solution: Put it in the instance.
My money is on the constant. That's 90% of all class variable usage.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Accessing class/subclass variables
by nmerriweather (Friar) on Mar 25, 2006 at 08:46 UTC |