[Catalyst-commits] r11093 - in
Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML: . Feed
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Mon Aug 10 07:00:04 GMT 2009
Author: rafl
Date: 2009-08-10 07:00:04 +0000 (Mon, 10 Aug 2009)
New Revision: 11093
Modified:
Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed.pm
Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed/Item.pm
Log:
use style;
Modified: Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed/Item.pm
===================================================================
--- Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed/Item.pm 2009-08-10 06:42:13 UTC (rev 11092)
+++ Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed/Item.pm 2009-08-10 07:00:04 UTC (rev 11093)
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# Item.pm
+# Item.pm
# Copyright (c) 2006 Jonathan Rockway <jrockway at cpan.org>
package Catalyst::Model::XML::Feed::Item;
@@ -8,12 +8,12 @@
sub new {
my ($class, $feed, $uri) = @_;
- my $self =
+ my $self =
{ _feed => $feed,
- _uri => $uri,
- _updated => time,
+ _uri => $uri,
+ _updated => time,
};
-
+
bless $self, $class;
return $self;
}
Modified: Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed.pm
===================================================================
--- Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed.pm 2009-08-10 06:42:13 UTC (rev 11092)
+++ Catalyst-Model-XML-Feed/trunk/lib/Catalyst/Model/XML/Feed.pm 2009-08-10 07:00:04 UTC (rev 11093)
@@ -108,24 +108,24 @@
$self = $self->NEXT::new(@_);
my @in_feeds = eval { @{$self->feeds} };
$self->feeds({});
-
+
$self->ttl($self->ttl || 3600);
foreach my $feed (@in_feeds) {
- my $name = $feed->{name} || $feed->{title};
- my $uri = $feed->{uri} || $feed->{location};
- #my $c = $_[0];
- if($name){
- #$c->log->debug("registering XML feed $uri as $name") if $c;
- $self->register($name, $uri);
- }
- else {
- #$c->log->debug("registering XML feed $uri") if $c;
- my @names = $self->register($uri);
- my $name = join q{,}, at names;
- #$c->log->debug("feed(s) at $uri created as $name") if $c;
- }
+ my $name = $feed->{name} || $feed->{title};
+ my $uri = $feed->{uri} || $feed->{location};
+ #my $c = $_[0];
+ if($name){
+ #$c->log->debug("registering XML feed $uri as $name") if $c;
+ $self->register($name, $uri);
+ }
+ else {
+ #$c->log->debug("registering XML feed $uri") if $c;
+ my @names = $self->register($uri);
+ my $name = join q{,}, at names;
+ #$c->log->debug("feed(s) at $uri created as $name") if $c;
+ }
}
-
+
return $self;
}
@@ -161,40 +161,40 @@
my $name;
my $uri;
-
+
if($arg2){
- # get only one feed
- $name = $arg1;
- $uri = URI->new($arg2);
- my $feed;
- eval {
- $feed = XML::Feed->parse($uri);
- };
- if($@){
- my @feeds = XML::Feed->find_feeds($arg2);
- if(@feeds > 1){
- croak "$arg2 points to too many feeds";
- }
- if(!@feeds){
- croak "$arg2 does not reference any feeds";
- }
- $uri = shift @feeds;
- }
-
- return $self->_add_uri($uri, $name);
+ # get only one feed
+ $name = $arg1;
+ $uri = URI->new($arg2);
+ my $feed;
+ eval {
+ $feed = XML::Feed->parse($uri);
+ };
+ if($@){
+ my @feeds = XML::Feed->find_feeds($arg2);
+ if(@feeds > 1){
+ croak "$arg2 points to too many feeds";
+ }
+ if(!@feeds){
+ croak "$arg2 does not reference any feeds";
+ }
+ $uri = shift @feeds;
+ }
+
+ return $self->_add_uri($uri, $name);
}
else {
- $uri = URI->new($arg1);
- my @feed_uris = XML::Feed->find_feeds($uri);
- croak "$arg1 does not reference any feeds" if !@feed_uris;
-
- my @added;
- foreach my $uri (@feed_uris){
- $uri = URI->new($uri);
- my $name = $self->_add_uri($uri);
- push @added, $name if $name;
- }
- return @added;
+ $uri = URI->new($arg1);
+ my @feed_uris = XML::Feed->find_feeds($uri);
+ croak "$arg1 does not reference any feeds" if !@feed_uris;
+
+ my @added;
+ foreach my $uri (@feed_uris){
+ $uri = URI->new($uri);
+ my $name = $self->_add_uri($uri);
+ push @added, $name if $name;
+ }
+ return @added;
}
}
@@ -204,9 +204,9 @@
my $name = shift;
my $feed = XML::Feed->parse($uri);
$feed->title($name) if $name;
- my $obj = Catalyst::Model::XML::Feed::Item->new($feed, $uri);
+ my $obj = Catalyst::Model::XML::Feed::Item->new($feed, $uri);
$name ||= $uri;
-
+
$self->feeds->{$name} = $obj;
return $name;
}
@@ -233,8 +233,8 @@
my @names = $self->names;
my @feeds;
foreach my $name (@names){
- my $feed = $self->get($name);
- push @feeds, $feed;
+ my $feed = $self->get($name);
+ push @feeds, $feed;
}
return @feeds;
}
@@ -254,9 +254,9 @@
# refresh the feed if it's too old
if(time - $feed->updated > $self->ttl){
- $self->_refresh($name);
+ $self->_refresh($name);
}
-
+
return $feed->feed;
}
@@ -270,16 +270,16 @@
sub refresh {
my $self = shift;
my $name = shift;
-
+
if($name){
- $self->_refresh($name);
+ $self->_refresh($name);
}
else {
- foreach my $name (keys %{$self->feeds}){
- $self->_refresh($name);
- }
+ foreach my $name (keys %{$self->feeds}){
+ $self->_refresh($name);
+ }
}
-
+
return;
}
@@ -288,7 +288,7 @@
my $name = shift;
my $feed = $self->feeds->{$name};
croak "No feed named $name" if !ref $feed;
-
+
my $uri = $feed->uri;
return $self->_add_uri($uri, $name);
}
More information about the Catalyst-commits
mailing list