in reply to Re: inside-out objects using arrays?
in thread inside-out objects using arrays?
I was thinking the following, which would lead to undef array elements once $obj->DESTROY gets called. Still, I like it ;-)
package Outside::In; use strict; use warnings; { my $obj_counter = 0; my @name; sub new { my $class = shift; my $instance_index = $obj_counter; my $self = sub { return $instance_index }; bless $self, $class; $obj_counter++; return $self; } sub name { my $self = shift; $name[$self->()] = shift if @_; return $name[$self->()]; } sub DESTROY { my $self = shift; delete $name[$self->()]; } } package main; my $obj1 = Outside::In->new; my $obj2 = Outside::In->new; $obj1->name('Bob'); $obj2->name('Fred'); print $obj1->name, "\n", $obj2->name, "\n"; print $obj1->();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: inside-out objects using arrays?
by adrianh (Chancellor) on Sep 18, 2005 at 00:37 UTC | |
by fishbot_v2 (Chaplain) on Sep 18, 2005 at 00:56 UTC | |
by chromatic (Archbishop) on Sep 18, 2005 at 02:20 UTC | |
by rvosa (Curate) on Sep 18, 2005 at 12:23 UTC | |
by ikegami (Patriarch) on Sep 18, 2005 at 02:52 UTC | |
by rvosa (Curate) on Sep 18, 2005 at 01:31 UTC |
In Section
Seekers of Perl Wisdom