Custom methods in generated module

25 views
Skip to first unread message

Rohan Almeida

unread,
Jun 15, 2010, 7:38:04 PM6/15/10
to rose-db...@googlegroups.com

Hi,

I'm using Rose::DB::Object::Loader's make_modules() to generate
the *.pm files from my database schema. No problems here.

However, I couldn't find a way to tell it not to overwrite any
custom methods/code which I put in. Any ideas?


Thanks,
Rohan

John Siracusa

unread,
Jun 15, 2010, 8:24:58 PM6/15/10
to rose-db...@googlegroups.com

One common way to do that is to put your custom code for module Foo
into Foo::Extra (or whatever), then put a use or "require Foo::Extra"
statement at the bottom of your generated Foo.pm using
module_postamble:

http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Loader.pm#module_postamble

(or module_preamble depending on when you want it loaded). That way,
the Loader never touches your custom modules/code, but the classes it
generates will load them.

(I personally generate my modules only once "for real," and then check
them in and customize them in-place. My schemas usually change slowly
enough that I can manually track each change and add it to the
necessary class(es), or, worst case, re-generate and then use a diff
tool to examine and apply the changes. YMMV.)

-John

Reply all
Reply to author
Forward
0 new messages