=cut
-use Moo;
+use Moo 1.000003;
use SQL::Translator::Schema::Constants;
-use SQL::Translator::Utils qw(parse_list_arg ex2err throw);
+use SQL::Translator::Utils qw(ex2err throw);
+use SQL::Translator::Role::ListAttr;
use SQL::Translator::Types qw(schema_obj);
-use List::MoreUtils qw(uniq);
+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
-);
-
-our ( $TABLE_COUNT, $VIEW_COUNT );
+extends 'SQL::Translator::Schema::Object';
our $VERSION = '1.59';
=cut
-has fields => (
- is => 'rw',
- default => sub { [] },
- coerce => sub { [uniq @{parse_list_arg($_[0])}] },
-);
-
-around fields => sub {
- my $orig = shift;
- my $self = shift;
- my $fields = parse_list_arg( @_ );
- $self->$orig($fields) if @$fields;
-
- return wantarray ? @{ $self->$orig } : $self->$orig;
-};
+with ListAttr fields => ( uniq => 1 );
sub is_valid {
=cut
-has name => ( is => 'rw', coerce => sub { defined $_[0] ? $_[0] : '' }, default => sub { '' } );
+has name => ( is => 'rw', coerce => sub { defined $_[0] ? $_[0] : '' }, default => quote_sub(q{ '' }) );
=head2 options
=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 => ();
=head2 table
=cut
-has table => ( is => 'rw', isa => schema_obj('Table') );
+has table => ( is => 'rw', isa => schema_obj('Table'), weak_ref => 1 );
around table => \&ex2err;
throw("Invalid index type: $type") unless $VALID_INDEX_TYPE{$type};
},
coerce => sub { uc $_[0] },
- default => sub { 'NORMAL' },
+ default => quote_sub(q{ 'NORMAL' }),
);
around type => \&ex2err;
return 1;
};
-sub DESTROY {
- my $self = shift;
- undef $self->{'table'}; # destroy cyclical reference
-}
-
# Must come after all 'has' declarations
around new => \&ex2err;