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));
--- /dev/null
+#!/usr/bin/perl\r
+\r
+use strict;\r
+use warnings;\r
+use Test::More;\r
+use SQL::Abstract;\r
+\r
+plan tests => 13;\r
+\r
+my $obj = bless {}, "Foo::Bar";\r
+\r
+is(SQL::Abstract->_refkind(undef), 'UNDEF', 'UNDEF');\r
+\r
+is(SQL::Abstract->_refkind({}), 'HASHREF', 'HASHREF');\r
+is(SQL::Abstract->_refkind([]), 'ARRAYREF', 'ARRAYREF');\r
+\r
+is(SQL::Abstract->_refkind(\{}), 'HASHREFREF', 'HASHREFREF');\r
+is(SQL::Abstract->_refkind(\[]), 'ARRAYREFREF', 'ARRAYREFREF');\r
+\r
+is(SQL::Abstract->_refkind(\\{}), 'HASHREFREFREF', 'HASHREFREFREF');\r
+is(SQL::Abstract->_refkind(\\[]), 'ARRAYREFREFREF', 'ARRAYREFREFREF');\r
+\r
+is(SQL::Abstract->_refkind("foo"), 'SCALAR', 'SCALAR');\r
+is(SQL::Abstract->_refkind(\"foo"), 'SCALARREF', 'SCALARREF');\r
+is(SQL::Abstract->_refkind(\\"foo"), 'SCALARREFREF', 'SCALARREFREF');\r
+\r
+# objects are treated like scalars\r
+is(SQL::Abstract->_refkind($obj), 'SCALAR', 'SCALAR');\r
+is(SQL::Abstract->_refkind(\$obj), 'SCALARREF', 'SCALARREF');\r
+is(SQL::Abstract->_refkind(\\$obj), 'SCALARREFREF', 'SCALARREFREF');\r
+\r