package Models::Model::HomeGrownModel; use base 'Catalyst::Model'; use HomeGrown; use Moose; our $AUTOLOAD; has 'HomeGrownInstance' => ( is => 'rw', isa => 'HomeGrown', ); # Gotcha: using the COMPONENT method like shown below may get you in # trouble because your component mat very well be loaded before the # DBIC model does. The initialize_after_setup hack shown further down, # is a work-around to deferr the instatiation of things, or at least # making sure that your model initializes lastly. #sub COMPONENT { # my ( $self, $app ) = @_; # my $dbic_schema = $app->model('ModelsDB')->schema; # return HomeGrown->new( schema => $dbic_schema ); #} sub initialize_after_setup { my ( $self, $app ) = @_; $app->log->debug('Initializing Homegrown with schema AFTER app is fully loaded...'); $self->HomeGrownInstance( HomeGrown->new( schema => $app->model('ModelsDB')->schema ) ); } # Here you would map your Catalyst Model methods to the actual model # in this example we will just forward everything as is to our # HomeGrown external Model sub AUTOLOAD { my $self = shift; my $name = $AUTOLOAD; $name =~ s/.*://; $self->HomeGrownInstance->$name(@_); } 1;