Class::Data::Accessor

jk2addict on 2005-11-28T02:51:45

Over the last view days of converting Handel from CDBI from DBIC, I took another look at Class::Accessor and Class::Data::Inheritable. One of the things I found myself wanting was something that did both the inheritable class data and supported instance data using the same accessor.

Well, as it turns out, Matt Trout had such a thing sitting in the repo. After some pod tweaking and slight dist preparation, Class::Data::Accessor 0.01 is coming to a CPAN mirror nearest you.

Its usage is roughly:

package Base;
use base qw/Class::Data:Accessor/;
__PACKAGE__->mk_classaccessor('AutoCommit' => 1);

print Base->AutoCommit; # prints 1



package BetterBase; use base qw/Base/; print BetterBase->AutoCommit; #prints 1

__PACKAGE__->AutoCommit(0); print BetterBase->AutoCommit; #prints 0 print Base->AutoCommit; # prints 1



my $base = BetterBase->yournew(); print $base->AutoCommit; # prints 1

$base->AutoCommit(1); print $base->AutoCommit; # prints 1