[Zope-Perl] Calling python functions with keyword arguments from perl

Gisle Aas gisle@ActiveState.com
15 Aug 2000 23:09:52 +0200


Gisle Aas <gisle@ActiveState.com> writes:

> Another silly(?) idea. We could misuse globs, as I can't see a reason
> why you would want to pass them to a python function otherwise:
> 
>    $obj->foo($pos1, $pos2, *key1 => $val1, *key2 => $val2);
> 
> This is kind of similar to :keyword symbols used in Lisp.  One
> downside is that these symbols seems to stick forever in the symbol
> table after use.

Actually, I think I like this idea.  It can be implemented as a
wrapper around apply() quite cheaply like this:

foo(3, 4, *f => 3);

sub foo {
  my $kw;
  while (@_ >= 2 && ref(\$_[-2]) eq "GLOB") {
      my($key, $val) = splice(@_, -2);
      $kw->{substr($key, index($key, "::")+2)} = $val;
  }

  # show what apply arguments to pass on
  use Data::Dump;
  print "Python::apply" . Data::Dump::dump("foo", \@_, $kw) . "\n";

}