Skip to content

Miscellaneous

Things to note or information not otherwise contained elsewhere

How to check syntax on a PSP file

To check the syntax of a PSP file, specifically any Perl code in the __PERL__ section make sure you have a #!perl shebang after the __PERL__ delimiter as here:

<start_html>
Hello World <? server_time() ?>
__PERL__
#!perl

sub server_time {
    my 2==1; #Error here
}

Then run the command perl -x -c -w <filename.psp>. This will check the file for syntax error and report back:

$ perl -c -w -x check.psp 
syntax error at check.psp line 4, near "my 2"
check.psp had compilation errors.
How to pass $self ref if using processing instructions

If you use the processing instruction form of calling a perl method it will not pass the WebDyne object ref through to your perl code. You can pass it by supplying @_ as a param, or just shift() and your parameters:

<start_html>
Hello World <? server_time(@_) ?>
Hello World <? server_time(shift(), 'UTC' ?>
Hello World <perl handler="server_time" param="UTC"/>
__PERL__

sub server_time {
    #  Now we can get self ref
    my ($self, $timezone)=@_;
    #  Do something and return
}
Use of hash characters for comments in .psp files

Any # characters at the very start of a PSP file before a <html> or <start_html> tag are treated as comments and discarded - they will not be stored or displayed (they are not translated into HTML comments). This allows easy to read comments at the start of .psp files. Any # characters after the first valid tag are not treated specially - they will be rendered as normal HTML:

#  This is my server time display file
#  
#  VERSION=1.23
#
<start_html>
Server local time is: <? localtime ?>
The <checkbox> tag will always set a hidden form field

The <checkbox> tag is unusual in that it adds a hidden field (with the same name as the checkbox) to the HTML page to retain state. Thus if you are examining the checkbox parameter from CGI via $_{'checkbox_name'} or $self->CGI->param('checkbox_name') you may get an array rather than a single value. The value of the checkbox (boolean, checked or unchecked, i.e. 1 or 0) will always be the first value returned. So the code if ($_{'checkbox_name'}) { .. do_something } will work as expected - but just be careful if using in an array context.