Re: pl/perl thoughts
От | Andrew Dunstan |
---|---|
Тема | Re: pl/perl thoughts |
Дата | |
Msg-id | 4038F233.5040807@dunslane.net обсуждение исходный текст |
Ответ на | pl/perl thoughts (Andrew Dunstan <andrew@dunslane.net>) |
Список | 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. >> >
В списке pgsql-hackers по дате отправления: