Galdor has asked for the wisdom of the Perl Monks concerning the following question:

I prefer Moo to Moose - how can I ensure returned DBIC objects are Moo rather than Moose? How can I tell?

Replies are listed 'Best First'.
Re: Moo with DBIC
by 1nickt (Canon) on Jan 07, 2026 at 10:07 UTC

    Hi,

    DBIx::Class does not itself use either Moose or Moo by default (Moose is an optional dependency for certain non-core functionalities, see https://metacpan.org/release/RIBASUSHI/DBIx-Class-0.082844/source/lib/DBIx/Class/Optional/Dependencies.pod).

    However you can import one of them yourself. See https://metacpan.org/dist/DBIx-Class/view/lib/DBIx/Class/Manual/FAQ.pod#Misc.

    UPDATE: Here's a demo you can play with:

    Using a SQLite DB at ./test.db created with one simple table:
    create table MyTable(id integer not null primary key, foo text not null);
    insert into MyTable values (1,"bar"),(2,"baz"),(3,"qux");

    And a resultset class at ./lib/Test/Schema/Result/MyTable.pm (note the use of Moo):

    use utf8; package Test::Schema::Result::MyTable; use Moo; extends 'DBIx::Class::Core'; has extra_attr => (is => 'rw', lazy => 1, default => sub{'hello, world +'}); =head1 NAME Test::Schema::Result::MyTable =cut use strict; use warnings; use base 'DBIx::Class::Core'; =head1 TABLE: C<MyTable> =cut __PACKAGE__->table("MyTable"); =head1 ACCESSORS =head2 id data_type: 'integer' is_auto_increment: 1 is_nullable: 0 =head2 foo data_type: 'text' default_value: 'bar' is_nullable: 0 =cut __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 } +, "foo", { data_type => "text", default_value => "bar", is_nullable => 0 }, ); =head1 PRIMARY KEY =over 4 =item * L</id> =back =cut __PACKAGE__->set_primary_key("id"); 1;

    And the base class at ./lib/Test/Schema.pm:

    use utf8; package Test::Schema; use strict; use warnings; use base 'DBIx::Class::Schema'; __PACKAGE__->load_namespaces; 1;

    And a script at ./bin/test.pl:

    use strict; use warnings; use feature 'say'; use Test::Schema; my $schema = Test::Schema->connect('dbi:SQLite:./test.db','',''); my $obj = $schema->resultset('MyTable')->find(1); say $obj->foo; say $obj->extra_attr; __END__

    Running this with $ perl ./bin/test.pl:

    bar hello, world

    Hope this helps!


    The way forward always starts with a minimal test.