1SQL::Translator::SchemaU:s:eFrieClodn(t3r)ibuted Perl DoScQuLm:e:nTtraatnisolnator::Schema::Field(3)
2
3
4

NAME

6       SQL::Translator::Schema::Field - SQL::Translator field object
7

SYNOPSIS

9         use SQL::Translator::Schema::Field;
10         my $field = SQL::Translator::Schema::Field->new(
11             name  => 'foo',
12             table => $table,
13         );
14

DESCRIPTION

16       "SQL::Translator::Schema::Field" is the field object.
17

METHODS

19       new
20
21       Object constructor.
22
23         my $field = SQL::Translator::Schema::Field->new(
24             name  => 'foo',
25             table => $table,
26         );
27
28       comments
29
30       Get or set the comments on a field.  May be called several times to set
31       and it will accumulate the comments.  Called in an array context,
32       returns each comment individually; called in a scalar context, returns
33       all the comments joined on newlines.
34
35         $field->comments('foo');
36         $field->comments('bar');
37         print join( ', ', $field->comments ); # prints "foo, bar"
38
39       data_type
40
41       Get or set the field's data type.
42
43         my $data_type = $field->data_type('integer');
44
45       default_value
46
47       Get or set the field's default value.  Will return undef if not defined
48       and could return the empty string (it's a valid default value), so
49       don't assume an error like other methods.
50
51         my $default = $field->default_value('foo');
52
53       extra
54
55       Get or set the field's "extra" attibutes (e.g., "ZEROFILL" for MySQL).
56       Accepts a hash(ref) of name/value pairs to store;  returns a hash.
57
58         $field->extra( qualifier => 'ZEROFILL' );
59         my %extra = $field->extra;
60
61       foreign_key_reference
62
63       Get or set the field's foreign key reference;
64
65         my $constraint = $field->foreign_key_reference( $constraint );
66
67       is_auto_increment
68
69       Get or set the field's "is_auto_increment" attribute.
70
71         my $is_auto = $field->is_auto_increment(1);
72
73       is_foreign_key
74
75       Returns whether or not the field is a foreign key.
76
77         my $is_fk = $field->is_foreign_key;
78
79       is_nullable
80
81       Get or set whether the field can be null.  If not defined, then returns
82       "1" (assumes the field can be null).  The argument is evaluated by Perl
83       for True or False, so the following are eqivalent:
84
85         $is_nullable = $field->is_nullable(0);
86         $is_nullable = $field->is_nullable('');
87         $is_nullable = $field->is_nullable('0');
88
89       While this is technically a field constraint, it's probably easier to
90       represent this as an attribute of the field.  In order keep things con‐
91       sistent, any other constraint on the field (unique, primary, and for‐
92       eign keys; checks) are represented as table constraints.
93
94       is_primary_key
95
96       Get or set the field's "is_primary_key" attribute.  Does not create a
97       table constraint (should it?).
98
99         my $is_pk = $field->is_primary_key(1);
100
101       is_unique
102
103       Determine whether the field has a UNIQUE constraint or not.
104
105         my $is_unique = $field->is_unique;
106
107       is_valid
108
109       Determine whether the field is valid or not.
110
111         my $ok = $field->is_valid;
112
113       name
114
115       Get or set the field's name.
116
117        my $name = $field->name('foo');
118
119       The field object will also stringify to its name.
120
121        my $setter_name = "set_$field";
122
123       Errors ("No field name") if you try to set a blank name.
124
125       full_name
126
127       Read only method to return the fields name with its table name
128       pre-pended.  e.g. "person.foo".
129
130       order
131
132       Get or set the field's order.
133
134         my $order = $field->order(3);
135
136       schema
137
138       Shortcut to get the fields schema ($field->table->schema) or undef if
139       it doesn't have one.
140
141         my $schema = $field->schema;
142
143       size
144
145       Get or set the field's size.  Accepts a string, array or arrayref of
146       numbers and returns a string.
147
148         $field->size( 30 );
149         $field->size( [ 255 ] );
150         $size = $field->size( 10, 2 );
151         print $size; # prints "10,2"
152
153         $size = $field->size( '10, 2' );
154         print $size; # prints "10,2"
155
156       table
157
158       Get or set the field's table object. As the table object stringifies
159       this can also be used to get the table name.
160
161         my $table = $field->table;
162         print "Table name: $table";
163
164       equals
165
166       Determines if this field is the same as another
167
168         my $isIdentical = $field1->equals( $field2 );
169

AUTHOR

171       Ken Y. Clark <kclark@cpan.org>.
172
173
174
175perl v5.8.8                       2007-10-24 SQL::Translator::Schema::Field(3)
Impressum