1 package DBIx::Class::InflateColumn::Object::Enum;
5 use Carp qw/croak confess/;
10 DBIx::Class::InflateColumn::Object::Enum - Allows a DBIx::Class user to define a Object::Enum column
18 # Dist::Zill should handle this now
19 # ABSTRACT: Allows a DBIx::Class user to define a Object::Enum column
20 #our $VERSION = '0.04';
25 Load this module via load_components and utilize is_enum and values property
26 to define Enumuration columns via Object::Enum
32 use base 'DBIx::Class';
34 __PACKAGE__->load_components(qw/InflateColumn::Object::Enum Core/);
35 __PACKAGE__->table('testtable');
36 __PACKAGE__->add_columns(
38 data_type => 'varchar',
41 list => [qw/red green blue/]
44 color_native => { # works inline with native enum type
48 list => [qw/red green blue/]
55 Now you may treat the column as an L<Object::Enum> object.
57 my $table_rs = $db->resultset('TableClass')->create({
61 $table_rs->color->set_red; # sets color to red
62 $table_rs->color->is_red; # would return true
63 $table_rs->color->is_green; # would return false
64 print $table_rs->color->value; # would print 'red'
65 $table_rs->color->unset; # set the value to 'undef' or 'null'
66 $table_rs->color->is_red; # returns false now
71 =head2 register_column
73 Internal chained method with L<DBIx::Class::Row/register_column>.
74 Users do not call this directly!
80 my ($column, $info) = @_;
82 $self->next::method(@_);
84 return unless defined $info->{is_enum} and $info->{is_enum};
86 croak("Object::Enum '$column' missing 'extra => { list => [] }' column configuration")
88 defined $info->{extra}
89 and ref $info->{extra} eq 'HASH'
90 and defined $info->{extra}->{list}
93 croak("Object::Enum '$column' value list (extra => { list => [] }) must be an ARRAY reference")
94 unless ref $info->{extra}->{list} eq 'ARRAY';
96 my $values = $info->{extra}->{list};
97 my %values = map {$_=>1} @{$values};
99 push(@{$values},$info->{default_value})
100 if defined($info->{default_value})
101 && !exists $values{$info->{default_value}};
103 push(@{$values}, undef)
104 if defined($info->{is_nullable})
105 && $info->{is_nullable};
107 $self->inflate_column(
111 my $e = Object::Enum->new({values=>$values});
125 Jason M. Mills, C<< <jmmills at cpan.org> >>
129 Please report any bugs or feature requests to C<bug-dbix-class-inflatecolumn-object-enum at rt.cpan.org>, or through
130 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-InflateColumn-Object-Enum>. I will be notified, and then you'll
131 automatically be notified of progress on your bug as I make changes.
138 You can find documentation for this module with the perldoc command.
140 perldoc DBIx::Class::InflateColumn::Object::Enum
143 You can also look for information at:
147 =item * RT: CPAN's request tracker
149 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-InflateColumn-Object-Enum>
151 =item * AnnoCPAN: Annotated CPAN documentation
153 L<http://annocpan.org/dist/DBIx-Class-InflateColumn-Object-Enum>
157 L<http://cpanratings.perl.org/d/DBIx-Class-InflateColumn-Object-Enum>
161 L<http://search.cpan.org/dist/DBIx-Class-InflateColumn-Object-Enum>
168 L<Object::Enum>, L<DBIx::Class>, L<DBIx::Class::InflateColumn::URI>
171 =head1 COPYRIGHT & LICENSE
173 Copyright 2008 Jason M. Mills, all rights reserved.
175 This program is free software; you can redistribute it and/or modify it
176 under the same terms as Perl itself.
181 1; # End of DBIx::Class::InflateColumn::Object::Enum