package Catalyst::Model::MultiAdaptor;
use strict;
use warnings;
use MRO::Compat;

our $VERSION = '0.11';
use base 'Catalyst::Model::MultiAdaptor::Base';

sub new {
    my $class = shift;
    my $self  = $class->next::method(@_);
    $self->load_services( $self->{config} );



=head1 NAME

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 C<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.

=head1 AUTHOR

dann E<lt>techmemo@gmail.comE<gt>

=head1 SEE ALSO

=head1 LICENSE

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