Solutions to problems:
make_immutable conflicts with the constructor non Moose new : this is automatically handled use MooseX::NonMoose ; unlike its documentation, no additional arguments or options are required; that DBIx::Class::Schema does not have a new method, and therefore MyApp::Schema does not need this helperInflateColumn::DateTime does not inflate when loaded into the base class: this was caused by the order of the components specified in load_components() ; the documentation should not hint that the order should matter, and I filed a bug report about it; reordering helped
With the solutions above, my DBIx :: Class example with Moose looks like this:
Schema Class:
package MyApp::Schema; use Moose;
Generic Result Base Class:
# a base class for all table class of this app package MyApp::Schema::Result; use Moose; use MooseX::MarkAsMethods autoclean => 1; use MooseX::NonMoose;
Generic ResultSet base class:
package MyApp::Schema::ResultSet; use Moose; use MooseX::MarkAsMethods autoclean => 1; use MooseX::NonMoose; extends 'DBIx::Class::ResultSet'; __PACKAGE__->meta->make_immutable; 1;
Example ResultSet class for the table my_table :
package MyApp::Schema::ResultSet::MyTable; use Moose; use MooseX::MarkAsMethods autoclean => 1; extends 'MyApp::Schema::ResultSet'; sub oldest { my $self = shift; $self->search({}, {order_by => {-ASC => 'date'}})->first; } __PACKAGE__->meta->make_immutable; 1;
Example Result class for table my_table :
package MyApp::Schema::Result::MyTable; use Moose; use MooseX::MarkAsMethods autoclean => 1; extends 'MyApp::Schema::Result'; __PACKAGE__->table("my_table"); __PACKAGE__->add_columns( id => {data_type => "integer", is_auto_increment => 1}, date => {data_type => "date"}, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->meta->make_immutable; 1;
source share