in reply to Re^2: Can you override lexically scoped variables when sub-classing a module.
in thread Can you override lexically scoped variables when sub-classing a module.
Well if you can change the 'my' to 'our' in p1 then this works
Package 1
package p1; our $var1 = 'var1-p1';#Note the change my->our sub new { my $class = ref $_[0] ? ref shift : shift; my $self = {}; bless $self, $class; return $self; } sub get_var1 { return $var1; } 1;
Package 2
package p2; use p1; our @ISA=qw(p1); sub set_var1 { my $self = shift; my $new_var1 = shift; $p1::var1 = $new_var1; return $p1::var1; } 1;
You get a global variable that you may not want
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Can you override lexically scoped variables when sub-classing a module.
by Anonymous Monk on Oct 11, 2012 at 20:45 UTC |