From: Justin Hunter Date: Fri, 29 May 2009 00:47:46 +0000 (-0700) Subject: handle types correctly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c0e05758af648d9dd94abe26b8b7233d3e008547;p=dbsrgits%2FSQL-Translator-2.0-ish.git handle types correctly --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index dcb4cb3..87fda18 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -1,11 +1,13 @@ package SQL::Translator::Object::Column; use Moose; +use MooseX::Types::Moose qw(Bool Int Str); +use SQL::Translator::Types qw(Trigger); -has 'name' => (is => 'ro', isa => 'Str', required => 1); -has 'type' => (is => 'ro', isa => 'Str', required => 1); -has 'size' => (is => 'ro', isa => 'Int', required => 1); -has 'nullable' => (is => 'ro', isa => 'Bool', required => 1, default => 1); -has 'default' => (is => 'ro', isa => 'Str', required => 0); -has 'trigger' => (is => 'ro', isa => 'SQL::Translator::Object::Trigger', required => 0); +has 'name' => (is => 'ro', isa => Str, required => 1); +has 'type' => (is => 'ro', isa => Str, required => 1); +has 'size' => (is => 'ro', isa => Int, required => 1); +has 'nullable' => (is => 'ro', isa => Bool, required => 1, default => 1); +has 'default' => (is => 'ro', isa => Str, required => 0); +has 'trigger' => (is => 'ro', isa => Trigger, required => 0); 1; diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 6ac6e88..4713b9d 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -1,9 +1,10 @@ package SQL::Translator::Object::Constraint; use Moose; -use SQL::Translator::Types; +use MooseX::Types::Moose qw(ArrayRef Str); +use SQL::Translator::Types qw(Column); -has 'name' => (is => 'ro', isa => 'Str', required => 1); -has 'columns' => (is => 'ro', isa => 'ArrayRef[Column]', required => 1); -has 'type' => (is => 'ro', isa => 'Str', required => 1); +has 'name' => (is => 'ro', isa => Str, required => 1); +has 'columns' => (is => 'ro', isa => ArrayRef[Column], required => 1); +has 'type' => (is => 'ro', isa => Str, required => 1); 1; diff --git a/lib/SQL/Translator/Object/Index.pm b/lib/SQL/Translator/Object/Index.pm index 4f645a1..e3e4eea 100644 --- a/lib/SQL/Translator/Object/Index.pm +++ b/lib/SQL/Translator/Object/Index.pm @@ -1,9 +1,10 @@ package SQL::Translator::Object::Index; use Moose; -use SQL::Translator::Types; +use MooseX::Types::Moose qw(ArrayRef Str); +use SQL::Translator::Types qw(Column); -has 'name' => (is => 'ro', isa => 'Str', required => 1); -has 'columns' => (is => 'ro', isa => 'ArrayRef[Column]', required => 1); -has 'type' => (is => 'ro', isa => 'Str', required => 1); +has 'name' => (is => 'ro', isa => Str, required => 1); +has 'columns' => (is => 'ro', isa => ArrayRef[Column], required => 1); +has 'type' => (is => 'ro', isa => Str, required => 1); 1; diff --git a/lib/SQL/Translator/Object/Procedure.pm b/lib/SQL/Translator/Object/Procedure.pm index 580fee8..fe5cae3 100644 --- a/lib/SQL/Translator/Object/Procedure.pm +++ b/lib/SQL/Translator/Object/Procedure.pm @@ -1,7 +1,9 @@ package SQL::Translator::Object::Procedure; use Moose; +use MooseX::Types::Moose qw(Str); +use SQL::Translator::Types qw(); -has 'name' => (is => 'ro', isa => 'Str', required => 1); -has 'contents' => (is => 'ro', isa => 'Str', required => 1); +has 'name' => (is => 'ro', isa => Str, required => 1); +has 'contents' => (is => 'ro', isa => Str, required => 1); 1; diff --git a/lib/SQL/Translator/Object/Schema.pm b/lib/SQL/Translator/Object/Schema.pm index 4668ae0..babad8f 100644 --- a/lib/SQL/Translator/Object/Schema.pm +++ b/lib/SQL/Translator/Object/Schema.pm @@ -1,9 +1,10 @@ package SQL::Translator::Object::Schema; use Moose; -use SQL::Translator::Types; +use MooseX::Types::Moose qw(ArrayRef); +use SQL::Translator::Types qw(Procedure Table View); -has 'tables' => (is => 'ro', isa => 'ArrayRef[Table]', required => 1); -has 'views' => (is => 'ro', isa => 'ArrayRef[View]', required => 0); -has 'procedures' => (is => 'ro', isa => 'ArrayRef[Procedure]', required => 0); +has 'tables' => (is => 'ro', isa => ArrayRef[Table], required => 1); +has 'views' => (is => 'ro', isa => ArrayRef[View], required => 0); +has 'procedures' => (is => 'ro', isa => ArrayRef[Procedure], required => 0); 1; diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 4037ff0..da83e8e 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -1,10 +1,11 @@ package SQL::Translator::Object::Table; use Moose; -use SQL::Translator::Types; +use MooseX::Types::Moose qw(ArrayRef Str); +use SQL::Translator::Types qw(Column Constraint Index); -has 'name' => (is => 'ro', isa => 'Str', required => 1); -has 'columns' => (is => 'ro', isa => 'ArrayRef[Column]', required => 1); -has 'indexes' => (is => 'ro', isa => 'ArrayRef[Index]', required => 0); -has 'constraints' => (is => 'ro', isa => 'ArrayRef[Constraint]', required => 0); +has 'name' => (is => 'ro', isa => Str, required => 1); +has 'columns' => (is => 'ro', isa => ArrayRef[Column], required => 1); +has 'indexes' => (is => 'ro', isa => ArrayRef[Index], required => 0); +has 'constraints' => (is => 'ro', isa => ArrayRef[Constraint], required => 0); 1; diff --git a/lib/SQL/Translator/Object/Trigger.pm b/lib/SQL/Translator/Object/Trigger.pm index c9c9ed2..d752c86 100644 --- a/lib/SQL/Translator/Object/Trigger.pm +++ b/lib/SQL/Translator/Object/Trigger.pm @@ -1,6 +1,8 @@ package SQL::Translator::Object::Trigger; use Moose; +use MooseX::Types::Moose qw(Str); +use SQL::Translator::Types qw(); -has 'name' => (is => 'ro', isa => 'Str', required => 1); +has 'name' => (is => 'ro', isa => Str, required => 1); 1; diff --git a/lib/SQL/Translator/Object/View.pm b/lib/SQL/Translator/Object/View.pm index f0b4995..7c45d8d 100644 --- a/lib/SQL/Translator/Object/View.pm +++ b/lib/SQL/Translator/Object/View.pm @@ -1,7 +1,10 @@ package SQL::Translator::Object::View; use Moose; +use MooseX::Types::Moose qw(ArrayRef); +use SQL::Translator::Types qw(); extends 'SQL::Translator::Object::Table'; -has 'sql' => (is => 'ro', isa => 'Str', required => 1); + +has 'sql' => (is => 'ro', isa => Str, required => 1); 1; diff --git a/lib/SQL/Translator/Types.pm b/lib/SQL/Translator/Types.pm index 41da8bb..2fd0ba7 100644 --- a/lib/SQL/Translator/Types.pm +++ b/lib/SQL/Translator/Types.pm @@ -1,13 +1,13 @@ package SQL::Translator::Types; -use MooseX::Types -declare => [qw(Column Constraint Index Procedure Schema Table Trigger View)]; +use MooseX::Types -declare, [qw(Column Constraint Index Procedure Schema Table Trigger View)]; -subtype Column => as 'SQL::Translator::Object::Column'; -subtype Constraint => as 'SQL::Translator:Object::Constraint'; -subtype Index => as 'SQL::Translator:Object::Index'; -subtype Procedure => as 'SQL::Translator:Object::Procedure'; -subtype Schema => as 'SQL::Translator:Object::Schema'; -subtype Table => as 'SQL::Translator::Object::Table'; -subtype Trigger => as 'SQL::Translator:Object::Trigger'; -subtype View => as 'SQL::Translator:Object::View'; +class_type Column, { class => 'SQL::Translator::Object::Column' }; +class_type Constraint, { class => 'SQL::Translator:Object::Constraint' }; +class_type Index, { class => 'SQL::Translator:Object::Index' }; +class_type Procedure, { class => 'SQL::Translator:Object::Procedure' }; +class_type Schema, { class => 'SQL::Translator:Object::Schema' }; +class_type Table, { class => 'SQL::Translator::Object::Table' }; +class_type Trigger, { class => 'SQL::Translator:Object::Trigger' }; +class_type View, { class => 'SQL::Translator:Object::View' }; 1;