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.
|