On Wed, Jan 12, 2011 at 14:45, Andrew Dunstan <and...@dunslane.net> wrote:
>
> What I was casting a bit of doubt on upthread was whether or not this would
> work without possibly breaking some code, in possibly silent or obscure
> ways.

I can't see how it would break, unless we did it wrong...

> If I'm wrong about that, then by all means let's use some perl Magic
> (that's a technical term) to achieve this. IIRC Alex recently posted some
> code that might be instructive about this.

There might be a more gutsy way to do this so that 'ref' gives you
back what you expected (would that be 'ARRAY' or 'SCALAR' ?), but
there is a simple pure perl solution using overload:
package PLPerl::ArgArray;
use overload '""' => \&to_str;

sub new
{
  # note we bless an arrayref here instead of the usual hashref so
  # you can use this 'object' as a normal array
  return bless([@_], ... );
}

sub to_str
{
  my $self = shift;
  # yeah this is not right not correct :P
  # we could also die here with something like "You are trying to use
an Array as a string" or whatever
  return join(',', map { '{'. $_ .'}' } @{$self});
}
---------

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to