=cut
use Moo;
-use SQL::Translator::Utils qw(parse_list_arg ex2err);
+use SQL::Translator::Utils qw(ex2err);
use SQL::Translator::Types qw(schema_obj);
-use List::MoreUtils qw(uniq);
+use SQL::Translator::Role::ListAttr;
+use Sub::Quote qw(quote_sub);
extends 'SQL::Translator::Schema::Object';
=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 );
=head2 tables
=cut
-has tables => (
- is => 'rw',
- default => sub { [] },
- coerce => sub { [uniq @{parse_list_arg($_[0])}] },
-);
-
-around tables => 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 tables => ( uniq => 1 );
=head2 options
=cut
-has options => (
- is => 'rw',
- default => sub { [] },
- coerce => sub { [uniq @{parse_list_arg($_[0])}] },
-);
-
-around options => sub {
- my $orig = shift;
- my $self = shift;
- my $options = parse_list_arg( @_ );
-
- if ( @$options ) {
- $self->$orig([ @{$self->$orig}, @$options ])
- }
-
- return wantarray ? @{ $self->$orig } : $self->$orig;
-};
+with ListAttr options => ( uniq => 1, append => 1 );
sub is_valid {
=cut
-has name => ( is => 'rw', default => sub { '' } );
+has name => ( is => 'rw', default => quote_sub(q{ '' }) );
=head2 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 ) = @_;
=cut
-has sql => ( is => 'rw', default => sub { '' } );
+has sql => ( is => 'rw', default => quote_sub(q{ '' }) );
=head2 schema