simonodell has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
With my limited and old fashioned understandings in PERL I've written this getrss plugin to my aXML system. Whilst this plugin works already, I beseech information on how to modernise and improove this code such that it passes the poetic standards of perl in 2007.
The plugin is called from within the aXML doc using the <getrss> tag in the following way:
(getrss url="http://news.bbc.co.uk/rss/newsonline_world_edition/front_ +page/rss.xml") <h3><d>title</d></h3> <p><d>description</d></p> <p><link to="<d>link</d>">Read More...</link></p> (/getrss)
The ( ) brackets indicate to the aXML parser that this tag must be run before its child tag, since it contains a link command which depends on data which would not be available if the link were run first.
The contents of the (getrss) tag is a "mask" for each item found in the rss return, and <d> represents an item of data within that item. Link is a hyperlink generator plugin.
The data within the getrss tag is handed to the getrss plugin and is referred to as $data within the plugin. The plugin builds the string $result, which is then handed back.
my $module = 'LWP::Simple'; my $return_val = $module->use; if ($return_val) { $raw_data = get($command_args->{url}); $result = ""; if ($raw_data =~ m@<channel>(.*?)</channel>@s) { $channel_data = $1; $channel_data =~ s@\[@<lftsqbrk/>@g; $channel_data =~ s@\]@<rtsqbrk/>@g; $channel_data =~ s@\(@<lftbrk/>@g; $channel_data =~ s@\)@<rtbrk/>@g; $channel_data =~ s@\+@<plus/>@g; $channel_data =~ s@\?@<ques/>@g; $channel_data =~ s@\'@<apos/>@g; $channel_data =~ s@\$@<dollar/>@g; #these escapes are needed for the regex's below to #work properly. while ($channel_data =~ m@<item>(.*?)</item>@s) { $item_info = $1; $mask = $data; #the output mask is set to a copy of the data #handed to the plugin while ($mask =~ m@<d>(.*?)</d>@s) { $get_item = $1; my $item_string; if ($item_info =~ m@<$get_item>(.*?)</$get_item>@s) { $ +item_string = $1; } $mask =~ s@<d>$get_item</d>@$item_string@; } $result .= $mask; $channel_data =~ s@<item>$item_info</item>@@; } } else { $result = "<error>Couldnt find channel tag</error>"; } } else { $result = "<error>Couldnt retrieve url</error>"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modernisation Needed
by Joost (Canon) on Apr 14, 2007 at 02:34 UTC | |
|
Re: Modernisation Needed
by diotalevi (Canon) on Apr 14, 2007 at 02:58 UTC | |
|
Re: Modernisation Needed
by GrandFather (Saint) on Apr 14, 2007 at 04:32 UTC | |
|
Re: Modernisation Needed
by blazar (Canon) on Apr 14, 2007 at 10:51 UTC |