This plugin allows you to embed scripts within topics, using a tightly controlled subset of Perl. The scripts will be executed on the server, and the result displayed in the topic.
Scripts are executed inside a Safe container that strictly limits what the perl script can do. By default only basic operations are permitted, as well as access to a subset of theFoswiki::Func
interface. No IO
operations, such as print or file manipulation are permitted, and neither
is sub-process execution.
The range of permitted operations can easily be customised from the
configure
interface.
%PERL{"perl expression"}%
%PERL{topic="topic name"}%
%PERL{"'A String'"}%
expands to A String
%PERL{"101 - 59"}%
expands to 42
%PERL{topic="System.VarPERL"}%
expands to 100
%CODE{"perl"}% my $x = 99; $x = $x + 1; return $x; %ENDCODE%Because the perl expression is entered as a parameter to a Foswiki macro, the usual constraints on characters apply. Note especially that double-quotes have to be escaped using \" e.g
%PERL{"my $meal=\"fish";\"I ate a $meal\""}%
Note that the same container is used for each %PERL call made during rendering. As a result, a perl function defined in one %PERL will be available in other %PERLs that are evaluated later. %PERL{"sub x{95};x()"}%...%PERL{"x()+164"}%
expands to % PERL{"sub x{95};x()"}%...% PERL{"x()+164"}%
%CODE...%ENDCODE%
delimiters are compatible with SyntaxHighlightingPlugin, should you want to use it. Note that Foswiki macros are not available inside %CODE sections.
Because Foswiki::Func runs outside Foswiki access controls, this has to be use with care.
Note thatSTDOUT
and STDERR
are automatically appended to the result of the %PERL macro. Errors and warnings, and STDERR, are output after the normal result.
So %PERL{"print '{{this}}'; print STDERR 'ouch'; 'that'"}%
expands to:
that{{this}}ouch
(You cannot suppress errors. Instead, fix your perl)
print
(but not open)
$Foswiki::cfg{Plugins}{PerlPlugin}{Opcodes} = { Permit => [], # :default only Deny => [ ':base_mem', ':base_loop', ':base_orig' ] }; $Foswiki::cfg{Plugins}{PerlPlugin}{Share} = {}; # no access to Foswiki::FuncThis denies access to looping constructs. If you want to use an even smaller subset of Perl then you should read the Safe and Opcode manual pages.
You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.
Open configure, and open the "Extensions" section. Use "Find More Extensions" to get a list of available extensions. Select "Install".
If you have any problems, or if the extension isn't available inconfigure
, then you can still install manually from the command-line. See http://foswiki.org/Support/ManuallyInstallingExtensions for more help.
Check the plugin is working:
%PERL{"'Cushty'"}%
expands to Cushty
Author(s): | Crawford Currie http://c-dot.co.uk | ||||||
Copyright: | © 2008-2010 Crawford Currie | ||||||
License: | GPL (Gnu General Public License) | ||||||
Version: | 9962 (2010-11-11) | ||||||
Release: | 1.1.3 | ||||||
Change History: | |||||||
1.1.3 | Padraig Lennon: Foswikitask:Item9997 | ||||||
1.1.2 | Add STDOUT and STDERR support | ||||||
1.1.1 | First full release | ||||||
Dependencies: |
|
||||||
Home: | http://foswiki.org/Extensions/PerlPlugin | ||||||
Support: | http://foswiki.org/Support/PerlPlugin |