From: Dagfinn Ilmari Mannsåker Date: Sat, 4 Aug 2012 17:44:41 +0000 (+0100) Subject: Filter undef from all constructor args X-Git-Tag: v0.11013_01~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=46ad748fcf9f976bb6ce2549f135023e3d66b2a8;p=dbsrgits%2FSQL-Translator.git Filter undef from all constructor args This was the old behaviour, but only Field and Constraint seemed to require it in the tests. Better put it back anyway. --- diff --git a/lib/SQL/Translator/Schema/Constraint.pm b/lib/SQL/Translator/Schema/Constraint.pm index ac4f63a..e4f3a9d 100644 --- a/lib/SQL/Translator/Schema/Constraint.pm +++ b/lib/SQL/Translator/Schema/Constraint.pm @@ -30,6 +30,7 @@ use SQL::Translator::Types qw(schema_obj); use List::MoreUtils qw(uniq); with qw( + SQL::Translator::Schema::Role::BuildArgs SQL::Translator::Schema::Role::Extra SQL::Translator::Schema::Role::Error SQL::Translator::Schema::Role::Compare @@ -73,7 +74,7 @@ around BUILDARGS => sub { 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}; diff --git a/lib/SQL/Translator/Schema/Field.pm b/lib/SQL/Translator/Schema/Field.pm index 6f60ea6..2443505 100644 --- a/lib/SQL/Translator/Schema/Field.pm +++ b/lib/SQL/Translator/Schema/Field.pm @@ -28,6 +28,7 @@ use SQL::Translator::Types qw(schema_obj); use SQL::Translator::Utils qw(parse_list_arg ex2err throw); with qw( + SQL::Translator::Schema::Role::BuildArgs SQL::Translator::Schema::Role::Extra SQL::Translator::Schema::Role::Error SQL::Translator::Schema::Role::Compare @@ -88,19 +89,6 @@ Object constructor. table => $table, ); -=cut - -around BUILDARGS => sub { - my $orig = shift; - my $self = shift; - my $args = $self->$orig(@_); - - foreach my $arg (keys %{$args}) { - delete $args->{$arg} unless defined($args->{$arg}); - } - return $args; -}; - =head2 comments Get or set the comments on a field. May be called several times to diff --git a/lib/SQL/Translator/Schema/Index.pm b/lib/SQL/Translator/Schema/Index.pm index 3084ca3..ae8313e 100644 --- a/lib/SQL/Translator/Schema/Index.pm +++ b/lib/SQL/Translator/Schema/Index.pm @@ -32,6 +32,7 @@ use SQL::Translator::Types qw(schema_obj); use List::MoreUtils qw(uniq); with qw( + SQL::Translator::Schema::Role::BuildArgs SQL::Translator::Schema::Role::Extra SQL::Translator::Schema::Role::Error SQL::Translator::Schema::Role::Compare diff --git a/lib/SQL/Translator/Schema/Procedure.pm b/lib/SQL/Translator/Schema/Procedure.pm index 554a496..0fd5c09 100644 --- a/lib/SQL/Translator/Schema/Procedure.pm +++ b/lib/SQL/Translator/Schema/Procedure.pm @@ -33,6 +33,7 @@ use SQL::Translator::Types qw(schema_obj); use List::MoreUtils qw(uniq); with qw( + SQL::Translator::Schema::Role::BuildArgs SQL::Translator::Schema::Role::Extra SQL::Translator::Schema::Role::Error SQL::Translator::Schema::Role::Compare diff --git a/lib/SQL/Translator/Schema/Role/BuildArgs.pm b/lib/SQL/Translator/Schema/Role/BuildArgs.pm new file mode 100644 index 0000000..295dffb --- /dev/null +++ b/lib/SQL/Translator/Schema/Role/BuildArgs.pm @@ -0,0 +1,15 @@ +package SQL::Translator::Schema::Role::BuildArgs; +use Moo::Role; + +around BUILDARGS => sub { + my $orig = shift; + my $self = shift; + my $args = $self->$orig(@_); + + foreach my $arg (keys %{$args}) { + delete $args->{$arg} unless defined($args->{$arg}); + } + return $args; +}; + +1; diff --git a/lib/SQL/Translator/Schema/Table.pm b/lib/SQL/Translator/Schema/Table.pm index 069695a..442ad91 100644 --- a/lib/SQL/Translator/Schema/Table.pm +++ b/lib/SQL/Translator/Schema/Table.pm @@ -31,6 +31,7 @@ use Carp::Clan '^SQL::Translator'; use List::Util 'max'; with qw( + SQL::Translator::Schema::Role::BuildArgs SQL::Translator::Schema::Role::Extra SQL::Translator::Schema::Role::Error SQL::Translator::Schema::Role::Compare diff --git a/lib/SQL/Translator/Schema/Trigger.pm b/lib/SQL/Translator/Schema/Trigger.pm index df72521..419effd 100644 --- a/lib/SQL/Translator/Schema/Trigger.pm +++ b/lib/SQL/Translator/Schema/Trigger.pm @@ -34,6 +34,7 @@ use SQL::Translator::Types qw(schema_obj); use List::MoreUtils qw(uniq); with qw( + SQL::Translator::Schema::Role::BuildArgs SQL::Translator::Schema::Role::Extra SQL::Translator::Schema::Role::Error SQL::Translator::Schema::Role::Compare diff --git a/lib/SQL/Translator/Schema/View.pm b/lib/SQL/Translator/Schema/View.pm index 51b76ec..6da6b95 100644 --- a/lib/SQL/Translator/Schema/View.pm +++ b/lib/SQL/Translator/Schema/View.pm @@ -29,6 +29,7 @@ use SQL::Translator::Types qw(schema_obj); use List::MoreUtils qw(uniq); with qw( + SQL::Translator::Schema::Role::BuildArgs SQL::Translator::Schema::Role::Extra SQL::Translator::Schema::Role::Error SQL::Translator::Schema::Role::Compare