Perl Programming More Templating Tools for Perl |
But first, let's complete our portal by writing the RSSBox library that all these sources use. First, we want a ONCE block to load up the modules we need: <%ONCE> Next we take our arguments, setting appropriate defaults: <%ARGS> Before we start outputting any content, we load up the feed in question and parse it with the XML::RSS module. We call Mason's cache_self method to have this component handle caching its output; if the same URL is accessed within 10 minutes, the cached copy will be presented instead: <%INIT> And now we are ready to go. So lets look at this altogether in Example 3-15. Example 3-15. RSSBox <%ONCE> <%ARGS> <%INIT> <BR> <dl class="rss"> % last if ++$count >= $Max; There isn't much to it; for each item in the feed, we want to provide a link, the item's title, and, optionally, the description. We stop if we have more items than we want. This demonstrates how powerful Mason can be; as I said, the total development time for this site was a couple of hours at most. The entire site takes considerably fewer than 200 lines of code. And, as we mentioned, we have the flexibility to include components that are not RSS. For instance, we don't actually have an RSS feed of the Oxford weather. However, there is a web page that spits out a weather report in a well-known format. This means that Weather/01-Oxford does not call RSSBox at all, but is in fact the following: <%INIT> <br> <ul> <& /BoxEnd &> And that sums up Mason--simple, extensible, and highly powerful.
blog comments powered by Disqus |
|
|
|
|
|
|
|