sub index :Path :Args(0) { my ( $self, $c ) = @_; my @people = $c->model('Models::People')->all(); $c->stash->{people} = \@people; } #### sub index :Path :Args(0) { my ( $self, $c ) = @_; $c->stash->{people} = $c->model('Models::People')->listall(); } #### package Models::Schema::ModelsDB::ResultSet::People; use strict; use warnings; use base 'DBIx::Class::ResultSet'; sub listall { my $self = shift; my @people = $self->all(); return \@people; } 1; #### sub index :Path :Args(0) { my ( $self, $c ) = @_; $c->stash->{people} = $c->model('HomeGrownModel')->homegrown_people(); } #### 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; #### after 'setup_components' => sub { my $app = shift; for (keys %{ $app->components }) { $app->components->{$_}->initialize_after_setup($app) if $app->components->{$_}->can('initialize_after_setup'); } }; #### package HomeGrown; use Moose; use namespace::autoclean; has 'schema' => ( is => 'rw', required => 1, isa => 'DBIx::Class::Schema', ); sub homegrown_people { my $self = shift; my @people = $self->schema->resultset('People')->all(); return \@people; } 1;