What is a Content Management System? It's a system that manages content. Any definition more specific than that is bound to make someone leave nasty flames in your inbox. There are simply too many diverse systems out there covered by the blanket term "CMS".
This module was orginally inspired by what I found to be a design flaw in SSI. Essentially, SSI forces your content to "pull in" the data from each content file. While this is less redundant than purely static content, it's still not quite good enough. I relized that a simple CMS, combined with HTML::Template and mod_perl, could fix the problem by taking the opposite approach--have the overall template pull in your content.
The result is documented below. Code is done, but I still need to package it up for CPAN. It's currently coded for Apache2 (because that's what I had available to experiment with), but it doesn't use many fancy features over Apache 1.3, so porting it shouldn't be a problem.
Apache::QuickCMS - A small content management system
<Directory /var/www/data>
<FilesMatch "\.(inc)$">
PerlSetVar UseCache 1
PerlSetVar TemplateFile index.tmpl
PerlSetVar DefaultContentType text/html
# Don't need extra features of perl-script, and
# modperl is faster
SetHandler modperl
PerlResponseHandler Apache::QuickCMS
</FilesMatch>
</Directory>
Implments a small content management system. Each directory on your web server contains a template file in HTML::Template format. The template contains TMPL_VARs at the locations you wish to fill data into.
Each document contains a POD-like format that gives the data to fill into each TMPL_VAR.
Default: 1
Cache the output to the disk. The cache file will be used if this is set to a true value, a cache file exists, and the modification times of the include file and the template are less than or equal to the modification time of the cache file. You can force a cache update by either running touch(1) on the include file or template or by deleting the cache file.
Default: .cache
When using caching, this controls what file extention to save the cache under.
Default: index.tmpl
Controls what file to use as the template for each directory. If this file does not exist in the document's directory, the one for the next directory down is used. It will keep searching in each parent directory until it finds a template file or it runs out of parent directories.
Default: text/html
If no content type is set inside the document, then this type is set instead.
The templates are in HTML::Template format. Because of the way it's used, TMPL_LOOP tags aren't useful.
Each directory can contain a different template, saved to the file noted by the TemplateFile parameter in your Apache configuration.
For every TMPL_VAR and TMPL_IF you have, you can place an entry for it in your include file. Here's an example:
<html>
<head>
<title><TMPL_VAR title></title>
</head>
<body>
<TMPL_VAR content>
</body>
</html>
This template would thus have an include file with directives for title and content.
The directives have a POD-like format. A directive named content_type is a special case (see below). An example for the tempale above would be:
=title
Hello
=cut
=content
<p>Hello, world!</p>
=cut
Save this document as index.inc (you may want to modify your Apache's DirectoryIndex attribute). You make a request for http://www.example.com/index.inc and (if properly configured) you will receive the above filled into the associated template entries.
The first POD-like directive is the name of the template variable, and everything after that up until =cut will be filled into that spot in the template. Anything not enclosed between a directive and a =cut will be ignored. If you specify the same directive twice in one file, the last one wins (this may change).
You may place any valid HTML::Template tags inside the directives. This is primarily for TMPL_INCLUDE tags. Other tags aren't particularly useful, since there is no way of getting data into them. I suggest limiting the use of this feature, since over-use will get you as many problems as SSI.
If you want to override the HTTP Content-type header being sent, you can specify a directive called content_type.
=content_type text/plain =cut
It's best to eliminate whitespace before the actual content-type, including a blank line (but you do need a newline after the =content_type text).
The tests in the t/ directory of this package hardly constitue a good test suite. If you wish to give a good test, you need to configure it yourself and add a PerlSetVar Debug 1 in the Apache config. You then setup the situations described here while doing a tail -f on your Apache error log.
After configuration and restarting Apache, use the files in the examples/ directory of this package, and then setup the situations below.
Now set your configuration back, turn on caching, and restart Apache.
You'll want to tail -f your Apache error log, and be sure to have PerlSetVar Debug 1 in your Apache configuration.
Yes.
HTML::Template. mod_perl2. touch(1). perlpod(1).
Apache::QuickCMS Copyright (C) 2004 Timm Murray
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Timm Murray <tmurray@wumpus-cave.net> CPAN ID: TMURRAY
----
send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.
In reply to RFC: Apache::QuickCMS by hardburn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |