return $_[0]->{case} ? $_[1] : uc($_[1]);
}
-
-#======================================================================
-# DISPATCHING FROM REFKIND
-#======================================================================
-
-sub _refkind {
- my ($self, $data) = @_;
-
- return 'UNDEF' unless defined $data;
-
- # blessed objects are treated like scalars
- my $ref = (Scalar::Util::blessed $data) ? '' : ref $data;
-
- return 'SCALAR' unless $ref;
-
- my $n_steps = 1;
- while ($ref eq 'REF') {
- $data = $$data;
- $ref = (Scalar::Util::blessed $data) ? '' : ref $data;
- $n_steps++ if $ref;
- }
-
- return ($ref||'SCALAR') . ('REF' x $n_steps);
-}
-
-sub _try_refkind {
- my ($self, $data) = @_;
- my @try = ($self->_refkind($data));
- push @try, 'SCALAR_or_UNDEF' if $try[0] eq 'SCALAR' || $try[0] eq 'UNDEF';
- push @try, 'FALLBACK';
- return \@try;
-}
-
-sub _METHOD_FOR_refkind {
- my ($self, $meth_prefix, $data) = @_;
-
- my $method;
- for (@{$self->_try_refkind($data)}) {
- $method = $self->can($meth_prefix."_".$_)
- and last;
- }
-
- return $method || puke "cannot dispatch on '$meth_prefix' for ".$self->_refkind($data);
-}
-
-
-sub _SWITCH_refkind {
- my ($self, $data, $dispatch_table) = @_;
-
- my $coderef;
- for (@{$self->_try_refkind($data)}) {
- $coderef = $dispatch_table->{$_}
- and last;
- }
-
- puke "no dispatch entry for ".$self->_refkind($data)
- unless $coderef;
-
- $coderef->();
-}
-
-
-
-
#======================================================================
# VALUES, GENERATE, AUTOLOAD
#======================================================================
+++ /dev/null
-#!/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');
-