Re: Miscellaneous changes to plperl [PATCH]

From: Alex Hunsaker <badalex(at)gmail(dot)com>
To: Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Miscellaneous changes to plperl [PATCH]
Date: 2010-01-23 03:59:10
Message-ID: 34d269d41001221959l18d585bcgac843f7811e2fa51@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 14, 2010 at 09:07, Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com> wrote:
> - Allow (ineffective) use of 'require' in plperl
>    If the required module is not already loaded then it dies.
>    So "use strict;" now works in plperl.

[ BTW I think this is awesome! ]

Id vote for use warnings; as well.

> - Stored procedure subs are now given names.
>    The names are not visible in ordinary use, but they make
>    tools like Devel::NYTProf and Devel::Cover _much_ more useful.

This needs to quote at least '. Any others you can think of? Also I
think we should sort the imports in ::mkfunsort so that they are
stable.

The cleanups were nice, the code worked as described. Other than the
quoting issue it looks good to me. Find below an incremental patch
that fixes the items above.

diff --git a/src/pl/plperl/plc_perlboot.pl b/src/pl/plperl/plc_perlboot.pl
index daef469..fa5df0a 100644
--- a/src/pl/plperl/plc_perlboot.pl
+++ b/src/pl/plperl/plc_perlboot.pl
@@ -27,16 +27,14 @@ sub ::mkfuncsrc {
my $BEGIN = join "\n", map {
my $names = $imports->{$_} || [];
"$_->import(qw(@$names));"
- } keys %$imports;
+ } sort keys %$imports;
$BEGIN &&= "BEGIN { $BEGIN }";

$name =~ s/\\/\\\\/g;
$name =~ s/::|'/_/g; # avoid package delimiters
+ $name =~ s/'/\'/g;

- my $funcsrc;
- $funcsrc .= qq[ undef *{'$name'}; *{'$name'} = sub { $BEGIN
$prolog $src } ];
- #warn "plperl mkfuncsrc: $funcsrc\n";
- return $funcsrc;
+ return qq[ undef *{'$name'}; *{'$name'} = sub { $BEGIN $prolog $src } ];
}

# see also mksafefunc() in plc_safe_ok.pl
diff --git a/src/pl/plperl/plc_safe_ok.pl b/src/pl/plperl/plc_safe_ok.pl
index 8d35357..79d64ce 100644
--- a/src/pl/plperl/plc_safe_ok.pl
+++ b/src/pl/plperl/plc_safe_ok.pl
@@ -25,6 +25,7 @@ $PLContainer->share(qw[&elog &return_next
$PLContainer->permit(qw[caller]);
::safe_eval(q{
require strict;
+ require warnings;
require feature if $] >= 5.010000;
1;
}) or die $@;

Attachment Content-Type Size
plperl_misc_inc_ah.patch application/octet-stream 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-01-23 04:19:39 Improving the accuracy of estimate_num_groups()
Previous Message David E. Wheeler 2010-01-23 03:08:39 Re: 8.5 vs. 9.0, Postgres vs. PostgreSQL