I'm just curious if when writing PL/Perl functions if I can have a use My::Lib;
statement, or enable pragma's and features (e.g. 'use strict; use feature 'switch';
).

- 16,274
- 24
- 118
- 243
2 Answers
Not when using PL/Perl. It restricts the use of require and use, so you cannot import modules. However, you can install PL/Perlu (for unrestricted mode) which allows you to load modules.
plperlu can be considered a security risk, however, as it also allows filesystem commands such as open.

- 34,814
- 10
- 72
- 86
-
3plperlu can be very usefull just think about security when making use of it and if it impacts your system in a way that you may want to stay away from it. The important thing to mitigate security risk with plperlu is to have any procedures written in it reviewed very carefully to make sure it's not doing bad things. – Kuberchaun Aug 24 '10 at 14:25
For security purposes you cannot run a use/require statement within a function under plperl, but you can under plperlu.
IF you want to use modules in a secure way, you can add plperl.on_init = 'require "myperlinit.pl";'
to the postgresql.conf
file, then create a perl script called myperlinit.pl in the data directory which contains your uses. This will require a restart of the database server and these modules are available to all of your functions.
If you want strict mode turned on, you can plperl.use_strict = true
will add it.
Note: this script is executed once per connection when the first perl function is called, and not when the connection is created.

- 1,462
- 13
- 16