Weblog 2.0 - Mother of Perl | 2
[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 ([email protected])'); $channel->publisher("Webreference.com"); $channel->subject("Internet/Webdev"); $channel->contributor("Jonathan Eisenzopf"); $channel->type("News Channel"); $channel->format("RSS 1.0"); $channel->identifier("11111"); $channel->source("Author"); $channel->relation("father"); $channel->coverage("eastern"); $channel->rights("2001 internet.com"); $channel ->taxo(['http:www.webref.com', 'https://www.news.com']); # add a new item in the channel my $item1 = new Weblog::Item(title => 'ddddd', link => 'aaaaaa', description => 'eeeeeeee', taxo => [ 'https://www.da.com', 'https://www.ba.com' ] ); 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 $channel->add_item($item1,"insert"); $channel->add_item($item2,"append"); # save the channel $channel->save; # output my $output = new Weblog::Output($channel,"Template"); #$output->outputall("all"); $output->output("vxml"); $output->output("html"); $output->output("palm"); $output->output("wml"); $output->output("avantgo");
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.
[previous] [next] |
Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: April 30, 2001
URL: https://www.webreference.com/perl/tutorial/22/2.html