File tree 8 files changed +303
-201
lines changed 8 files changed +303
-201
lines changed Original file line number Diff line number Diff line change 1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.71 2009/11/29 03: 02:27 tgl Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.72 2010/01/09 02:40:50 adunstan Exp $ -->
2
2
3
3
<chapter id="plperl">
4
4
<title>PL/Perl - Perl Procedural Language</title>
14
14
<para>
15
15
PL/Perl is a loadable procedural language that enables you to write
16
16
<productname>PostgreSQL</productname> functions in the
17
- <ulink url="http://www.perl.com ">Perl programming language</ulink>.
17
+ <ulink url="http://www.perl.org ">Perl programming language</ulink>.
18
18
</para>
19
19
20
20
<para>
@@ -313,7 +313,8 @@ SELECT * FROM perl_set();
313
313
use strict;
314
314
</programlisting>
315
315
in the function body. But this only works in <application>PL/PerlU</>
316
- functions, since <literal>use</> is not a trusted operation. In
316
+ functions, since the <literal>use</> triggers a <literal>require</>
317
+ which is not a trusted operation. In
317
318
<application>PL/Perl</> functions you can instead do:
318
319
<programlisting>
319
320
BEGIN { strict->import(); }
Original file line number Diff line number Diff line change 1
1
# Makefile for PL/Perl
2
- # $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.37 2009/06/05 18:29:56 adunstan Exp $
2
+ # $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.38 2010/01/09 02:40:50 adunstan Exp $
3
3
4
4
subdir = src/pl/plperl
5
5
top_builddir = ../../..
@@ -45,6 +45,11 @@ PSQLDIR = $(bindir)
45
45
46
46
include $(top_srcdir ) /src/Makefile.shlib
47
47
48
+ plperl.o : perlchunks.h
49
+
50
+ perlchunks.h : plc_* .pl
51
+ $(PERL ) text2macro.pl --strip=' ^(\#.*|\s*)$$' plc_* .pl > perlchunks.htmp
52
+ mv perlchunks.htmp perlchunks.h
48
53
49
54
all : all-lib
50
55
@@ -65,7 +70,7 @@ submake:
65
70
$(MAKE ) -C $(top_builddir ) /src/test/regress pg_regress$(X )
66
71
67
72
clean distclean maintainer-clean : clean-lib
68
- rm -f SPI.c $(OBJS )
73
+ rm -f SPI.c $(OBJS ) perlchunks.htmp perlchunks.h
69
74
rm -rf results
70
75
rm -f regression.diffs regression.out
71
76
Original file line number Diff line number Diff line change
1
+ SPI::bootstrap();
2
+ use vars qw( %_SHARED) ;
3
+
4
+ sub ::plperl_warn {
5
+ (my $msg = shift ) =~ s /\( eval \d +\) // g ;
6
+ &elog(&NOTICE, $msg );
7
+ }
8
+ $SIG {__WARN__ } = \&::plperl_warn;
9
+
10
+ sub ::plperl_die {
11
+ (my $msg = shift ) =~ s /\( eval \d +\) // g ;
12
+ die $msg ;
13
+ }
14
+ $SIG {__DIE__ } = \&::plperl_die;
15
+
16
+ sub ::mkunsafefunc {
17
+ my $ret = eval (qq[ sub { $_ [0] $_ [1] } ] );
18
+ $@ =~ s /\( eval \d +\) // g if $@ ;
19
+ return $ret ;
20
+ }
21
+
22
+ use strict;
23
+
24
+ sub ::mk_strict_unsafefunc {
25
+ my $ret = eval (qq[ sub { use strict; $_ [0] $_ [1] } ] );
26
+ $@ =~ s /\( eval \d +\) // g if $@ ;
27
+ return $ret ;
28
+ }
29
+
30
+ sub ::_plperl_to_pg_array {
31
+ my $arg = shift ;
32
+ ref $arg eq ' ARRAY' || return $arg ;
33
+ my $res = ' ' ;
34
+ my $first = 1;
35
+ foreach my $elem (@$arg ) {
36
+ $res .= ' , ' unless $first ; $first = undef ;
37
+ if (ref $elem ) {
38
+ $res .= _plperl_to_pg_array($elem );
39
+ }
40
+ elsif (defined ($elem )) {
41
+ my $str = qq( $elem ) ;
42
+ $str =~ s / ([\"\\ ])/ \\ $1 / g ;
43
+ $res .= qq( \" $str \" ) ;
44
+ }
45
+ else {
46
+ $res .= ' NULL' ;
47
+ }
48
+ }
49
+ return qq( {$res }) ;
50
+ }
Original file line number Diff line number Diff line change
1
+ use vars qw( $PLContainer) ;
2
+
3
+ $PLContainer = new Safe(' PLPerl' );
4
+ $PLContainer -> permit_only(' :default' );
5
+ $PLContainer -> share(qw[ &elog &ERROR] );
6
+
7
+ my $msg = ' trusted Perl functions disabled - please upgrade Perl Safe module to version 2.09 or later' ;
8
+ sub ::mksafefunc {
9
+ return $PLContainer -> reval(qq[ sub { elog(ERROR,'$msg ') }] );
10
+ }
11
+
12
+ sub ::mk_strict_safefunc {
13
+ return $PLContainer -> reval(qq[ sub { elog(ERROR,'$msg ') }] );
14
+ }
15
+
Original file line number Diff line number Diff line change
1
+ use vars qw( $PLContainer) ;
2
+
3
+ $PLContainer = new Safe(' PLPerl' );
4
+ $PLContainer -> permit_only(' :default' );
5
+ $PLContainer -> permit(qw[ :base_math !:base_io sort time] );
6
+
7
+ $PLContainer -> share(qw[ &elog &return_next
8
+ &spi_query &spi_fetchrow &spi_cursor_close &spi_exec_query
9
+ &spi_prepare &spi_exec_prepared &spi_query_prepared &spi_freeplan
10
+ &_plperl_to_pg_array
11
+ &DEBUG &LOG &INFO &NOTICE &WARNING &ERROR %_SHARED
12
+ ] );
13
+
14
+ # Load strict into the container.
15
+ # The temporary enabling of the caller opcode here is to work around a
16
+ # bug in perl 5.10, which unkindly changed the way its Safe.pm works, without
17
+ # notice. It is quite safe, as caller is informational only, and in any case
18
+ # we only enable it while we load the 'strict' module.
19
+ $PLContainer -> permit(qw[ require caller] );
20
+ $PLContainer -> reval(' use strict;' );
21
+ $PLContainer -> deny(qw[ require caller] );
22
+
23
+ sub ::mksafefunc {
24
+ my $ret = $PLContainer -> reval(qq[ sub { $_ [0] $_ [1] }] );
25
+ $@ =~ s /\( eval \d +\) // g if $@ ;
26
+ return $ret ;
27
+ }
28
+
29
+ sub ::mk_strict_safefunc {
30
+ my $ret = $PLContainer -> reval(qq[ sub { BEGIN { strict->import(); } $_ [0] $_ [1] }] );
31
+ $@ =~ s /\( eval \d +\) // g if $@ ;
32
+ return $ret ;
33
+ }
You can’t perform that action at this time.
0 commit comments