NAME
DBIx::Class::Moo::ResultClass - Moo-ify DBIx::Class Result (row) Classes
SYNOPSIS
package Schema::Result::Artist;
use DBIx::Class::Moo::ResultClass;
has spork => (is => 'ro', default => sub { 'THERE IS NO SPORK' });
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(
artist_id => {
data_type => 'integer',
is_auto_increment => 1,
},
name => {
data_type => 'varchar',
size => '96',
});
__PACKAGE__->set_primary_key('artist_id');
my $artist = $schema->resultset('Artist')
->create({name=>'Foo');
warn $artist->spork; # 'THERE IS NO SPORK'
my $another = $schema->resultset('Artist')
->create({name=>'Foo', spork=>'foo');
warn $artist->spork; # 'foo'
DESCRIPTION
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');
1;
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.
AUTHOR
mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
jnap - John Napiorkowski (cpan:JJNAPIORK) L<email:jjnapiork@cpan.org>
SEE ALSO
COPYRIGHT & LICENSE
Copyright 2020, John Napiorkowski email:jjnapiork@cpan.org
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