From: Johannes Plunien Date: Tue, 17 Mar 2009 09:48:06 +0000 (+0000) Subject: New method to clear out extra attributes X-Git-Tag: v0.11008~218 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=12018c0920bca7f83d7d939a704a8f6dfaaf2dce;p=dbsrgits%2FSQL-Translator.git New method to clear out extra attributes --- diff --git a/lib/SQL/Translator/Schema/Object.pm b/lib/SQL/Translator/Schema/Object.pm index b58f16c..4325424 100644 --- a/lib/SQL/Translator/Schema/Object.pm +++ b/lib/SQL/Translator/Schema/Object.pm @@ -151,6 +151,32 @@ Returns a hash or a hashref. return wantarray ? %$extra : $extra; } +# ---------------------------------------------------------------------- +sub remove_extra { + +=head2 remove_extra + +L can only be used to get or set "extra" attributes but not to +remove some. Call with no args to remove all extra attributes that +have been set before. Call with a list of key names to remove +certain extra attributes only. + + # remove all extra attributes + $field->remove_extra(); + + # remove timezone and locale attributes only + $field->remove_extra(qw/timezone locale/); + +=cut + + my ( $self, @keys ) = @_; + unless (@keys) { + $self->{'extra'} = {}; + } + else { + delete $self->{'extra'}{$_} for @keys; + } +} # ---------------------------------------------------------------------- sub equals { diff --git a/t/38-mysql-producer.t b/t/38-mysql-producer.t index ae2c64d..16151f5 100644 --- a/t/38-mysql-producer.t +++ b/t/38-mysql-producer.t @@ -19,7 +19,7 @@ use FindBin qw/$Bin/; #============================================================================= BEGIN { - maybe_plan(32, + maybe_plan(35, 'YAML', 'SQL::Translator::Producer::MySQL', 'Test::Differences', @@ -399,4 +399,27 @@ is ( SELECT id, name FROM thing )"; is($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL'); + + { + my %extra = $view1->extra; + is_deeply \%extra, + { + 'mysql_algorithm' => 'MERGE', + 'mysql_definer' => 'CURRENT_USER', + 'mysql_security' => 'DEFINER' + }, + 'Extra attributes'; + } + + $view1->remove_extra(qw/mysql_definer mysql_security/); + { + my %extra = $view1->extra; + is_deeply \%extra, { 'mysql_algorithm' => 'MERGE', }, 'Extra attributes after first reset_extra call'; + } + + $view1->remove_extra(); + { + my %extra = $view1->extra; + is_deeply \%extra, {}, 'Extra attributes completely removed'; + } }