From: Peter Rabbitson Date: Sat, 1 Jun 2013 20:02:17 +0000 (+0200) Subject: Pave the road to more global state X-Git-Tag: v1.74~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b9d807ed582eaefa2ec65ee33654b5dbb537f73;hp=5e4361304e44378efe29ad97c4430cd5f5c0f1ba;p=dbsrgits%2FSQL-Abstract.git Pave the road to more global state (Yes, yes an object is saner, but it means a thought out interface and all that, and then it means optimization of when and how do we do the modification passes, and really I am not after this stuff at the moment) --- diff --git a/t/10test.t b/t/10test.t index 6e4259f..19afd8f 100644 --- a/t/10test.t +++ b/t/10test.t @@ -153,7 +153,7 @@ my @sql_tests = ( }, { equal => 0, - parenthesis_significant => 1, + opts => { parenthesis_significant => 1 }, statements => [ q/SELECT foo FROM bar WHERE a = 1 AND b = 1 AND c = 1/, q/SELECT foo FROM bar WHERE (a = 1 AND b = 1 AND c = 1)/, @@ -164,7 +164,7 @@ my @sql_tests = ( }, { equal => 0, - parenthesis_significant => 1, + opts => { parenthesis_significant => 1 }, statements => [ q/SELECT foo FROM bar WHERE a = 1 OR b = 1 OR c = 1/, q/SELECT foo FROM bar WHERE (a = 1 OR b = 1) OR c = 1/, @@ -174,7 +174,7 @@ my @sql_tests = ( }, { equal => 0, - parenthesis_significant => 1, + opts => { parenthesis_significant => 1 }, statements => [ q/SELECT foo FROM bar WHERE (a = 1) AND (b = 1 OR c = 1 OR d = 1) AND (e = 1 AND f = 1)/, q/SELECT foo FROM bar WHERE a = 1 AND (b = 1 OR c = 1 OR d = 1) AND e = 1 AND (f = 1)/, @@ -260,7 +260,7 @@ my @sql_tests = ( }, { equal => 0, - parenthesis_significant => 1, + opts => { parenthesis_significant => 1 }, statements => [ q/SELECT foo FROM bar WHERE a IN (1,2,3)/, q/SELECT foo FROM bar WHERE a IN (1,3,2)/, @@ -943,14 +943,23 @@ use_ok('SQL::Abstract::Test', import => [qw( )]); for my $test (@sql_tests) { + + # this does not work on 5.8.8 and earlier :( + #local @{*SQL::Abstract::Test::}{keys %{$test->{opts}}} = map { \$_ } values %{$test->{opts}} + # if $test->{opts}; + + my %restore_globals; + + for (keys %{$test->{opts} || {} }) { + $restore_globals{$_} = ${${*SQL::Abstract::Test::}{$_}}; + ${*SQL::Abstract::Test::}{$_} = \ do { my $cp = $test->{opts}{$_} }; + } + my $statements = $test->{statements}; while (@$statements) { my $sql1 = shift @$statements; foreach my $sql2 (@$statements) { - no warnings qw/once/; # perl 5.10 is dumb - local $SQL::Abstract::Test::parenthesis_significant = $test->{parenthesis_significant} - if $test->{parenthesis_significant}; my $equal = eq_sql($sql1, $sql2); TODO: { @@ -975,6 +984,9 @@ for my $test (@sql_tests) { } } } + + ${*SQL::Abstract::Test::}{$_} = \$restore_globals{$_} + for keys %restore_globals; } for my $test (@bind_tests) {