View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Lukas Thiemeier > Catalyst-TraitFor-Model-DBIC-Schema-ResultRoles > Catalyst::TraitFor::Model::DBIC::Schema::ResultRoles



Annotate this POD

View/Report Bugs
Module Version: 0.011   Source  


Catalyst::TraitFor::Model::DBIC::Schema::ResultRoles - Automatically applying Moose Roles to Result-Classes at BUILD time


Version 0.0110


In your Catalyst Model (lib/YourApp/Model/


                traits => "ResultRoles",

OR in your Application main file (lib/


                "Model::YourModel" => (

                        traits => "ResultRoles",


and then, in an appropriate location (lib/YourApp/Schema/ResultRole/YourResult/

        package YourApp::Schema::ResultRole::YourResult::YourRole;

        use namespace::autoclean;
        use Moose::Role;


        sub your_result_sub{
                # do something result specific


This module is a trait for DBIC based Catalyst models. It hooks to the models BUILD process and appies a set of Moose Roles to each loaded resultclass. This makes it possible to customize the resultclasses without changing the automaticaly created DBIx::Class::Core files. Resultclasses can be customized by creating one or more roles per resultclass. Customized code and automatically created code are clearly seperated.

Because applying roles depends on the presence of a meta-class, this trait only works with "moosified" resultclasses. "Non-moosified" resultclasses are ignored, which makes it possible to use a mixed set of moosified and non-moosified resultclasses.


enabling the traits

See "SYNOPSIS" above or "traits" in Catalyst::Model::DBIC::Schema

creating roles for result classes


Assumed the application name is "MyApp", and the schema class is "MyApp::Schema". If you want to create a role for "MyApp::Schema::Book",

create lib/MyApp/Schema/ResultRole/ with the following content:

        package MyApp::Schema::ResultRole::Book::Author;

        use namespace::autoclean;
        use Moose::Role;


Within this package, MyApp::Schema::Book can be customized with all features provided by Moose::Role. Result-class methods, like "many_to_many" and "has_many" have to be called with the full result-class name.

Assumed there is another result-class named "Author" and a corresponding BookAuthor relation, a many_to_many relation could be defined for MyApp::Schema::Result::Book by editing the role and adding:

        requires qw/book_authors/;
        MyApp::Schema::Result::Book->many_to_many(authors => 'book_authors', 'author');

to MyApp::Schema::ResultRole::Book::Author, after "use Moose::Role", but before "1;"

How does it work:

Without further configuration, the trait will guess the role_location attribute by calling $self->schema_class and appending "::ResultRole".

Example: Assumed the application name is "MyApp", and the schema class is "MyApp::Schema": The result_location will be set to "MyApp::Schema::ResultRole"

Catalyst::TraitFor::Model::DBIC::Schema::Result uses "find_all_modules" in Module::Find to find possible roles for each defined result source. The roles namespace is expected to be:

 $self->role_location . "::". $souce_name

Example: Assumed the application name is "MyApp", the schema class is "MyApp::Schema" and the current source name is "Book": All packages in "MyApp::Schema::ResultRole::Book" are expected to be roles for MyApp::Schema::Result::Book;

Possible roles are applied to the schema class with "apply_all_roles" in Moose::Util.

setting attributes

All attributes can be configured by setting their "config args" within the applications configuration, either in the the applications main file, or in the applications schema class.

Example: Assumed the application name is "MyApp", and the model class is "MyApp::Model::DB": To enable the "debug" flag, either add

        rr_debug => 1,

to lib/MyApp/Model/, or add

        'Model::DB' =>{
                rr_debug => 1,

to lib/


The following attributes can be customized:


Please report any bugs or feature requests to bug-catalyst-traitfor-model-dbic-schema-resultroles at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



Lukas Thiemeier, <lukast at>


You can find documentation for this module with the perldoc command.

        perldoc Catalyst::TraitFor::Model::DBIC::Schema::ResultRoles

A public subversion repository is available at:

WebSVN is available at




Copyright 2011 Lukas Thiemeier.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

syntax highlighting: