package MyApp::SingleTableInheritance::Schema::Result::Player; use namespace::autoclean; use Moose; use MooseX::NonMoose; use MooseX::Types::Moose qw(Str Num Undef); use MooseX::Types::UUID qw(UUID); extends qw( DBIx::Class::Core ); __PACKAGE__->load_components(qw( UUIDColumns )); # **************************************************************** # table setting(s) # **************************************************************** __PACKAGE__->table('players'); __PACKAGE__->add_columns( id => { data_type => 'char', size => 36, }, name => { data_type => 'varchar', size => 32, }, club => { data_type => 'varchar', size => 32, is_nullable => 1, }, batting_average => { data_type => 'float', is_nullable => 1, }, bowling_average => { data_type => 'float', is_nullable => 1, }, type => { data_type => 'text', }, ); # Or, use DBIx::Class::MooseColumns with ( 'MyApp::Role::Schema::Result::Validatable' => { columns => { id => { isa => UUID }, name => { isa => Str }, club => { isa => Str|Undef }, batting_average => { isa => Num|Undef }, bowling_average => { isa => Num|Undef }, type => { isa => Str }, }, }, ); sub _prepare_table { my ($class) = @_; $class->set_primary_key( qw(id) ); $class->uuid_columns( qw(id) ); $class->add_unique_constraint( [qw(name)] ); return; } sub insert { my ($self, $arguments) = @_; $self->type(blessed $self); return $self->next::method($arguments); } sub update { my ($self, $arguments) = @_; delete $arguments->{type} if defined $arguments && ref $arguments eq 'HASH' && exists $arguments->{type}; return $self->next::method($arguments); } # **************************************************************** # business logic(s) # **************************************************************** sub salute { my ($self) = @_; printf( "Hello, my name is %s.\n", $self->name, ); } # **************************************************************** # compile-time process(es) # **************************************************************** __PACKAGE__->_prepare_table; __PACKAGE__->meta->make_immutable; 1; __END__ =pod =encoding utf-8 =head1 NAME MyApp::SingleTableInheritance::Schema::Result::Player - blah blah blah =head1 SYNOPSIS # yada yada yada =head1 DESCRIPTION blah blah blah =head1 AUTHOR =over 4 =item MORIYA Masaki, alias Gardejo C<< >>, L =back =head1 COPYRIGHT AND LICENSE Copyright (c) 2010 MORIYA Masaki, alias Gardejo. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L and L. The full text of the license can be found in the F file included with this distribution. =cut