[Bast-commits] r8826 - ironman/Perlanet-IronMan/lib/Perlanet
idn at dev.catalyst.perl.org
idn at dev.catalyst.perl.org
Sat Feb 27 00:33:23 GMT 2010
Author: idn
Date: 2010-02-27 00:33:23 +0000 (Sat, 27 Feb 2010)
New Revision: 8826
Modified:
ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm
Log:
This is some nasty hacking around of Olivers originally very nice code. Sorry :( Needs a refactor to tidy up and we need a replacement run function that correctly wraps all this shit together
Modified: ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm
===================================================================
--- ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm 2010-02-27 00:30:33 UTC (rev 8825)
+++ ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm 2010-02-27 00:33:23 UTC (rev 8826)
@@ -3,6 +3,9 @@
use IronMan::Schema;
use Perlanet::Feed;
+use Data::Dumper;
+use Try::Tiny;
+use Carp;
extends 'Perlanet';
use Perlanet::Entry;
@@ -25,19 +28,35 @@
my $self = shift;
return [ map {
Perlanet::Feed->new(
+ id => $_->id,
url => $_->url,
- website => $_->link,
+ website => $_->link || $_->url,
title => $_->title,
- author => $_->owner
+ author => $_->owner,
);
} $self->schema->resultset('Feed')->all ];
};
+=head2 select_entries
+
+The select entries function takes an array of feed entries and filters it to
+remove duplicates. The non-duplicated feed entries are then returned to the
+caller as an array of feed entries.
+
+Okay, that's what I thought this function does, but it doesn't seem to quite be
+that straight forward. The objects passed in and the objects returned are not
+the same.
+
+=cut
+
override 'select_entries' => sub {
my ($self, @feeds) = @_;
my @entries;
for my $feed (@feeds) {
+
+ #print(Dumper($feed));
+
my $unseen = $self->schema->resultset('Feed')->filter_unseen($feed->url, [ $feed->_xml_feed->entries ]);
push @entries, @$unseen;
@@ -49,26 +68,87 @@
override 'save' => sub { };
override 'render' => sub {
- my ($self, $feed) = @_;
+ my ($self, $feed, $post) = @_;
- my $new = [
- map { +{
- feed_id => 'davorg',
- author => 'Dave',
- tags => '',
- url => $_->link,
- title => $_->title,
- posted_on => $_->issued,
- summary => $_->summary->body,
- summary_filtered => $self->clean($_->summary->body),
- body => $_->content->body,
- body_filtered => $self->clean($_->content->body),
- } } @{ $feed->entries }
- ];
+# my $new = [
+# map {
+#
+#
+#{
+# feed_id => 'davorg',
+# author => 'Dave',
+# tags => '',
+# url => $_->link,
+# title => $_->title,
+# posted_on => $_->issued || DateTime->from_epoch(epoch => 0),
+# summary => $_->summary->body,
+# summary_filtered => $self->clean($_->summary->body),
+# body => $_->content->body,
+# body_filtered => $self->clean($_->content->body),
+# }
- $self->schema->resultset('Post')->populate($new);
+ #map($self->_db_insert($_), @{ $post->entries });
+
+ $self->_db_insert($feed, $post);
+
+ #print(Dumper($new));
+
+ #$self->schema->resultset('Post')->populate($new);
};
+
+
+sub _db_insert {
+ my $self = shift;
+ my $feed = shift;
+ my $post = shift;
+
+ my $posts = $post->entries;
+
+ #print(Dumper($posts));
+ #exit;
+
+ foreach my $post (@{$posts}) {
+
+ # Check we've got tags on this post
+ unless(defined($post->category)) {
+ next;
+ }
+
+ # Check that perl is one of those tags
+ unless($post->category =~ /perl/i) {
+ next;
+ }
+
+ # Set the summary text if not explicity specified
+ my $summary = $post->summary->body || substr($post->content->body, 0, 250) . "...";
+
+ #print(Dumper($post));
+ #exit;
+
+ try {
+
+ $self->schema->resultset('Post')->populate( [ {
+ feed_id => $feed->id,
+ author => $post->author,
+ tags => $post->category,
+ url => $post->link,
+ title => $post->title,
+ posted_on => $post->issued || DateTime->from_epoch(epoch => 0),
+ summary => $summary,
+ summary_filtered => $self->clean($summary),
+ body => $post->content->body,
+ body_filtered => $self->clean($post->content->body),
+ } ] );
+ }
+
+ catch {
+ Carp::cluck("ERROR: $!\n");
+ Carp::cluck("ERROR: Link URL is '" . $post->link . "'\n");
+ };
+ }
+}
+
no Moose;
__PACKAGE__->meta->make_immutable;
1;
More information about the Bast-commits
mailing list