in reply to Seeking inside-out object implementations
You can look at my Class::BuildMethods. It's extremely lightweight. The nice thing about it is you can slowly convert your objects to inside-out objects regardless of the implementation you currently use. This gives you a migration path.
use Data::UUID; use Class::BuildMethods 'name', rank => { default => 'private' }, age => { validate => sub { my ($self, $age) = @_; die "Must be 18 or over" unless $age >= 18; }, }, id => { default => Data::UUID->new->get_str, validate => sub { die "id() is readonly" } }; sub new { bless [], shift } sub foo { my $self = shift; return $self->[0] unless @_; # lots of horribly complicated code $self->[0] = shift; return $self; }
In the above example, you have a blessed array reference, but it can be a blessed typeglob, hashref, whatever. You can also add your own methods which are independent of the inside-out attributes that BuildMethods defines. This allows you to take an existing class and gradually encapsulate methods one at a time.
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Seeking inside-out object implementations
by xdg (Monsignor) on Dec 06, 2005 at 23:07 UTC | |
by Ovid (Cardinal) on Dec 06, 2005 at 23:57 UTC |