in reply to Re^2: Subroutines with differing behaviour created from AUTOLOAD
in thread Subroutines with differing behaviour created from AUTOLOAD
Untested is right. That method will DEFINITELY work with more than one object in the class. I should know - I use it in production. You are NOT "injecting"(?) closures over the current $self. Test it before you make pronouncements like that.
With the original poster's code, this test:
gives me:my $test = Foo->new(); my $test2 = Foo->new(); $test->read_write("water"); $test2->read_write("wine"); print "test: should be water, is ", $test->read_write, "\n"; print "test2: should be wine, is ", $test2->read_write, "\n";
test: should be water, is wine test2: should be wine, is wine
I'm confused as to what you're saying will definitely work - the OP's code has an AUTOLOAD sub which defines a lexical $self, in which he defines a couple of anonymous subs which refer to that $self. Nothing that can't be fixed by adding a my $self into the subs, as I did in my code and as you've done in yours.
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Subroutines with differing behaviour created from AUTOLOAD
by davis (Vicar) on Jun 08, 2004 at 16:20 UTC | |
|
Re^4: Subroutines with differing behaviour created from AUTOLOAD
by dragonchild (Archbishop) on Jun 08, 2004 at 16:56 UTC |