Blog::Simple - Perl extension for the creation of a simple weblog (blogger) system.


use Blog::Simple;

my $sbO = Blog::Simple->new(); $sbO->create_index(); #generally only needs to be called once

my $content="<p>blah blah blah in XHTM"p" <p><b>Better</b> when done in XHTM"p""; my $title = 'some title'; my $author = 'a.n. author'; my $email = ''; my $smmry = 'blah blah'; $sbO->add($title,$author,$email,$smmry,$content);

$sbO->render_current('blog_test.xsl',3); $sbO->render_all('blog_test.xsl');





None by default.


This module provides a simple mechanism for blogging, the reverse chronological diary-like systems so popular on the Internet today. It was intended to be simple, and just handles the basics of blogging: managing blog entries (adding, removing -- there probably should be a 'modify,' but there isn't), generating the most recent n entries, and generating all of the entries in the 'blogbase'.

Blog::Simple requires that the XML::XSL module be installed. Rather than try and do the rendering itself, it passes the XML that it generates to an XSL file that the user creates. So you will need to know XSLT to really find this module useful.

Blog::Simple generates XML files and stores them in a blogbase and in a timestamped subfolder. The blogbase consists of a folder under the path you specify in your code called b_base and a file called bb.idx. If no path is given, then it uses the directory the calling Perl file is saved in. bb.idx contains a tab-delimited list of the path, datestamp, title, author, summary of each blog entry. The Blog::Simple generated XML files are stored underneath b_base in automatically generated timestamped folders.

The XML entry for a blog is rendered as follows (this XML template is hardcoded in the add() method):

                <!-- title of blog -->
                <!-- who wrote it -->
                <!-- email -->

                <!-- timestamp - generated automatically -->
                <!-- just text here - NO TABS -->
                <!-- put XHTML blog between these tags      -->
                <!--   <img> tags must refer to same folder -->

When you tell Blog::Simple to generate its output, you will need an XSL document. One I used for testing looks like:

        <xsl:stylesheet xmlns:xsl="" version="1.0">
                <!-- this is the main template match -->
                <xsl:template match="/">
                        <xsl:apply-templates select="simple_blog_wrap/simple_blog"/>              

                <xsl:template match="simple_blog">
                        <xsl:apply-templates select="title"/>
                        <xsl:apply-templates select="ts"/>
                        <xsl:apply-templates select="content"/> 

                <xsl:template match="title"><xsl:copy-of select="."/></xsl:template>

                <xsl:template match="ts"><xsl:copy-of select="."/></xsl:template>

                <xsl:template match="content"><xsl:copy-of select="."/></xsl:template>


That should get you started. An XSL stylesheet is required when you invoke the render_current() and render_all() methods. Blog::Simple wraps a root element around all the <simple_blog></simple_blog> elements it renders called <simple_blog_wrap></simple_blog_wrap>. Keep this in mind when you are writing your XSL stylesheet.


new( [$path] )

The new() method instantiates a new Blog::Simple object. It sets the path to the blogbase, defaulting to the directory of the calling script if no path is given. Use relative or absolute paths. For example:

        $sbO = Blog::Simple->new('c:/absolute/path');


        $sbO = Blog::Simple->new('../path/to/somewhere/relative');


Call this method only once per blogbase you create. It merely generates the files necessary for Blog::Simple to work. You can manually create them somewhere, if you create the file bb.idx and the subdirectory b_base in some directory dir on your system, and then pass this path to the new() method. The resulting file structure in any case should be


There are no arguments for this method.


add( $title, $author, $email, $smmry, $content )

This adds an entry into the blogbase. It generates the XML and stores it as a file in a subdirectory below b_base. It also updates the blogbase, bb.idx, generating a timestamp and putting it at the head of the file.

        $sbO->add('some title', 'some author', '', 'some summary', 'some content, etc, etc...');

remove( $regex )

This method takes a regular expression, and searches through the bb.idx file, removing the entries that match. It creates an array of the paths of the entries it has removed, and stuffs a reference of it in a hash key associated with the object, called del_list. It does not remove the directories from the b_base directory; the array it returns can be used to do this.


In order to access the array of deleted paths, the value of


is a reference to the created array, whose elements can be gotten by using

        while(@{$sbO->{del_list}}) {
                #process elements

or some such.

render_current( $xsl_file [, $display_num, $out_file] )

This method processes an arbitrary number of the most recent blog entries against an XSL stylesheet that is passed as an argument. You pass it the stylesheet path/filename, and the number of entries to process. It will retrieve the entries from the filesystem, and wrap them in the root element <simple_blog_wrap></simple_blog_wrap> before passing them to your stylesheet. If the $display_num parameter is missing, the method defaults to 1, and returns one blog entry. $outfile is the path/filename to the output file. If you do not specify this, output is returned to STDOUT.

        $sbO->render_current('myxslfile.xsl', 3, 'output.html');

generates three blog entries and saves them to the file output.html. The same call, but sent to standard output:

        $sbO->render_current('myxslfile.xsl', 3);

render_all( $xsl_file [, $out_file] )

render_all() looks up all the blog entries stored in the blogbase and applies the stylesheet you provide against it. $out_file specifies a path/filename to save the output to.



        $sbO->render_all('mystylesheet.xsl', 'output.html');


This method simply reads in the bb.idx file entry by entry (line by line), and returns it as an array. This is a useful method for doing custom things with the blogbase.

        my @bI = $sB->get_index();


J. A. Robson, <>


XML, XSLT, Regular Expressions, XML::XSL