1package Class::DBI::Column; 2 3=head1 NAME 4 5Class::DBI::Column - A column in a table 6 7=head1 SYNOPSIS 8 9 my $column = Class::DBI::Column->new($name); 10 11 my $name = $column->name; 12 13 my @groups = $column->groups; 14 my $pri_col = $colg->primary; 15 16 if ($column->in_database) { ... } 17 18=head1 DESCRIPTION 19 20Each Class::DBI class maintains a list of its columns as class data. 21This provides an interface to those columns. You probably shouldn't be 22dealing with this directly. 23 24=head1 METHODS 25 26=cut 27 28use strict; 29use base 'Class::Accessor'; 30 31__PACKAGE__->mk_accessors( 32 qw/name accessor mutator placeholder 33 is_constrained/ 34); 35 36use overload 37 '""' => sub { shift->name_lc }, 38 fallback => 1; 39 40=head2 new 41 42 my $column = Class::DBI::Column->new($column) 43 44A new object for this column. 45 46=cut 47 48sub new { 49 my ($class, $name) = @_; 50 return $class->SUPER::new( 51 { 52 name => $name, 53 _groups => {}, 54 placeholder => '?' 55 } 56 ); 57} 58 59sub name_lc { lc shift->name } 60 61sub add_group { 62 my ($self, $group) = @_; 63 $self->{_groups}->{$group} = 1; 64} 65 66sub groups { 67 my $self = shift; 68 my %groups = %{ $self->{_groups} }; 69 delete $groups{All} if keys %groups > 1; 70 return keys %groups; 71} 72 73sub in_database { 74 return !scalar grep $_ eq "TEMP", shift->groups; 75} 76 771; 78