From: Peter Rabbitson Date: Sun, 14 Sep 2014 17:45:01 +0000 (+0200) Subject: An arrayref makes sense for literals, but no sense for values X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=966200cc8a0d73449caac4beb3a7f3c60580b0de;p=scpubgit%2FQ-Branch.git An arrayref makes sense for literals, but no sense for values Change the API before it goes live (extra benefit - no mixing up of the functions by accident) --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 0c3f11c..56bd631 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -84,12 +84,12 @@ sub is_literal_value ($) { # FIXME XSify - this can be done so much more efficiently sub is_plain_value ($) { no strict 'refs'; - ! length ref $_[0] ? [ $_[0] ] + ! length ref $_[0] ? \($_[0]) : ( ref $_[0] eq 'HASH' and keys %{$_[0]} == 1 and exists $_[0]->{-value} - ) ? [ $_[0]->{-value} ] + ) ? \($_[0]->{-value}) : ( # reuse @_ for even moar speedz defined ( $_[1] = Scalar::Util::blessed $_[0] ) @@ -124,7 +124,7 @@ sub is_plain_value ($) { ) ) ) - ) ? [ $_[0] ] + ) ? \($_[0]) : undef; } @@ -2148,9 +2148,8 @@ module: =back -On failure returns C, on sucess returns a reference to a single -element array containing the string-version of the supplied argument or -C<[ undef ]> in case of an undefined initial argument. +On failure returns C, on sucess returns a B reference +to the original supplied argument. =head2 is_literal_value @@ -2167,8 +2166,8 @@ module: =back -On failure returns C, on sucess returns a reference to an array -cotaining the unpacked version of the supplied literal SQL and bind values. +On failure returns C, on sucess returns an B reference +containing the unpacked version of the supplied literal SQL and bind values. =head1 WHERE CLAUSES diff --git a/t/23_is_X_value.t b/t/23_is_X_value.t index df3b0ea..8f37f0b 100644 --- a/t/23_is_X_value.t +++ b/t/23_is_X_value.t @@ -142,7 +142,7 @@ for my $case ( if (STRINGIFIER_CAN_RETURN_IVS and $can_cmp) { is_deeply( is_plain_value $num, - [ $num ], + \$num, "stringification detected on $case->{class}", ) || diag explain $case; } @@ -150,13 +150,13 @@ for my $case ( # is_deeply does not do nummify/stringify cmps properly # but we can always compare the ice ok( - ( nfreeze( is_plain_value $num ) eq nfreeze( [ $num ] ) ), + ( nfreeze( is_plain_value $num ) eq nfreeze( \$num ) ), "stringification without cmp capability detected on $case->{class}" ) || diag explain $case; } is ( - refaddr( ( is_plain_value($num)||[] )->[0] ), + refaddr( ${is_plain_value($num)} ), refaddr $num, "Same reference (blessed object) returned", ); @@ -178,7 +178,7 @@ lives_ok { cmp_ok(--$num, 'eq', 23, 'test overloaded object compares correctly'); is_deeply( is_plain_value $num, - [ 23 ], + \23, 'fallback stringification detected' ); cmp_ok(--$num, 'eq', 22, 'test overloaded object compares correctly'); @@ -188,7 +188,7 @@ lives_ok { is_deeply is_plain_value { -value => [] }, - [ [] ], + \[], '-value recognized' ; @@ -203,7 +203,7 @@ for ([], {}, \'') { for (undef, { -value => undef }) { is_deeply is_plain_value $_, - [ undef ], + \undef, 'NULL -value recognized' ; }