On 1/12/07 8:25 PM, Jud wrote: > Reading throught the Rose::DB::Object::Metadata::Column docs, it looks > like I can manually create get and set methods from setup via the > columns declaration, but I'm stuck on how to proceed either in the case > of manually specifying what the name of the accessor and mutator should > be, and the more desirable case where get_* and set_* are created by > default.
There are a few ways to do this. One way is to explicitly set the default_auto_method_types() for each column class: http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Metadata/Colum n.pm#default_auto_method_types But that's a bit tedious (there are a lot of column classes) and it'd probably break any other RDBO-using code that you might try to add to your own code. A better option is to make your own Metadata subclass and then override the make_column_methods() method and change the auto_method_types() of all the columns before calling through to the base class implementation: package My::DB::Metadata; use base 'Rose::DB::Object::Metadata'; sub make_column_methods { my($self) = shift; foreach my $column ($self->columns) { $column->auto_method_types(qw(get set)); } $self->SUPER::make_column_methods(@_); } Then configure your common object base class to use your custom metadata class: package My::DB::Object; use base 'Rose::DB::Object'; use My::DB::Metadata; sub meta_class { 'My::DB::Metadata' } ... and you should be all set. (You could also override add_columns() or initialize() or any number of other Metadata methods that have a chance to twiddle the column metadata before the methods are made.) > BTW, there appears to be a typo in the Rose::DB::Object::Metadata::Column > docs, in the "MAKING METHODS" section under the text > > "The default method map is:" > > the titles are get_set, get, and get_set. The final get_set should > probably be just "set" Looks right here: http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Metadata/Colum n.pm#MAKING_METHODS or am I missing it? -John ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Rose-db-object mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/rose-db-object
