From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org> |
Subject: | plperl strict mode |
Date: | 2005-05-21 20:04:36 |
Message-ID: | 428F9454.8090602@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
The attached patch (submitted for testing and comment) allows turning on
perl strict mode via a GUC setting for plperl/plperlu. (plplerlu users
would be able to turn it off again, but plperl users would not, I think.
Certainly not straightforwardly at least.
In order to protect legacy code, the default is to have strict mode off.
For those who are not perl savvy, strict mode disallows some
quick-and-dirty coding methods that are mostly really hangovers from the
days of perl 4, expecially use of undeclared variables and use of bare
words in circumstances where they might be ambiguous. Turning strict
mode on is a common requirement in corporate coding standards (including
some I have written).
This feature has been requested by several plperl users, as well as
scratching my own itch ;-)
Illustration: with this in postgresql.conf:
custom_variable_classes = 'plperl'
plperl.use_strict = true
it works like this:
andrew=# create or replace function foo() returns text language plperl
as $$ $x = 1; return 'hello'; $$;
CREATE FUNCTION
andrew=# select foo();
ERROR: creation of Perl function failed: Global symbol "$x" requires
explicit package name at (eval 11) line 1.
andrew=# create or replace function foo() returns text language plperl
as $$ my $x = 1; return 'hello'; $$;
CREATE FUNCTION
andrew=# select foo();
foo
-------
hello
Note that in the second case $x is declared as a lexical variable,
whereas in the first (failing) case it is an undeclared global.
There is one problem ... it blew up if I used a context setting of
anything more strict than PGC_USERSET. But rally, that's not good. It
needs to be set at the time we make the functions that set up the
anonymous subs ... i.e. at interpreter startup. Anything later will be
ginored anyway. So I'd like to find a way to do that.
cheers
andrew
Attachment | Content-Type | Size |
---|---|---|
strictplperl2.patch | text/x-patch | 5.1 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2005-05-21 20:58:42 | bug fix - plperl %_SHARED misspelled |
Previous Message | Simon Riggs | 2005-05-21 17:38:02 | Re: WIP XLog Switch |