For this to work you need two things.
- The script that starts your Catalyst application needs to be able to find the model in the Perl library path (i.e. @INC)
- You need to configure Catalyst to re-use a different model outside of where it will normally find it.
Below I detail one possible approach to this. There are many different ways do this depending on what fits your needs.
Create a "super-project" or folder that will contain the common model, AppOne and AppTwo. AppOne and AppTwo are two normal Catalyst projects with the default folder structure. To store the common model create the folder common/lib in the "super-project".
Modify the AppOne/script/appone_server.pl (or what other script you use to starter your Catalyst server so that it can find the common/lib folder. You can do this be adding the lines
use FindBin;
use lib "$FindBin::Bin/../../common/lib"; # now AppOne can find the lib.
Add a Catalyst model to AppOne/lib/Model called CommonModel like this.
package AppOne::Model::CommonModel;
use strict;
use base 'Catalyst::Model::DBIC::Schema';
__PACKAGE__->config(
schema_class => 'CommonSchema', # name of the schema class in common/lib
connect_info => {
# connect info here
}
);
Repeat the two last steps for AppTwo as well.
As mentioned this is one way to do it. It assumes that you will deploy you applications by just copying the entire super-project to your server and that the directory structure will be exactly the same.