The only public interface the Web::Simple Perl module itself provides is an import based one -
use Web::Simple 'NameOfApplication';
This imports 'strict' and 'warnings FATAL => "all"' into your code as well, so you can skip the usual
use strict;
use warnings;
provided you 'use Web::Simple' at the top of the file. Note that we turn on *fatal* warnings so if you have any warnings at any point from the file that you did 'use Web::Simple' in, then your application will die. This is, so far, considered a feature.
Calling the import also makes NameOfApplication isa Web::Simple::Application - i.e. does the equivalent of
{
package NameOfApplication;
use base qw(Web::Simple::Application);
}
It also exports the following subroutines:
default_config(
key => 'value',
...
);
dispatch { sub (...) { ... }, ... };
response_filter { ... };
redispatch_to '/somewhere';
subdispatch sub (...) { ... }
and creates a $self global variable in your application package, so you can use $self in dispatch subs without violating strict (Web::Simple::Application arranges for dispatch subroutines to have the correct $self in scope when this happens).
Finally, import sets
$INC{"NameOfApplication.pm"} = 'Set by "use Web::Simple;" invocation';
so that perl will not attempt to load the application again even if
require NameOfApplication;
is encountered in other code.
SYNOPSIS
#!/usr/bin/perl
use Web::Simple 'HelloWorld';
{
package HelloWorld;
dispatch {
sub (GET) {
[ 200, [ 'Content-type', 'text/plain' ], [ 'Hello world!' ] ]
},
sub () {
[ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
}
};
}
HelloWorld->run_if_script;
Product's homepage
Requirements:
· Perl