NAME
Sordid::CGI - Rapid, Simple CGI application development
VERSION
Version 0.4
SYNOPSIS
*NOTE* Please be aware that as of 0.5 I will be giving Sordid::CGI a complete revamp. The _GET, _POST and _SESSION hashes will be diminished and replaced by something nicer and less PHPish.
Sordid::CGI can be used to create quick (and dirty) CGI applications. While I recommend the use of awesome frameworks that can use FastCGI, like Catalyst, sometimes you want to just write out some quick Perl code, instead of learning an entire framework. A working example of a simple query string.
## index.pl
#!/usr/bin/env perl
# don't forget to import %_GET, %_POST or both depending on what you need
use Sordid::CGI qw( %_GET );
my $s = Sordid::CGI->new(view => 'default.tt');
$s->stash(title => "The I like to Greet Page!");
if (exists $_GET{name}) {
$s->stash(name => $_GET{name});
}
else {
$s->stash(name => 'Anonymous');
}
$s->process('greet.tt');
## view/default.tt
<!doctype html><html><head><title><% title %></title></head>
<body>
<% content %>
</body>
</html>
## template/greet.tt
Hello there, <% name %>!
Sordid::CGI->new
Creates a new instance of Sordid::CGI and also detects whether GET or POST has been submitted, then adds the values into %_GET and %_POST respectively.
Sordid::CGI->redirect
Redirects the user to a different page. Redirects need to be done before the main html stuff (before start_html)
Sordid::CGI->redirect('/uri/to/redirect/to');
Sordid::CGI->url_decode
Turns all of the weird HTML characters into human readable stuff. This is automatically called when you get POST or GET data
Sordid::CGI->url_encode
This works the same as url_decode, except around the other way.
process
Processes the template. If no argument is passed then the template will be $self->{$template_path}/<filename>.tt
$s->process;
$s->process('about.tt');