NAME

Lavoco::Website - EXPERIMENTAL FRAMEWORK.

Framework to run small websites, URL dispatching based on a flexible config file, to render Template::Toolkit templates.

VERSION

Version 0.12

SYNOPSIS

A FastCGI web-app for serving Template::Toolkit templates.

This is an experimental framework to control various small websites, use at your own risk.

use Lavoco::Website;

my $website = Lavoco::Website->new( name => 'Example' );

my $action = lc( $ARGV[0] );   # (start|stop|restart)

$website->$action;

METHODS

Class Methods

new

Creates a new instance of the website object.

Instance Methods

name

The identifier for the website, used as the process title.

base

The base directory of the application, using FindBin.

dev

A simple boolean flag to indicate whether you're running a development instance of the website.

It's on by default, and currently turned off if the base directory contains /live. Feel free to set it based on your own logic before calling start().

I typically use working directories such as /home/user/www.example.com/dev and /home/user/www.example.com/live.

This flag is useful to disable things like Google Analytics on the dev site.

The website object is avilable to all templates under the name website.

e.g. [% IF website.dev %]...

processes

Number of FastCGI process to spawn, 5 by default.

$website->processes( 10 );

templates

The directory containing the TT templates, by default it's $website->base . '/templates'.

start

Starts the FastCGI daemon. Performs basic checks of your environment and dies if there's a problem.

stop

Stops the FastCGI daemon.

restart

Restarts the FastCGI daemon, with a 1 second delay between stopping and starting.

CONFIG

Currently only JSON is supported, the config file should be named website.json and should be placed in the base directory of your website.

See the examples directory for a sample JSON config file.

{
   "pages" : [
      {
         "path" : "/",
         "template":"index.tt",
         ...
      },
      ...
   ]
   ...
   "send_alerts_from":"The Example Website <no-reply@example.com>",
   "send_404_alerts_to":"you@example.com",
   ...
}

The entire config hash is available in all templates via [% config %], and is flexible, there are only a couple of mandatory/reserved attributes.

The mandatory field in the config is pages, which is an array of JSON objects.

Each page object should have a path (to match a URL) and template.

All other fields are up to you, to fit your requirements.

When a request is made, a lookup is performed for a page by matching the path - the associated template will be rendered.

If no page is found, the template 404.tt will be rendered, make sure you have this file ready in the templates directory.

The page object is available in the templates.

It is often useful to have sub-pages, simply create a pages attribute in a page object.

If a sub-page is selected, an extra key for parents is included in the page object as a list of the parent pages, this is useful for building breadcrumb links.

TODO

More documentation.

AUTHOR

Rob Brown, <rob at intelcompute.com>

BUGS

Please report any bugs or feature requests to bug-lavoco-website at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lavoco-Website. I will be notified, and then you will automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Lavoco::Website

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2014 Rob Brown.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.