package DBIx::Class::MooseColumns;

use Moose ();
use Moose::Exporter;
use Moose::Util::MetaRole;

use DBIx::Class::MooseColumns::Meta::Role::Attribute;

=head1 NAME

DBIx::Class::MooseColumns - Lets you write DBIC add_column() definitions as attribute options

=head1 VERSION

Version 0.22


our $VERSION = '0.22';


  package MyApp::Schema::Result::Artist;

  use Moose;
  use DBIx::Class::MooseColumns;
  use namespace::autoclean;

  extends 'DBIx::Class::Core';


  has id => (
    isa => 'Int',
    is  => 'rw',
    add_column => {
      is_auto_increment => 1,

  has foo => (
    isa => 'Str',
    is  => 'rw',
    add_column => {
      data_type => 'datetime'

  has bar => (        # will call __PACKAGE__->add_column({})
    isa => 'Str',
    is  => 'rw',
    add_column => {

  has quux => (       # no __PACKAGE__->add_column() call
    isa => 'Str',
    is  => 'rw',


  __PACKAGE__->meta->make_immutable( inline_constructor => 0 );



This is ALPHA SOFTWARE. Use at your own risk. Features may change.


This module allows you to put the arguments to
L<DBIx::Class::ResultSource/add_column> right into your attribute definitions
and will automatically call it when it finds an C<add_column> attribute option.
It also replaces the L<DBIx::Class>-generated accessor methods (these are
L<Class::Accessor::Grouped>-generated accessor methods under the hood) with the
L<Moose>-generated accessor methods so that you can use more of the wonderful
powers of L<Moose> (eg. type constraints, triggers, ...).

I<Note:> C<< __PACKAGE__->table(...) >> must go B<before> the C<has> stanzas
(the L<DBIx::Class::ResultSource/table> is magic and does much more than
setting the table name, thus the C<< __PACKAGE__->add_column(...) >> calls that
the C<has> triggers won't work before that).

I<Note:> C<< __PACKAGE__->set_primary_key(...) >> and C<<
__PACKAGE__->add_unique_constraint(...) >> calls must go B<after> the C<has>
stanzas (since they depend on the referred columns being registered via C<<
__PACKAGE__->add_column(...) >> and that call is done when the C<has> runs).

=head1 TODO


=item *

convert the test harness to something sane - consider L<Fennec>?

=item *

delay ->add_column() calls until right after the ->table() call (collect the args and run them in an after method modifier of 'table', possibly batched in a single ->add_columns() call)


=head1 SEE ALSO

L<DBIx::Class>, L<Moose>

=head1 AUTHOR

Norbert Buchmuller, C<< <norbi at> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-dbix-class-moosecolumns at>, or through the web interface at
L<>.  I
will be notified, and then you'll automatically be notified of progress on your
bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc DBIx::Class::MooseColumns

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker


=item * AnnoCPAN: Annotated CPAN documentation


=item * CPAN Ratings


=item * Search CPAN




Copyright 2010 Norbert Buchmuller, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


my %metaroles = (
  class_metaroles => {
    attribute => ['DBIx::Class::MooseColumns::Meta::Role::Attribute'],

if ( $Moose::VERSION >= 1.9900 ) {
  $metaroles{role_metaroles} = {
    applied_attribute => ['DBIx::Class::MooseColumns::Meta::Role::Attribute'],


1; # End of DBIx::Class::MooseColumns