Pi3Perl is a perl embedding module for the Pi3Web Server, which provides
direct access to the API functions of the Pi3Web Server from any perl code.
The configured perl file will be loaded and evaluated, an initialization subroutine
is called. Later the execute subroutine is called during request handling phase.
The perl code can use callbacks to all Pi3 API functions through the Pi3::
perl module.
Perl Server Pages (PSP) is an embedded script language, which allows to
mix Perl code with any tag language (HTML) pages. You can either use scriptlets
to execute embedded perl code, expressions to write dynamic output or directives
to include subsequent PSP files. Pi3Perl is similar to Java Servlet API and
PSP is similar to JSP. For further information regarding PSP refer to the
PSP language specification v0.5.
Although Pi3Perl and PSP are indeed similar, there are also some differences:
- Pi3Perl scripts contain only perl, just like other perl scripts, PSP contains
plain tag language text with embedded PSP tags containing perl code
- Pi3Perl scripts are parsed on server startup, PSP scripts are parsed prior
they are used for the first time
- The perl subroutines, which are configured as "init" and "execute" parameter
values will be called in a Pi3Perl script. The PSP routines pspLoad(), pspUnLoad
and pspSetResponse() will be executed if they exist in a PSP scriptlet.
- Pi3Perl code is simply executed. To write data back to the client, the
Pi3:: package provides access to the Pi3Web server API's. PSP scriptlets are
also executed but expressions are evaluated and directly written back to the
client.
You should use Pi3Perl if:
- You rather want to write a server extension (handler) than a dynamic page
- It's important to evaluate the code at server startup
- Your code should be executed in other request handling phases than handle.
- You're familiar with the Pi3Web API's and would use them with Perl
You should rather use PSP if:
- You want to write dynamic pages with strict separation between content
and code
- You're not so familiar with the Pi3Web API's but with tag based scripting
languages like ASP or PHP
In each case you should like the Perl language ;-). By the way, Pi3Perl
and PSP aren't required to run Perl based CGI with Pi3Web. They provide a way
to
- Faster execute Perl code (4-5 times as standard Perl CGI)
- Extend the Pi3Web server with Perl based logical extensions (like shown
in the
Basic Authentication example below).