in reply to dprofpp -- now what?
One of the things you could do is to subclass the _mk_column_accessors method, e.g.:
sub _mk_column_accessors { my $class = shift; my @new = grep {!exists &{$class."::$_"}} @_; # remember new ones $class->SUPER::_mk_column_accessors( @_ ); # accessors + mutators # Redefine accessors to be very lean no warnings 'redefine'; no strict 'refs'; foreach (@new) { my $method = $class."::$_"; my $old = \&$method; *$method = sub { # if not available yet, got fetch with normal accessor return $old->( @_ ) unless exists $_[0]->{$_}; $_[0]->{$_}; }; } } #_mk_column_accessors
Further optimizations with the accessors could be made if you know 100% sure that when a subclss Class::DBI object is created, all the fields are fetched from the database (bij setting all of the fields to be "Essential"). Something like:
sub _mk_column_accessors { my $class = shift; eval "sub ${class}::$_ { \$_[0]->{'$_'} }" foreach grep {!exists &{$class."::$_"}} @_; $class->SUPER::_mk_column_accessors( @_ ); } #_mk_column_accessors
Please note that I've used a string eval here for a reason: benchmarks have shown that accessors created that way are the fastest accessors possible (just as if writing them manually). All other solutions use a closure, which are inherently slower. And since speed is what you're interested in here... ;-)
Hope this helps.
Liz
|
|---|