Re: Miscellaneous changes to plperl [PATCH] - Mailing list pgsql-hackers

From Alex Hunsaker
Subject Re: Miscellaneous changes to plperl [PATCH]
Date
Msg-id 34d269d41001221959l18d585bcgac843f7811e2fa51@mail.gmail.com
Whole thread Raw
In response to Miscellaneous changes to plperl [PATCH]  (Tim Bunce <Tim.Bunce@pobox.com>)
Responses Re: Miscellaneous changes to plperl [PATCH]  ("David E. Wheeler" <david@kineticode.com>)
Re: Miscellaneous changes to plperl [PATCH]  (Tim Bunce <Tim.Bunce@pobox.com>)
List pgsql-hackers
On Thu, Jan 14, 2010 at 09:07, Tim Bunce <Tim.Bunce@pobox.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

pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: 8.5 vs. 9.0, Postgres vs. PostgreSQL
Next
From: Tom Lane
Date:
Subject: Improving the accuracy of estimate_num_groups()