HSP allows executing Perl code that is embedded in plain
text files that otherwise would not contain perl code. Similar to
ASP, JSP or PHP you can define code blocks within plain text.
Example:
<~ if($form{go} ne ''){ htsendheader('location' => $form{go}); htflush(); }else{ print "<form>URL: <input name=go><input type=submit></form>"; } ~>
<~ # Perl code goes here ~>
The perl code is embedded between <~ and ~>. You can also use the following syntax:
But you cannot mix different them! If you decide to use
one type of code block delimiters then you have to use it until the
end of the file. That is if you have a "<% %>" code
block you cannot have a "<? ?>" code block unless
you put it into another file and embed it with the htembed command.
A special kind of code blocks was introduced to make variable interpolation easier:
<~..$foo~> or <~=$foo~>These code blocks will be eval'ed and then printed. It is the same as <~ print $foo ~> only shorter.
htsendheader(NAME => CONTENT); htsendheader(NAME => CONTENT [, NAME => CONTENT ]);
NAME is the type of the header. CONTENT is the value of the header. For example this will redirect the browser to another page:
htsendheader("location" => "/foo/bar.html");
htflush;
<~ if($foo){ ~> Hello World <~ } ~>
That is the same as
<~ if($foo){ print "Hello World"; } ~>
Don't do things like this:
<~ $foo = " ~> Hello World <~ " ~>
or
Hello World <~ =~s/\W+//g ~>
htembed("myscript.hsp"); # embed a .hsp scriptYou can even pass arguments to the embeded code:
htembed("myfile.hsp", {foo => 'bar'}); # pass arguments to .hsp scriptThe embeded script can access the arguments through %form. If you don't provide arguments then %form will contain the same values as in the calling script.
AddHandler hsp-perl .hsp Action hsp-perl /cgi-bin/hsp/hsp.pl
The second argument of the Action directive must match the relative URL of hsp.pl. Place hsp.pl in the cgi-bin of your server and edit the first line of hsp.pl to match the perl intepreter. Upload hsp.pl to the specified directory and make it executable by using CHMOD 755. The first line in hsp.pl must match the path to perl on your server.
ScriptAlias /hsp-perl/ "PATH_TO_HSP.PL" AddType application/hsp-perl .hsp Action application/hsp-perl /hsp-perl/hsp.pl
PATH_TO_HSP.PL must be replaced with the path to hsp.pl.
Also open hsp.pl and edit the first line to match the path to the
perl interpreter.