Gianni Ceccarelli > CatalystX-ComponentsFromConfig-1.004 > CatalystX::ComponentsFromConfig::ModelPlugin

Download:
CatalystX-ComponentsFromConfig-1.004.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.004   Source  

NAME ^

CatalystX::ComponentsFromConfig::ModelPlugin - plugin to create Models from configuration

VERSION ^

version 1.004

SYNOPSIS ^

In your application:

  package My::App;
  use Catalyst qw(
      ConfigLoader
      +CatalystX::ComponentsFromConfig::ModelPlugin
  );

In your config:

   <Model::MyClass>
    class My::Class
    <args>
      some  param
    </args>
    <traits>
      +My::Special::Role
    </traits>
   </Model::MyClass>

Now, $c->model('MyClass') will contain an object built just like:

  my $obj = My::Class->new({some=>'param'});
  apply_all_roles($obj,'My::Special::Role');

DESCRIPTION ^

This plugin, built on CatalystX::ComponentsFromConfig::Role::PluginRole, allows you to create model components at application setup time, just by specifying them in the configuration.

GLOBAL CONFIGURATION ^

  <models_from_config>
   base_class My::ModelAdaptor
  </models_from_config>

The default base_class is CatalystX::ComponentsFromConfig::ModelAdaptor, but you can specify whatever adaptor you want. Of course, you have to make sure that the model-specific configuration block is in the format that your adaptor expects.

A useful example is when you want to use Catalyst::Model::DBIC::Schema:

 <Model::DB>
  base_class Catalyst::Model::DBIC::Schema
  schema_class My::Schema
  <connect_info>
   dsn dbi:SQLite:dbname=/tmp/whatever.db
  </connect_info>
 </Model::DB>

Note that, since we're not using CatalystX::ComponentsFromConfig::ModelAdaptor, the way you pass the various parameters is different than what is shown at the top.

AUTHORS ^

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2012 by Net-a-porter.com.

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

syntax highlighting: