X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FSchema%2FTable.pm;h=2f36e9b7a1c4286150596b1ca3ce0450d4cc9051;hb=f56361ad7eea3245af7ec5b0eaed5ca439bd6168;hp=3712306f414d129211e1522daa535f5c3ab44f0d;hpb=45595850cc8937473606c3430c5fcbbd4b07a294;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Schema/Table.pm b/lib/SQL/Translator/Schema/Table.pm index 3712306..2f36e9b 100644 --- a/lib/SQL/Translator/Schema/Table.pm +++ b/lib/SQL/Translator/Schema/Table.pm @@ -19,9 +19,10 @@ C is the table object. =cut -use Moo; -use SQL::Translator::Utils qw(parse_list_arg ex2err throw); +use Moo 1.000003; +use SQL::Translator::Utils qw(parse_list_arg ex2err throw carp_ro); use SQL::Translator::Types qw(schema_obj); +use SQL::Translator::Role::ListAttr; use SQL::Translator::Schema::Constants; use SQL::Translator::Schema::Constraint; use SQL::Translator::Schema::Field; @@ -29,13 +30,9 @@ use SQL::Translator::Schema::Index; use Carp::Clan '^SQL::Translator'; use List::Util 'max'; +use Sub::Quote qw(quote_sub); -with qw( - SQL::Translator::Role::Error - SQL::Translator::Role::BuildArgs - SQL::Translator::Schema::Role::Extra - SQL::Translator::Schema::Role::Compare -); +extends 'SQL::Translator::Schema::Object'; our $VERSION = '1.59'; @@ -78,7 +75,7 @@ C object. has _constraints => ( is => 'ro', init_arg => undef, - default => sub { +[] }, + default => quote_sub(q{ +[] }), predicate => 1, lazy => 1, ); @@ -201,7 +198,7 @@ C object. has _indices => ( is => 'ro', init_arg => undef, - default => sub { [] }, + default => quote_sub(q{ [] }), predicate => 1, lazy => 1, ); @@ -285,7 +282,7 @@ existing field, you will get an error and the field will not be created. has _fields => ( is => 'ro', init_arg => undef, - default => sub { +{} }, + default => quote_sub(q{ +{} }), predicate => 1, lazy => 1 ); @@ -408,8 +405,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 { @@ -552,6 +549,8 @@ True if table has no data (non-key) fields and only uses single key joins. has is_trivial_link => ( is => 'lazy', init_arg => undef ); +around is_trivial_link => carp_ro('is_trivial_link'); + sub _build_is_trivial_link { my $self = shift; return 0 if $self->is_data; @@ -580,6 +579,8 @@ Returns true if the table has some non-key fields. has is_data => ( is => 'lazy', init_arg => undef ); +around is_data => carp_ro('is_data'); + sub _build_is_data { my $self = shift; @@ -600,7 +601,7 @@ Determine whether the table can link two arg tables via many-to-many. =cut -has _can_link => ( is => 'ro', init_arg => undef, default => sub { +{} } ); +has _can_link => ( is => 'ro', init_arg => undef, default => quote_sub(q{ +{} }) ); sub can_link { my ( $self, $table1, $table2 ) = @_; @@ -801,21 +802,7 @@ an array or array reference. =cut -has options => ( - is => 'rw', - default => sub { [] }, - coerce => \&parse_list_arg, -); - -around options => sub { - my $orig = shift; - my $self = shift; - my $options = parse_list_arg( @_ ); - - push @{ $self->$orig }, @$options; - - return wantarray ? @{ $self->$orig } : $self->$orig; -}; +with ListAttr options => ( append => 1 ); =head2 order @@ -825,7 +812,7 @@ Get or set the table'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 ) = @_;