Oops. Sent privately instead of to the list. Resending. --- "nntp.perl.org" <[EMAIL PROTECTED]> wrote: > I've written a module to deal with the issue of inheritable class > data (yes, yet another one). > What's peculiar with it is that it doesn't rely on accessor methods. > After declaration, you can use the variables just like any other > package > variable but you can inherit and override those variables in other > packages/classes.
Hi Giacamo, Hey, this idea sounds very cool, but unfortunately, it's a bad idea (conceptually similar to Java's mistake of allowing public properties). Here's an example, using some pseudo-code which assumes that Universe exports class data named '$pi': use Universe ($pi); my $universe = Universe->new('standard'); print $pi; # 3.14 ... $pi = -13; # What? print $pi; # -13 The problem with public properties instead of methods is that you cannot easily validate them at the time of setting the value. Sure, you can tie the variable, but why go through all of that work for a single value? Just make a setter/getter and you can validate it. Admittedly, Class::Data::Inheritable doesn't validate it, but you can do this: use base 'Class::Data::Inheritable'; __PACKAGE__->mk_classdata( _pi => 3.14 ); sub pi { my $self = shift; return $self->_pi unless @_; my $pi = shift; # make sure $pi is a valid number or die, die, die $self->_pi($pi); return $self; } Now you get nice safety and don't have to worry about things. Later, if you find your universe needs to calculate the value of pi (presumably by making an RPC call to another universe), you still have a nice method encapsulating this and don't have to change the public interface. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/