use Moo;
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);
-with qw(
- 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';
my $args = $self->$orig(@_);
foreach my $arg (keys %{$args}) {
- delete $args->{$arg} if !defined($args->{$arg}) || (ref($args->{$arg}) eq "ARRAY" && !@{$args->{$arg}});
+ delete $args->{$arg} if ref($args->{$arg}) eq "ARRAY" && !@{$args->{$arg}};
}
if (exists $args->{fields}) {
$args->{field_names} = delete $args->{fields};
=cut
-has field_names => (
- is => 'rw',
- default => sub { [] },
- coerce => sub { [uniq @{parse_list_arg($_[0])}] },
-);
-
-around field_names => sub {
- my $orig = shift;
- my $self = shift;
- my $fields = parse_list_arg( @_ );
- $self->$orig($fields) if @$fields;
-
- $fields = $self->$orig;
- return wantarray ? @{$fields}
- : @{$fields} ? $fields
- : undef;
-};
+with ListAttr field_names => ( uniq => 1, undef_if_empty => 1 );
=head2 match_type
=cut
-has options => ( is => 'rw', coerce => \&parse_list_arg, default => sub { [] } );
-
-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 on_delete
=cut
-has reference_fields => (
- is => 'rw',
- coerce => sub { [uniq @{parse_list_arg($_[0])}] },
+with ListAttr reference_fields => (
+ may_throw => 1,
builder => 1,
lazy => 1,
);
-around reference_fields => sub {
- my $orig = shift;
- my $self = shift;
- my $fields = parse_list_arg( @_ );
- $self->$orig($fields) if @$fields;
-
- $fields = ex2err($orig, $self) or return;
- return wantarray ? @{$fields} : $fields
-};
-
sub _build_reference_fields {
my ($self) = @_;
=cut
-has table => ( is => 'rw', isa => schema_obj('Table') );
+has table => ( is => 'rw', isa => schema_obj('Table'), weak_ref => 1 );
around table => \&ex2err;
return 1;
};
-sub DESTROY {
- my $self = shift;
- undef $self->{'table'}; # destroy cyclical reference
-}
-
# Must come after all 'has' declarations
around new => \&ex2err;