in reply to Re^2: RFC: The Poor Man's Accessor Filter
in thread RFC: The Poor Man's Accessor Filter

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' );

Replies are listed 'Best First'.
Re^4: RFC: The Poor Man's Accessor Filter
by rje (Deacon) on Oct 08, 2008 at 18:59 UTC
    Ummm, I like that quite a bit. So my new code would look like this:
    package Games::Traveller::Sophont; { use Class::BuildMethods qw/ name longname homeworld star orbit status niche ... etc ... /; sub new { bless {}, shift } ... etc ... } 1; package My::Purple::Blovinator; my $foo = new Games::Traveller::Sophont; $foo->name( "Chamaxi" ); ... etc ...
    Yeah... yeah, I think I like that a lot.