From: Peter Rabbitson Date: Fri, 5 Sep 2014 08:37:21 +0000 (+0200) Subject: Make sure is_plain_value returns the actual object pre-stringify X-Git-Tag: v1.79~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Abstract.git;a=commitdiff_plain;h=d0ecdb28a6c6ba2112bf49e3fa687ee989353a9f Make sure is_plain_value returns the actual object pre-stringify This is important since DBIC is starting to heavily rely on the contents of the returned [] --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 63d6c2e..0c3f11c 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -124,7 +124,7 @@ sub is_plain_value ($) { ) ) ) - ) ? [ "$_[0]" ] + ) ? [ $_[0] ] : undef; } diff --git a/t/23_is_X_value.t b/t/23_is_X_value.t index b919e0a..79c003e 100644 --- a/t/23_is_X_value.t +++ b/t/23_is_X_value.t @@ -3,6 +3,8 @@ use strict; use Test::More; use Test::Exception; +use Scalar::Util 'refaddr'; +use Storable 'nfreeze'; use SQL::Abstract qw(is_plain_value is_literal_value); @@ -54,15 +56,26 @@ lives_ok { ok( ( $nummifiable_maybefallback_num + 1) == 43 ) }; - my $can_str = !! eval { "$nummifiable_maybefallback_num" }; + my $is_pv_res = is_plain_value $nummifiable_maybefallback_num; - lives_ok { - is_deeply( - is_plain_value $nummifiable_maybefallback_num, - ( $can_str ? [ 42 ] : undef ), - 'parent-disabled-fallback stringification detected same as perl', + # this perl can recognize inherited fallback + if ( !! eval { "$nummifiable_maybefallback_num" } ) { + # we may *not* be able to compare, due to ""-derived-eq fallbacks missing, + # but we can always compare the ice + ok ( + ( nfreeze( $is_pv_res ) eq nfreeze( [ $nummifiable_maybefallback_num ] ) ), + 'parent-disabled-fallback stringification matches that of perl' ); - }; + + is ( + refaddr($is_pv_res->[0]), + refaddr $nummifiable_maybefallback_num, + "Same reference (blessed object) returned", + ); + } + else { + is $is_pv_res, undef, 'parent-disabled-fallback stringification matches that of perl'; + } } is_deeply