Re: pl/perl thoughts

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pl/perl thoughts
Date: 2004-02-22 18:17:23
Message-ID: 4038F233.5040807@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


FWIW, I have now tested the scheme below, and it appears to work as
expected. I can't see any reason it should disturb any existing
functionality, unless people currently use plperl to store nonlexical
variables which might now clobber each other. I think it's worth doing,
for a small but nontrivial functionality gain. If nobody objects, I will
submit a patch and some docco on how to use it.

cheers

andrew

I wrote:

>>
>> Thus the following perl contained in plperl.c and executed on
>> interpreter startup:
>>
>> require Safe; SPI::bootstrap();
>> sub ::mksafefunc { my $x = new Safe;
>> $x->permit_only(':default');$x->permit(':base_math');
>> $x->share(qw[&elog &DEBUG &LOG &INFO &NOTICE &WARNING
>> &ERROR]);
>> return $x->reval(qq[sub { $_[0] }]); }
>> sub ::mkunsafefunc {return eval(qq[ sub { $_[0] } ]); }
>>
>> would become something like:
>>
>> require Safe; SPI::bootstrap();
>> use vars qw($PLContainer); $PLContainer = new
>> Safe("PLPerl");
>>
>> $PLContainer->permit_only(':default');$PLContainer->permit(':base_math');
>>
>> $PLContainer->share(qw[&elog &DEBUG &LOG &INFO &NOTICE
>> &WARNING &ERROR]);
>> sub ::mksafefunc { return $PLContainer->reval(qq[sub {
>> $_[0] }]); }
>> sub ::mkunsafefunc {return eval(qq[ sub { $_[0] } ]); }
>>
>> Now you could do something like this:
>>
>> create function myplperlfuncs() returns int language plperl as '
>> $datavar = "foo";
>> $funcvar = sub { return "bar"; };
>> return 1;
>> ';
>>
>> create function f1 () returns text language plperl as '
>> return $datavar;
>> ';
>>
>> create function f2() returns text language plperl as '
>> return &$funcvar();
>> ';
>>
>> At the start of your session you would issue "select
>> myplperlfuncs();" to preload the values, and thereafter you could
>> call f1() and f2() quite happily.
>>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Scott Goodwin 2004-02-22 18:19:24 Re: [HACKERS] Mac OS X, PostgreSQL, PL/Tcl
Previous Message Dave Cramer 2004-02-22 18:07:48 Re: Pl/Java - next step?