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