++ed by:
1 non-PAUSE user
Author image dann
and 1 contributors


Catalyst::Model::MultiAdaptor - use plain classes as a Catalyst Model


Given a good old perl class like:

  package MyApp::Service::SomeClass;
  use Moose;

  has 'id' => (
      is => 'rw', 


  package MyApp::Service::AnotherClass;
  use Moose;

  has 'host' => (
      is => 'rw', 


Wrap them with a Catalyst Model. The package parameter is base package for plain old perl classes. The lifecyce parameter is lifcycle for wrapped class instance. You can set lifecyle listed as below: * Singleton - create instance per applciation * PerRequest - create instance per request * Prototype - create instance per every time.

  use Catalyst::Model::MultiAdaptor;

  package MyApp::Web::Model::Service;
  use base 'Catalyst::Model::MultiAdaptor';
      package => 'MyApp::Service',
      lifycycle => 'Singleton',
      config => {
          'SomeClass' => {
              id => 1,
          'AnotherClass' => {
                host => 'example',


Then you can use Wrapped models like below:

  sub action: Whatever {
      my ($self, $c) = @_;
      my $someclass = $c->model('Service::SomeClass');
      $someclass->method; #yay

  sub another_action: Whatever {
      my ($self, $c) = @_;
      my $anotherclass = $c->model('Service::AnotherClass');
      $anotherclass->method; #yay

Note that MyApp::Service::SomeClass is instantiated at application statup time.


This modules aims to integrate POPO models into Catalyst model.

Application models should be plain old perl class (POPO). Separating model classes from Catalyst makes Model classes more resusable and testable.

Catalyst::Model::Adaptor is very good module for this purpose. but we need to create multiple adaptors if we have multiple plain perl classes.

This modules can easily integrate multiple plain models as Catalyst model.


dann <techmemo@gmail.com>



This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.