Author image John Napiorkowski
and 1 contributors


DBIx::Class::Moo::ResultClass - Moo-ify DBIx::Class Result (row) Classes


    package Schema::Result::Artist;

    use DBIx::Class::Moo::ResultClass;

    has spork => (is => 'ro', default => sub { 'THERE IS NO SPORK' });


      artist_id => {
        data_type => 'integer',
        is_auto_increment => 1,
      name => {
        data_type => 'varchar',
        size => '96',


    my $artist = $schema->resultset('Artist')

    warn $artist->spork; # 'THERE IS NO SPORK'

    my $another = $schema->resultset('Artist')
      ->create({name=>'Foo', spork=>'foo');

    warn $artist->spork; # 'foo'


Note: Warning, Early Access module. This is pretty straightforward but we've not used it extensively so its possible some corner cases exist. Test cases / docs welcomed.

Use Moo with DBIx::Class. It's not immediately obvious how to do this in DBIx::Class since you need to fuss with Moo and 'FOREIGNBUILDARGS' to get it working correctly. So we did the heavy lifting for you.

You can use this directly on your result classes and/or on a base resultclass. You can also use it to consume Moo roles directly:

    package Schema::MyRole;

    use Moo::Role;

    has foo => (is => 'rw');

    package Schema::Result;

    use strict;
    use warnings;

    use DBIx::Class::Moo::ResultClass;

    # Don't need to "extends 'DBIx::Class::Core';" since we do that by default for you 

    has 'result' => (is=>'ro');


    package Schema::Result::Artist;

    use DBIx::Class::Moo::ResultClass;

    extends 'Schema::Result';
    with 'Schema::MyRole';


And it should just do the right thing.

This doesn't work yet on ResultSet classes (another time / test cases welcomed).

NOTE By default we extend "DBIx::Class::Core " unless the consuming class ISA DBIx::Class. This allows you to easily set a custom base class.


    mst - Matt S. Trout (cpan:MSTROUT) <>
    jnap - John Napiorkowski (cpan:JJNAPIORK)  L<>


DBIx::Class, Moo


Copyright 2020, John Napiorkowski

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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 108:

L<> starts or ends with whitespace