1 package SQL::Translator::Schema::Field;
3 # ----------------------------------------------------------------------
4 # $Id: Field.pm,v 1.2 2003-05-03 15:42:59 kycl4rk Exp $
5 # ----------------------------------------------------------------------
6 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
27 SQL::Translator::Schema::Field - SQL::Translator field object
31 use SQL::Translator::Schema::Field;
32 my $field = SQL::Translator::Schema::Field->new(
34 sql => 'select * from foo',
39 C<SQL::Translator::Schema::Field> is the field object.
48 use base 'Class::Base';
49 use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
53 # ----------------------------------------------------------------------
62 my $schema = SQL::Translator::Schema::Field->new;
66 my ( $self, $config ) = @_;
67 $self->params( $config, qw[ name data_type size is_primary_key ] );
71 # ----------------------------------------------------------------------
78 Get or set the field's data_type.
80 my $data_type = $field->data_type('integer');
85 $self->{'data_type'} = shift if @_;
86 return $self->{'data_type'} || '';
89 # ----------------------------------------------------------------------
96 Get or set the field's is_primary_key attribute.
98 my $is_pk = $field->is_primary_key(1);
102 my ( $self, $arg ) = @_;
104 if ( defined $arg ) {
105 $self->{'is_primary_key'} = $arg ? 1 : 0;
108 return $self->{'is_primary_key'} || 0;
111 # ----------------------------------------------------------------------
118 Get or set the field's name.
120 my $name = $field->name('foo');
125 $self->{'name'} = shift if @_;
126 return $self->{'name'} || '';
129 # ----------------------------------------------------------------------
136 Get or set the field's size.
138 my $size = $field->size('25');
142 my ( $self, $arg ) = @_;
144 if ( $arg && $arg =~ m/^\d+(?:\.\d+)?$/ ) {
145 $self->{'size'} = $arg;
148 return $self->{'size'} || 0;
151 # ----------------------------------------------------------------------
158 Determine whether the field is valid or not.
160 my $ok = $field->is_valid;
165 return 1 if $self->name && $self->data_type;
170 # ----------------------------------------------------------------------
176 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>