From: Justin Hunter Date: Thu, 3 Sep 2009 20:00:42 +0000 (-0700) Subject: add/use new Bit type (0 or 1) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ada068ed4adab55a4bd5a26269f8ef34bceeb6e6;p=dbsrgits%2FSQL-Translator-2.0-ish.git add/use new Bit type (0 or 1) --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index 844364c..71eda45 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -2,7 +2,7 @@ use MooseX::Declare; class SQL::Translator::Object::Column extends SQL::Translator::Object { use MooseX::Types::Moose qw(Bool Int Maybe Str); use MooseX::MultiMethods; - use SQL::Translator::Types qw(ColumnSize Constraint Table Trigger); + use SQL::Translator::Types qw(Bit ColumnSize Constraint Table Trigger); has 'table' => ( is => 'rw', @@ -50,8 +50,9 @@ class SQL::Translator::Object::Column extends SQL::Translator::Object { has 'is_auto_increment' => ( is => 'rw', - isa => Bool, + isa => Bit, required => 1, + coerce => 1, default => 0 ); diff --git a/lib/SQL/Translator/Types.pm b/lib/SQL/Translator/Types.pm index 182636a..fd61352 100644 --- a/lib/SQL/Translator/Types.pm +++ b/lib/SQL/Translator/Types.pm @@ -1,7 +1,8 @@ use MooseX::Declare; class SQL::Translator::Types { use MooseX::Types::Moose qw(ArrayRef CodeRef Int Maybe Str Undef); - use MooseX::Types -declare, [qw(Column Constraint ForeignKey Index PrimaryKey Procedure Schema Sequence Table Trigger View DBIHandle ColumnSize Parser Producer Translator)]; + use MooseX::Types -declare, [qw(Column Constraint ForeignKey Index PrimaryKey Procedure Schema Sequence Table Trigger View + Bit DBIHandle ColumnSize Parser Producer Translator)]; class_type Column, { class => 'SQL::Translator::Object::Column' }; class_type Constraint, { class => 'SQL::Translator::Object::Constraint' }; @@ -19,6 +20,11 @@ class SQL::Translator::Types { class_type Producer, { class => 'SQL::Translator::Producer' }; class_type Translator, { class => 'SQL::Translator' }; + subtype Bit, as Int, where { $_ == 1 || $_ == 0 }; + coerce Bit, + from Undef, via { 0 }, + from Str, via { $_ eq '1' ? 1 : 0 }; + subtype ColumnSize, as ArrayRef[Int]; coerce ColumnSize, from Int, via { [ $_ ] },