Wise ones...
I have been playing with ideas I have read in relation to InsideOut - hiding object data inside of a lexical block within a class. I have been trying to bind the data even more tightly to the methods. However, since DESTROY() needs to be called for proper housekeeping, I am finding it difficult to accomplish.
I have searched the tomes here, but have not been successful in finding what I am looking for. Feel free to point out where I have missed :)
I know that this is not complete - I mean look at the names of the variable ;). Bugs with data checks aside... (thanks diotalevi ;)
use strict; use warnings; package testhiding; sub new { bless [], shift; } { my %foo = (); my %bar = (); sub foo { my $self = shift; my $new = shift; my $old = $foo{$self}; $foo{$self} = $new if defined($new); $old; } sub bar { my $self = shift; my $new = shift; my $old = $bar{$self}; $bar{$self} = $new if defined($new); $old; } sub DESTROY { my $self = shift; delete $_->{$self} for (\%foo, \%bar); } } 1;
use strict; use warnings; package testhiding; sub new { bless [], shift; } { my %foo = (); sub foo { my $self = shift; my $new = shift; my $old = $foo{$self}; $foo{$self} = $new if defined($new); $old; } } { my %bar = (); sub bar { my $self = shift; my $new = shift; my $old = $bar{$self}; $bar{$self} = $new if defined($new); $old; } } # XXX - Where does this go then... sub DESTROY { my $self = shift; delete $_->{$self} for (\%foo, \%bar); } 1;
I know why DESTROY does not work, that is not the problem. I would like to make DESTROY work somehow. The structure to allow that while also allowing the tighter coupling of the data to the methods is where I am getting stuck.
Any ideas?
Update: Lack of data checking and bugs in the code acked. Since that isn't the intent of the question, take all code as a sample, not as should be written, etc. :)In reply to InsideOut - even tighter coupling by MidLifeXis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |