From: Matt S Trout Date: Sun, 31 Jul 2011 20:20:20 +0000 (+0000) Subject: annihilate refkind stupidity X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4f4bff195663da3610cdf396b60fe96b61847f27;p=dbsrgits%2FSQL-Abstract.git annihilate refkind stupidity --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 606ef6d..51b733b 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -875,70 +875,6 @@ sub _sqlcase { 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 #====================================================================== diff --git a/t/09refkind.t b/t/09refkind.t deleted file mode 100644 index 1044231..0000000 --- a/t/09refkind.t +++ /dev/null @@ -1,31 +0,0 @@ -#!/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'); -