Add SQL_TINYINT and SQL_BIGINT to %SQL::Translator::Schema::Field::type_mapping
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema / Field.pm
index c5bda76..b9aed47 100644 (file)
@@ -25,14 +25,10 @@ C<SQL::Translator::Schema::Field> is the field object.
 use Moo;
 use SQL::Translator::Schema::Constants;
 use SQL::Translator::Types qw(schema_obj);
-use SQL::Translator::Utils qw(parse_list_arg ex2err throw);
+use SQL::Translator::Utils qw(parse_list_arg ex2err throw carp_ro);
+use Sub::Quote qw(quote_sub);
 
-with qw(
-  SQL::Translator::Schema::Role::BuildArgs
-  SQL::Translator::Schema::Role::Extra
-  SQL::Translator::Schema::Role::Error
-  SQL::Translator::Schema::Role::Compare
-);
+extends 'SQL::Translator::Schema::Object';
 
 our $VERSION = '1.59';
 
@@ -47,13 +43,14 @@ use overload
 
 use DBI qw(:sql_types);
 
-# Mapping from string to sql contstant
+# Mapping from string to sql constant
 our %type_mapping = (
   integer => SQL_INTEGER,
   int     => SQL_INTEGER,
 
+  tinyint => SQL_TINYINT,
   smallint => SQL_SMALLINT,
-  bigint => 9999, # DBI doesn't export a constatn for this. Le suck
+  bigint => SQL_BIGINT,
 
   double => SQL_DOUBLE,
 
@@ -102,8 +99,8 @@ all the comments joined on newlines.
 
 has comments => (
     is => 'rw',
-    coerce => sub { ref($_[0]) eq 'ARRAY' ? $_[0] : [$_[0]] },
-    default => sub { [] },
+    coerce => quote_sub(q{ ref($_[0]) eq 'ARRAY' ? $_[0] : [$_[0]] }),
+    default => quote_sub(q{ [] }),
 );
 
 around comments => sub {
@@ -129,7 +126,7 @@ Get or set the field's data type.
 
 =cut
 
-has data_type => ( is => 'rw', default => sub { '' } );
+has data_type => ( is => 'rw', default => quote_sub(q{ '' }) );
 
 =head2 sql_data_type
 
@@ -156,16 +153,6 @@ assume an error like other methods.
 
 has default_value => ( is => 'rw' );
 
-=head2 extra
-
-Get or set the field's "extra" attibutes (e.g., "ZEROFILL" for MySQL).
-Accepts a hash(ref) of name/value pairs to store;  returns a hash.
-
-  $field->extra( qualifier => 'ZEROFILL' );
-  my %extra = $field->extra;
-
-=cut
-
 =head2 foreign_key_reference
 
 Get or set the field's foreign key reference;
@@ -178,6 +165,7 @@ has foreign_key_reference => (
     is => 'rw',
     predicate => '_has_foreign_key_reference',
     isa => schema_obj('Constraint'),
+    weak_ref => 1,
 );
 
 around foreign_key_reference => sub {
@@ -204,7 +192,7 @@ Get or set the field's C<is_auto_increment> attribute.
 
 has is_auto_increment => (
     is => 'rw',
-    coerce => sub { $_[0] ? 1 : 0 },
+    coerce => quote_sub(q{ $_[0] ? 1 : 0 }),
     builder => 1,
     lazy => 1,
 );
@@ -235,7 +223,7 @@ Returns whether or not the field is a foreign key.
 
 has is_foreign_key => (
     is => 'rw',
-    coerce => sub { $_[0] ? 1 : 0 },
+    coerce => quote_sub(q{ $_[0] ? 1 : 0 }),
     builder => 1,
     lazy => 1,
 );
@@ -261,7 +249,7 @@ sub _build_is_foreign_key {
 
 Get or set whether the field can be null.  If not defined, then
 returns "1" (assumes the field can be null).  The argument is evaluated
-by Perl for True or False, so the following are eqivalent:
+by Perl for True or False, so the following are equivalent:
 
   $is_nullable = $field->is_nullable(0);
   $is_nullable = $field->is_nullable('');
@@ -276,8 +264,8 @@ foreign keys; checks) are represented as table constraints.
 
 has is_nullable => (
     is => 'rw',
-    coerce => sub { $_[0] ? 1 : 0 },
-    default => sub { 1 },
+    coerce => quote_sub(q{ $_[0] ? 1 : 0 }),
+    default => quote_sub(q{ 1 }),
  );
 
 around is_nullable => sub {
@@ -297,7 +285,7 @@ a table constraint (should it?).
 
 has is_primary_key => (
     is => 'rw',
-    coerce => sub { $_[0] ? 1 : 0 },
+    coerce => quote_sub(q{ $_[0] ? 1 : 0 }),
     lazy => 1,
     builder => 1,
 );
@@ -324,6 +312,8 @@ Determine whether the field has a UNIQUE constraint or not.
 
 has is_unique => ( is => 'lazy', init_arg => undef );
 
+around is_unique => carp_ro('is_unique');
+
 sub _build_is_unique {
     my ( $self ) = @_;
 
@@ -410,7 +400,7 @@ Get or set the field's order.
 
 =cut
 
-has order => ( is => 'rw', default => sub { 0 } );
+has order => ( is => 'rw', default => quote_sub(q{ 0 }) );
 
 around order => sub {
     my ( $orig, $self, $arg ) = @_;
@@ -455,7 +445,7 @@ numbers and returns a string.
 
 has size => (
     is => 'rw',
-    default => sub { [0] },
+    default => quote_sub(q{ [0] }),
     coerce => sub {
         my @sizes = grep { defined && m/^\d+(?:\.\d+)?$/ } @{parse_list_arg($_[0])};
         @sizes ? \@sizes : [0];
@@ -493,11 +483,11 @@ also be used to get the table name.
 
 =cut
 
-has table => ( is => 'rw', isa => schema_obj('Table') );
+has table => ( is => 'rw', isa => schema_obj('Table'), weak_ref => 1 );
 
 around table => \&ex2err;
 
-=head2
+=head2 parsed_field
 
 Returns the field exactly as the parser found it