WebDyne
NAME
WebDyne - Primary runtime module for the WebDyne framework, with support for standalone .psp to HTML rendering
SYNOPSIS
# Framework usage usually happens under a WebDyne-compatible runtime
# such as Apache/mod_perl, PSGI, or PAGI, where WebDyne->handler()
# is called by the request layer.
#
use WebDyne qw(html html_sr);
# Render a .psp file to HTML and return a string
#
my $html = html('app.psp');
# Render a .psp file with template parameters
#
my $html = html('app.psp', {
param => {
user => 'alice',
},
});
# Render a .psp file to HTML and return a scalar ref
#
my $html_ref = html_sr('app.psp');
# Write rendered output to an existing filehandle
#
html('template.psp', { outfile => $fh });
DESCRIPTION
WebDyne is the primary supporting module for the WebDyne framework. In normal use it operates under a web server or application runtime such as Apache/mod_perl, PSGI, or PAGI, where it acts as the main request handler and rendering engine for .psp pages.
The module can also be used directly from scripts to render .psp templates to HTML without a web server, which is useful for tooling, diagnostics, offline generation, and simple standalone usage. In that mode the main entry points are html() and html_sr().
The html() and html_sr() functions are exported only on request:
use WebDyne qw(html html_sr);
WebDyne supports embedded Perl within HTML, compile-time parsing and caching, chained handler modules, filters, templates, CGI-style parameter access, and integration with the wider WebDyne module family.
Comprehensive documentation around .psp page construction and framework usage is available in the module source tree and the Github repository.
The simplest representation of a .psp file that can be rendered is:
<start_html>
The current server time is: <? localtime() ?>
If this example is saved as C<app.psp>, it can be rendered from the command line with C<wdrender>:
$ wdrender app.psp
<!DOCTYPE html><html lang="en"><head><title>Untitled Document</title><meta charset="UTF-8"></head>
<body><p>The current server time is: ...</p></body></html>
METHODS
html($filename, \%options, ...)
Render a
.pspfile and return the result as a string. This is the convenience wrapper aroundhtml_sr().Supported calling styles include:
html('page.psp')html('page.psp', { ... })html('page.psp', key => value, ...)html({ filename => 'page.psp', ... })html_sr($filename, \%options, ...)
Render a
.pspfile and return a scalar reference to the generated HTML when output is captured internally. This is the core script-facing rendering function.If
outfileis supplied, output is written to that filehandle andhtml_sr()returns a reference toundefinstead of a scalar reference containing generated HTML. Thehtml()wrapper dereferences this, sohtml(..., outfile => $fh)returnsundef.Arguments and options are the same as for
html().In standalone rendering,
html_sr()creates aWebDyne::Request::Fakerequest object unless anroption is supplied. If a customhandleroption is supplied, that handler class is loaded before rendering.handler($r, \%params)
Main request lifecycle entry point for WebDyne under server environments such as Apache/mod_perl, PSGI, PAGI, and chained WebDyne handler modules. It is not typically called directly from standalone scripts.
Raw Apache request objects are wrapped in
WebDyne::Request::Apache; other runtimes normally provide an appropriate WebDyne request object. The return value is the status or response result expected by the active runtime.
OPTIONS
The following options are the most commonly used with html() and html_sr():
filename
.pspfilename to render. Usually supplied as the first argument.handler
Custom handler class to use for rendering. Defaults to
WebDyne.outfile
Filehandle to receive rendered output. When supplied, output is written directly and
html_sr()does not return a scalar reference.param
Hash reference of parameters passed into the handler/rendering context for use by page code.
r
Optional prebuilt request object. If omitted, WebDyne creates a
WebDyne::Request::Fakeobject for standalone rendering.
SEE ALSO
Plack Catalyst Dancer2 Mojolicious
AUTHOR
Andrew Speer mailto:andrew.speer@isolutions.com.au and contributors.
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/ .