From: Laurent Dami Date: Wed, 12 Nov 2008 05:25:34 +0000 (+0000) Subject: fixed _refkind for \$object, \\$object. Added tests for _refkind X-Git-Tag: v1.70~264 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=90aab162eed6811e18e80f05d1c43c012b54daef;p=dbsrgits%2FSQL-Abstract.git fixed _refkind for \$object, \\$object. Added tests for _refkind --- diff --git a/MANIFEST b/MANIFEST index 5ca4d1a..039267f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -11,4 +11,6 @@ t/03values.t t/06order_by.t t/07subqueries.t t/08special_ops.t +t/09refkind.t + diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 8034548..b3c4581 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -871,23 +871,23 @@ sub _refkind { my ($self, $data) = @_; my $suffix = ''; my $ref; + my $n_steps = 0; - # $suffix = 'REF' x (length of ref chain, i. e. \\[] is REFREFREF) while (1) { - # blessed references are considered like scalars - last if blessed $data; - $suffix .= 'REF'; - $ref = ref $data; - - last if $ref ne 'REF'; + # blessed objects are treated like scalars + $ref = (blessed $data) ? '' : ref $data; + $n_steps += 1 if $ref; + last if $ref ne 'REF'; $data = $$data; } - return $ref ? $ref.$suffix : - defined $data ? 'SCALAR' : - 'UNDEF'; + my $base = $ref || (defined $data ? 'SCALAR' : 'UNDEF'); + + return $base . ('REF' x $n_steps); } + + sub _try_refkind { my ($self, $data) = @_; my @try = ($self->_refkind($data)); diff --git a/t/09refkind.t b/t/09refkind.t new file mode 100644 index 0000000..e51fcf0 --- /dev/null +++ b/t/09refkind.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; +use SQL::Abstract; + +plan tests => 13; + +my $obj = bless {}, "Foo::Bar"; + +is(SQL::Abstract->_refkind(undef), 'UNDEF', 'UNDEF'); + +is(SQL::Abstract->_refkind({}), 'HASHREF', 'HASHREF'); +is(SQL::Abstract->_refkind([]), 'ARRAYREF', 'ARRAYREF'); + +is(SQL::Abstract->_refkind(\{}), 'HASHREFREF', 'HASHREFREF'); +is(SQL::Abstract->_refkind(\[]), 'ARRAYREFREF', 'ARRAYREFREF'); + +is(SQL::Abstract->_refkind(\\{}), 'HASHREFREFREF', 'HASHREFREFREF'); +is(SQL::Abstract->_refkind(\\[]), 'ARRAYREFREFREF', 'ARRAYREFREFREF'); + +is(SQL::Abstract->_refkind("foo"), 'SCALAR', 'SCALAR'); +is(SQL::Abstract->_refkind(\"foo"), 'SCALARREF', 'SCALARREF'); +is(SQL::Abstract->_refkind(\\"foo"), 'SCALARREFREF', 'SCALARREFREF'); + +# objects are treated like scalars +is(SQL::Abstract->_refkind($obj), 'SCALAR', 'SCALAR'); +is(SQL::Abstract->_refkind(\$obj), 'SCALARREF', 'SCALARREF'); +is(SQL::Abstract->_refkind(\\$obj), 'SCALARREFREF', 'SCALARREFREF'); +