There is also ovid's Class::BuildMethods which does not care how you implement your objects (but can work with the inside out kind), e.g.
package Soldier;
use strict;
use Class::BuildMethods
'name',
rank => { default => 'private' };
sub new {
my $class = shift;
return bless [] => $class;
}
package main;
use warnings;
use Data::Dumper;
my $foo = Soldier->new;
$foo->name('John');
$foo->rank('Major');
printf "name: %s, rank: %s\n", $foo->name, $foo->rank;
print Dumper($foo) . "\n";
output:
name: John, rank: Major
$VAR1 = bless( [], 'Soldier' );
|