<% $js %> <%args> $name => undef # key into hash %feeds below <%init> use XML::RSS::JavaScript; use LWP::Simple; use Cache::SizeAwareFileCache; ## How many items to print per feed my $item_count = 3; ## Turn on|off (1|0) printing of item ## descriptions per feed my $descriptions = 0; ## Please note that max-size below ## needs to be adjusted ## depending upon the values of ## $item_count and $description. ## 50 kb is adequate for the defaults above. my $cache = new Cache::SizeAwareFileCache( { 'namespace' => 'rll', 'default_expires_in' => '2 h', 'cache_root' => '/www/htdocs/rllroot/rss_cache/', 'max_size' => 50000 } ); my %feeds = ( lemonde => "http://www.lemonde.fr/rss/sequence/0,2-3208,1-0,0.xml", elpais => "http://www.elpais.es/rss.html", jornada => "http://www.jornada.unam.mx/rss/mundo.xml", repubblica => "http://www.repubblica.it/rss/homepage/rss2.0.xml", ubnews => "http://wings.buffalo.edu/calendar/events.rss" ); ## If allowing these params to come in via a GET querystring $name = undef if (int($item_count) > 100 || int($item_count) < 1); $name = undef if (int($descriptions) < 0 || int($descriptions) > 1); my $js; if ( defined $name && exists $feeds{$name} ) { $js = $cache->get( $name ); if ( not defined $js ) { my $xml = get( $feeds{$name} ); my $rss = XML::RSS::JavaScript->new(); $rss->parse( $xml ); $js = $rss->as_javascript($item_count, $descriptions); $cache->set( $name, $js, '2 h' ); } }