NAME

Webs::CGI - Rapid, Simple CGI application development

VERSION

Version 0.1

SYNOPSIS

Webs::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.

#!/usr/bin/env perl

use warnings;
use strict;

# don't forget to import %_GET, %_POST or both depending on what you need
use Webs::CGI qw( %_GET );

my $webs = Webs::CGI->new;

$webs->start_html; # send content-type header information

if (exists $_GET{name}) {
    print "<p>Hello, " . $_GET{name} . "</p>\n";
}
else {
    print "<p>Hi Anonymous!</p>\n";
}

Webs::CGI->new

Creates a new instance of Webs::CGI and also detects whether GET or POST has been submitted, then adds the values into %_GET and %_POST respectively.

Webs::CGI->start_html Prints the content type to the browser. Things like redirects MUST be written BEFORE you start_html

use Webs::CGI qw( %_POST );

my $webs = Webs::CGI->new;

if (! exists($_POST{'submit_login'})) {
    $webs->redirect('/cgi-bin/login.pl');
}

$webs->start_html; # prints similar to Content-Type: text/html\n\n

print qq{ <p>Hello, World!</p> };

Webs::CGI->redirect

Redirects the user to a different page. Redirects need to be done before the main html stuff (before start_html)

Webs::CGI->redirect('/uri/to/redirect/to');

Webs::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

Webs::CGI->url_encode

This works the same as url_decode, except around the other way.