From 6b97e437ca20cbfcff059c668516c59914f5ba4d Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 12 Oct 2005 14:28:33 +0000 Subject: [PATCH] Add warning about plperl nested named subroutines Andrew Dunstan --- doc/src/sgml/plperl.sgml | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/plperl.sgml b/doc/src/sgml/plperl.sgml index f1a99a1f99..9ae95feb1b 100644 --- a/doc/src/sgml/plperl.sgml +++ b/doc/src/sgml/plperl.sgml @@ -1,5 +1,5 @@ @@ -53,22 +53,34 @@ CREATE FUNCTION funcname (argument-types # PL/Perl function body $$ LANGUAGE plperl; - The body of the function is ordinary Perl code. A PL/Perl function must + The body of the function is ordinary Perl code. In fact, the PL/Perl + glue code wraps it inside a Perl subroutine. A PL/Perl function must always return a scalar value. You can return more complex structures (arrays, records, and sets) by returning a reference, as discussed below. Never return a list. + - The syntax of the CREATE FUNCTION command requires - the function body to be written as a string constant. It is usually - most convenient to use dollar quoting (see ) for the string constant. - If you choose to use regular single-quoted string constant syntax, - you must escape single quote marks (') and backslashes - (\) used in the body of the function, typically by - doubling them (see ). + The use of named nested subroutines is dangerous in Perl, especially if + they refer to lexical variables in the enclosing scope. Because a PL/Perl + function is wrapped in a subroutine, any named subroutine you create will + be nested. In general, it is far safer to create anonymous subroutines + which you call via a coderef. See the perldiag + man page for more details. + + + + The syntax of the CREATE FUNCTION command requires + the function body to be written as a string constant. It is usually + most convenient to use dollar quoting (see ) for the string constant. + If you choose to use regular single-quoted string constant syntax, + you must escape single quote marks (') and backslashes + (\) used in the body of the function, typically by + doubling them (see ). + Arguments and results are handled as in any other Perl subroutine: -- 2.40.0