I think I'd consider doing it the other way around.
- customer instance script
- customer specific application module (where the foo script would be)
- base module (sessions, dbi, templates, logging, "presentation of infrastructure" etc.
I'm sure I'd find the 'code in a db' method hard to debug, test and maintiain.
shudder :-)