NAME
CGIx::Core - Rapid, Simple CGI application development
VERSION
Version 0.02
DESCRIPTION
This module can be used to create quick CGI applications using the excellent Template::Alloy. Now you can use the power of CGI (as powerful as it can be) with a template engine instead of writing multiple print commands in your script. Separate the code from HTML. Use 'views' as your layout, then the templates are the content inside the view.
SYNOPSIS
## index.pl (main script)
#!/usr/bin/env perl
use CGIx::Core;
my $c = CGIx::Core->new(view => 'default.tt');
$c->stash(
title => 'My First App',
greet => 'Hello, World!',
);
$c->process; # will use index.tt in templates/ as default
# $c->process('use_this_template.tt'); # to use a different one
## view/default.tt
<!-- HTML for application "layout" -->
<!doctype html>
<html>
<head>
<title><% title %></title>
</head>
<body>
<% content %>
</body>
</html>
## template/index.tt
<h3><% greet %></h3>
new
Creates a new instance of CGIx::Core. Handles POST and GET queries, which will one day be moved to a separate module. You also set the view here.
$c = CGIx::Core->new(view => 'default.tt');
stash
stash can be used to set global variables while the current page is available. They can be used throughout the view and templates, too.
$c->stash(title => 'My App');
$c->stash(
title => 'My App',
foo => 'baz',
bar => 'foo'.
);
redirect
Redirects the user to a different page. Redirects need to be done before the headers are sent to the browser. ie: before the process method.
$c->redirect('users/add.pl');
url_decode
Turns all HTML characters into human readable stuff. This is automatically called when you get POST or GET data
url_encode
This works the same as url_decode, except around the other way.
process
Runs the view and template. When you've finished all your code, then you run this. Without any arguments it will use the filename (minus the extension) as the template name.
## about.pl
$c->process; # runs $c->{template_path}/about.tt
$c->process('about_us'); # runs $c->{template_path}/about_us.tt
query_params
Return a value set by the GET method or 0 on failure.
if ($c->query_params('name')) { $c->stash(name => $c->query_params('name'); }
else { $c->stash(name => 'Anonymous'); }
body_params
The same as query_params but for POST requests.
$c->stash(password => $c->body_params('password'));