[Jifty-commit] r6335 - in jifty/trunk: . plugins/NewsFeed/lib/Jifty/Plugin

Jifty commits jifty-commit at lists.jifty.org
Fri Feb 13 02:13:20 EST 2009


Author: c9s
Date: Fri Feb 13 02:13:19 2009
New Revision: 6335

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed.pm
   jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed/View.pm

Log:
 r7209 at Oulixeus:  c9s | 2009-02-13 13:43:45 +0800
 - fix newsfeed App::Cache permission problem: provide option to set cacheroot for Cache::File


Modified: jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed.pm
==============================================================================
--- jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed.pm	(original)
+++ jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed.pm	Fri Feb 13 02:13:19 2009
@@ -2,6 +2,7 @@
 use strict;
 package Jifty::Plugin::NewsFeed;
 use base qw'Jifty::Plugin';
+__PACKAGE__->mk_accessors(qw(config));
 
 =head1 NAME
 
@@ -12,14 +13,14 @@
 # In your jifty config.yml under the framework section:
 
   Plugins:
-    - NewsFeed: {}
+    - NewsFeed:
+		CacheRoot: /tmp
 
 # In your jifty application view
 
     template 'news' => page { title is 'News' } content  {
         show 'display_feed', 'http://path/to/feed', { max_items => 6 };
     };
-  
 
 
 =head1 DESCRIPTION
@@ -27,6 +28,16 @@
 Provides templates to include site news feeds in your Jifty app. 
 More detail about templates , see L<Jifty::Plugin::NewsFeed::View>
 
+
+=head2 init
+
+=cut
+
+sub init {
+    my $self = shift;
+	$self->config( { @_ });
+}
+
 =head2 AUTHOR
 
 Yo-An Lin ( Cornelius )

Modified: jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed/View.pm
==============================================================================
--- jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed/View.pm	(original)
+++ jifty/trunk/plugins/NewsFeed/lib/Jifty/Plugin/NewsFeed/View.pm	Fri Feb 13 02:13:19 2009
@@ -67,11 +67,21 @@
     return unless ( $feed_url and $feed_url =~ m(^https?://) );
 
     use XML::Feed;
-    use App::Cache;
     use Encode qw(decode_utf8);
+	use Cache::File;
 
-    my $cache = App::Cache->new({ ttl =>  $options->{cache_ttl} || 60*60   });
-    my $feed_xml = $cache->get_url( $feed_url );
+	my $plugin = Jifty->find_plugin( 'Jifty::Plugin::NewsFeed' );
+	warn $plugin->config->{CacheRoot};
+
+
+	my $c1 = Cache::File->new( cache_root =>  $plugin->config->{CacheRoot}  );
+	my $feed_xml = $c1->get( 'feed_url' );
+ 	unless ($feed_xml) {
+		use LWP::Simple;
+		Jifty->log->info('Fetch feed:' . $feed_url );
+ 		$feed_xml = get $feed_url;
+ 		$c1->set( 'feed_url' , $feed_xml , '1 hours' );
+ 	}
 
     my $feed = XML::Feed->parse ( \$feed_xml );
 


More information about the Jifty-commit mailing list