Skip to content

Introduction

WebDyne is a Perl based dynamic HTML engine. It works with web servers (or from the command line) to render HTML documents with embedded Perl code.

Once WebDyne is installed and initialised any file with a .psp extension is treated as a WebDyne source file. It is parsed for WebDyne pseudo-tags (such as <perl> and <block>) which are interpreted and executed on the server. The resulting output is then sent to the browser.

WebDyne works with common web server persistent Perl interpreters - such as Apache mod_perl and PSGI - to provide fast dynamic content. It works with PSGI servers such as Plack and Starman, and can be implemented as a Docker container to run HTML with embedded Perl code.

Pages are parsed once, then stored in a partially compiled format - speeding up subsequent processing by avoiding the need to re-parse a page each time it is loaded.

Alternate syntaxes are available to enable WebDyne code to be used with editors that do not recognise custom HTML tags, and the syntax supports the use of PHP type processing instruction tags (<?..?>) or <div> tags (via data attributes such as <div data-webdyne-perl>) to define WebDyne blocks.

Perl code can be co-mingled in the HTML code for "quick and dirty" pages or completed isolated into separate files or modules for separation of presentation and logic layers. You can see examples in a dedicated section - but here are a few very simple examples as an overview.

Simple HTML file with Perl code embedded using WebDyne :

<html>
<head><title>Server Time</title></head>
<body>
The local server time is:
<perl> localtime() </perl>
</body>
</html>

Run

This can be abbreviated with some WebDyne shortcut tags such as <start_html>. This does exactly the same thing and still renders compliant HTML to the browser:

<start_html title="Server Time">
The local server time is: <? localtime() ?>

Run

Don't like the co-mingling code and HTML but still want things in one file ?

<start_html title="Server Time">
The local server time is <? print_time() ?>
</html>
__PERL__
sub print_time {
    print(scalar localtime);
}

Run

Want further code and HTML separation ? You can import methods from any external Perl module. Example from a core module below, but could be any installed CPAN module or your own code:

<start_html title="Server Time">
Server Time::HiRes time:
<perl require="Time::HiRes" import="time">time()</perl>

Run

Same concepts implemented in slightly different ways:

<start_html title="Server Time">
The local server epoch time (hires) is: <? time() ?>
<end_html>
__PERL__
use Time::HiRes qw(time);
1;

Run

<start_html title="Server Time">
<perl require="Time::HiRes" import="time"/>
The local server time (hires) is: <? time() ?>

Run

Using an editor that doesn't like custom tags ? Use of the <div> tag with a data-* attribute is legal HTML syntax and can be used to embed Perl:

<start_html title="Server Time">
The local server time is: <div data-webdyne-perl> localtime() </div>

Run

Don't like <div> style syntax ? Put the code in a <script> block - it will be interpreted on the server, not the client:

<start_html title="Server Time">
Server local time is: 
<script type="application/perl">
    print scalar localtime()
</script>

Run

Template blocks and variable replacement is supported also:

<start_html>

<!-- Call perl code to render server time -->
<perl handler="server_time">

<!-- Template Block it will be rendered into -->
<block name="server_time">
<p>
Loop ${i}: The local server time is: ${time}
</block>

</perl>

__PERL__

sub server_time {

    #  Get self ref
    #
    my $self=shift();

    #  Get local time
    #
    my $time=scalar localtime();

    #  Loop 4 times
    #
    foreach my $i (1..4) {

        #  Render template block
        #
        $self->render_block('server_time', i=>$i, time=>$time)

    }

    #  Return section
    #
    return $self->render()

}

Run