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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|