Weblog 2.0 - Mother of Perl | 2 | WebReference

Weblog 2.0 - Mother of Perl | 2

To page 1current pageTo page 3
[previous] [next]

Weblog 2.0

New Modules

Weblog Module

I've rewritten the Weblog functionality into a discrete set of modules that can be reused to develop other applications. I did this to make it easier for me to extend the code for use in an aggregator and for being able to post to remote Weblogs via XML-RPC. The modules will probably change in the future, but it's a good set of code where you need to manipulate multiple RSS channels in a production environment. For example, below is a script that loads a channel, adds an item, saves the channel, and outputs the channel to several different formats:

use strict;
use Weblog;
my $config_file = '../config/config.xml';
# create new instance of the Weblog module
my $weblog = new Weblog($config_file);
# get a list of the channels that are available
my @channels = $weblog->list_channels(local  => 1);
foreach my $channel (@channels) {
    print $channel->{'name'},"\n";
# load the channel into memory
my $channel = new Weblog::Channel($weblog, "webnews");
$channel->creator('Andy King (aking@internet.com)');
$channel->contributor("Jonathan Eisenzopf");
$channel->type("News Channel");
$channel->format("RSS 1.0");
$channel->rights("2001 internet.com");
$channel ->taxo(['http:www.webref.com',
# add a new item in the channel
my $item1 = new Weblog::Item(title => 'ddddd',
			    link => 'aaaaaa',
			    description => 'eeeeeeee',
			    taxo => [
my $item2 = new Weblog::Item(title => 'ddddd',
			    link => 'aaaaaa',
			    description => 'eeeeeeee'
# if you want to add one item to multiple channels
# $weblog->add_item($itemref, "append', $channel1, $channel2, $channel3);
# add the items to a channel
# save the channel
# output
my $output = new Weblog::Output($channel,"Template");

There are several example scripts that I used for testing in addition to the modules themselves that are sitting in the lib/ directory. Feel free to play around with them. This module has not been finalized or fully documented, so expect it to change. When it becomes more stable, I will probably release it to CPAN.

To page 1current pageTo page 3
[previous] [next]


Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: April 30, 2001

URL: http://www.webreference.com/perl/tutorial/22/2.html