Blosxoms, Bryars and Blikis
by Simon CozensDecember 18, 2003
Recently we heard from Kake Pugh about the OpenGuides project, a wiki-based collaborative city guide system; previously, we heard from Brian Ingerson about his Kwiki wiki implementation. Guides, wikis, blogs ... the new fashion in software engineering at the moment is the use of software to help organize, document, and facilitate collaboration -- the social software movement is gaining momentum, and Perl is one of the best languages for it.
In this article we'll look not just at some of the existing social software tools in Perl (focusing, naturally, on my own Bryar blog toolkit), but we'll look at some ways to break, bend, and embed them in other tasks.
Basic Blogging with Blosxom
When I finally decided that the world would benefit from hearing my internal monologue, I naturally looked around for nice, simple blogging programs. Blogs are, essentially, simple things, and so I didn't want all-singing, all-dancing web-based database-backed content management systems. I knew that if I were going to blog, it would have to be easy for me to do so, and there's nothing easier than firing up a text editor in the next available terminal window and doodling my thoughts into it.
Thankfully, Rael Dornfest has the same sort of laziness as I, and created Blosxom, a very simple blogging tool, which simply reads a bunch of files from the file system, finds the most recent and relevant, packages them up together, and sends them at a browser. That was how I saw blogging.
Getting Blosxom up and running is, in keeping with the whole
theme of Blosxom, quite simple. You need to download the blosxom zip
file, unpack it, drop the blosxom.cgi file in
your web server's cgi-bin directory, and then edit the first few
lines of it to tell it the name of your blog and where the entries
will live, and you're done.
Posting into the blog is just a matter of creating a file
called something.txt in the blog directory. It
doesn't even matter what the something is. All that
matters is the first line of the file, which becomes the title,
and the rest, which becomes the story in raw HTML:
First post!
<p> Today I set up a blosxom blog. It was really easy! </p>
You can then, if you like, style your blog with custom header and footer files, CSS, custom HTML for each blog post, and so on.
Enter Bryar
Of course, back when I started using Blosxom, things were not quite so easy, and templating required hacking the Blosxom CGI file itself, and things just didn't seem as neat as I wanted them to be. I liked Blosxom's simplicity, but didn't want to pay the price for it in terms of flexibility.
At the same time, I was learning the wonders of the Template Toolkit, and thought that a well-designed blog should merely collect Post objects and send them to a user-defined template to do what it wants with them.
So I started writing Bryar, which is designed to be a modular, extensible replacement for Blosxom. To make this happen, I needed to provide a default set of components that simply Does The Right Thing. Let's take a look at that default set before we go any further.
When we install Bryar from CPAN, we're encouraged to run a command to set up a new blog:
You probably want to run bryar-newblog in a likely home for
your blog once we've finished installing.
The bryar-newblog command simply sets up a decent
default set of templates, creates a first blog post, and drops
in a bryar.cgi driver, similar to
blosxom. At this point, we're ready to go.
Bryar's default collection of modules consists of a
Bryar::DataSource::FlatFile, which emulates
Blosxom's use of text files in the file system as a database of
blog posts; there are Bryar::Frontend::CGI and
Bryar::Frontend::mod_perl, which describe how URL
parameters are retrieved from the server translated into a
request for documents, Bryar::Document which
represents each post, and Bryar::Collector which
ties it all together. With the benefit of hindsight, that should
have been called a Bryar::Controller, since the
whole thing can be described as a Model-View-Controller
application. But more on that later!
Since all of these things can be overridden, we need something to
keep track of which classes we're using, and the
Bryar::Config class does that, reading an optional
configuration file but otherwise providing mostly sensible
defaults.
In the rest of this article we're going to look at some interesting ways to override those classes, and build some more funky tools out of this social software framework.
Blogging the Past
Now it may surprise some people to find that I'm not really a programmer, although it may not come as a surprise to some of my colleagues.
I was trained in modern and classical Japanese language and literature, with a side order of linguistics. Programming was a hobby that turned out to make a bit more cash than conjugating 10th century verbs.
But as I began thinking a bit about blogging, I found an old Japanese diary of a lady-in-waiting to the Emperor, called the "Pillow Book", by Sei Shonagon. It was something I'd read before and found quite interesting, but picking it up again in a blog context put it in a completely new light. It read just like a 10th century LiveJournal.
Here's a sample entry:
Small children and babies should be fat. Provincial governors should be fat too, and other people who have done well for themselves. If they're too thin, it makes you think they're miserable.
As well as thoughts, observations, tales of life at the court, the book contains a large number of random lists, which really made me think of LiveJournal polls and surveys. Here's another example:
Things I think are elegant
- A white coat over a violet waistcoat
- Duck's eggs
- Sherbet ice, liana syrup, in a nice new silver bowl
- Rock crystal
- Wisteria
- Snow on plum blossoms
- A pretty little girl eating strawberries
I decided that it would be quite fun to translate the blog -- uh, book -- in a fairly modern, relaxed style, use fictitious but plausible dates for the entries, and run it as a real blog.
Naturally, I wanted to do this with Bryar, but there was going to be a slight problem; Bryar takes its entry dates from the Unix timestamp of the file, and try as I might, I could not persuade Unix to recognize epoch times a thousand years before the epoch. I had to find another way of getting the times.
But since Bryar is extensible, this is really easy -- I just
write a new data source class that gets the entry timestamp
from somewhere else. I simply created a subclass of
Bryar::DataSource::FlatFile called
...FlatFile::Dated, which takes its date from the
first line, and title from the next line.
Telling the Bryar blog to use the new data source was simply a
matter of writing a little config file called bryar.conf:
source: Bryar::DataSource::FlatFile::Dated
name: Notes on a Pillow - Sei Shonagon's blog
baseurl: http://blog.simon-cozens.org/shonagon/bryar.cgi
And the rest, of course, is just a simple matter of classical Japanese translation.
Blogging the House
But as well as a linguist, I'm also a geek, and I use Perl to
control various things around the house -- the house network, the
division of the phone bill, and so on. This is all driven by
Template Toolkit and Class::DBI.
It seemed useful, at the time, to add a blog into this great mass of centralized control, so we could pass phone messages around. Of course, in the end, it was easier to just put a big whiteboard in the lounge. XP's "the simplest thing that could possibly work" wins again.
But it was fun, and it allowed me to use Bryar in a new way. This time, we're using the original data source, collector, and other modules, but we're plugging them into an existing templating system. We already have code to deal with the web server, handle the URL processing, and the output; we already have code to transform objects into HTML; all we need is to collect the recent documents and hand them on to the templates.
I did this by adding a Bryar object to our template variables,
and calling the collect_current method on the Bryar
collector, using Richard Clamp's
Template::Plugin::Class module. This gave a bunch
of Bryar::Documents, which the template system could
manipulate however it desired:
[% INCLUDE header %]
[% PROCESS blogmacros %]
<h2> Recent blog postings</h2>
[%
USE c = Class("Bryar::Collector");
FOR post = c.collect_current(blog);
display_post(post);
END;
%]
Pages: 1, 2 |





