[Bast-commits] r8088 - in ironman: . Perlanet-IronMan Perlanet-IronMan/lib Perlanet-IronMan/lib/Perlanet Perlanet-IronMan/t Perlanet-IronMan/t/lib Perlanet-IronMan/t/lib/Perlanet

aCiD2 at dev.catalyst.perl.org aCiD2 at dev.catalyst.perl.org
Sat Dec 12 20:19:07 GMT 2009


Author: aCiD2
Date: 2009-12-12 20:19:06 +0000 (Sat, 12 Dec 2009)
New Revision: 8088

Added:
   ironman/Perlanet-IronMan/
   ironman/Perlanet-IronMan/TODO
   ironman/Perlanet-IronMan/lib/
   ironman/Perlanet-IronMan/lib/Perlanet/
   ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm
   ironman/Perlanet-IronMan/t/
   ironman/Perlanet-IronMan/t/01_basic.t
   ironman/Perlanet-IronMan/t/lib/
   ironman/Perlanet-IronMan/t/lib/Perlanet/
   ironman/Perlanet-IronMan/t/lib/Perlanet/IronMan.pm
   ironman/Perlanet-IronMan/t/testrc
Log:
Perlanet::IronMan - initial import. Render should be implemented, but select_entries is not fully working yet. Depends on my Perlanet fork at http://github.com/cycles/perlanet

Added: ironman/Perlanet-IronMan/TODO
===================================================================
--- ironman/Perlanet-IronMan/TODO	                        (rev 0)
+++ ironman/Perlanet-IronMan/TODO	2009-12-12 20:19:06 UTC (rev 8088)
@@ -0,0 +1,2 @@
+* How to populate the feed_id field (in render)
+* How to actually call resultset('feed')->unseen_filter
\ No newline at end of file

Added: ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm
===================================================================
--- ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm	                        (rev 0)
+++ ironman/Perlanet-IronMan/lib/Perlanet/IronMan.pm	2009-12-12 20:19:06 UTC (rev 8088)
@@ -0,0 +1,49 @@
+package Perlanet::IronMan;
+use Moose;
+
+use IronMan::Schema;
+
+extends 'Perlanet';
+
+has 'schema' => (
+    is => 'rw',
+    lazy_build => 1,
+);
+
+sub _build_schema {
+    my $self = shift;
+    return IronMan::Schema->connect(
+        $self->cfg->{db}{dsn},
+        $self->cfg->{db}{username},
+        $self->cfg->{db}{password},
+    );
+}
+
+around 'select_entries' => sub {
+    my $orig = shift;
+    my ($self, @feeds) = @_;
+    my @all = $self->$orig();
+    return $self->schema->resultset('Feed')->filter_unseen(@all);
+};
+
+override 'render' => sub {
+    my ($self, $feed) = shift;
+    $self->schema->resultset('Post')->populate(
+        map {
+            +{
+                feed_id => ?,
+                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
+    );
+};
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+1;

Added: ironman/Perlanet-IronMan/t/01_basic.t
===================================================================
--- ironman/Perlanet-IronMan/t/01_basic.t	                        (rev 0)
+++ ironman/Perlanet-IronMan/t/01_basic.t	2009-12-12 20:19:06 UTC (rev 8088)
@@ -0,0 +1,41 @@
+use strict;
+use warnings;
+
+use Perlanet::IronMan;
+use XML::Feed;
+use IronMan::Schema;
+
+unlink("t/var/test.db");
+my $schema = IronMan::Schema->connect("dbi:SQLite:t/var/test.db");
+$schema->deploy();
+
+## Initialise with something to test against:
+$schema->resultset('Feed')->create({ id => 'fdave',
+                                     url => 'http://blog.dave.org.uk/',
+                                     link => '',
+                                     owner => '',
+                                     title => "Dave's Blog",
+                                   });
+$schema->resultset('Post')->create({ url => 'http://blog.dave.org.uk/2009/10/updates-from-jesusistan.html'
+                                     feed_id => 'dave',
+                                     title => 'Entry 1',
+                                     posted_on => DateTime->now,
+                                     body => 'blahblah',
+                                   });
+
+my $p = Perlanet::IronMan->new('testrc');
+
+if (exists $p->cfg->{opml} and -e $p->cfg->{opml}) {
+  unlink $p->cfg->{opml};
+}
+
+if (exists $p->cfg->{feed}{file} and -e $p->cfg->{feed}{file}) {
+  unlink $p->cfg->{feed}{file};
+}
+
+if (exists $p->cfg->{page}{file} and -e $p->cfg->{page}{file}) {
+  unlink $p->cfg->{page}{file};
+}
+
+$p->run;
+

Added: ironman/Perlanet-IronMan/t/lib/Perlanet/IronMan.pm
===================================================================
--- ironman/Perlanet-IronMan/t/lib/Perlanet/IronMan.pm	                        (rev 0)
+++ ironman/Perlanet-IronMan/t/lib/Perlanet/IronMan.pm	2009-12-12 20:19:06 UTC (rev 8088)
@@ -0,0 +1,49 @@
+package Perlanet::IronMan;
+use Moose;
+
+use IronMan::Schema;
+
+extends 'Perlanet';
+
+has 'schema' => (
+    is => 'rw',
+    lazy_build => 1,
+);
+
+sub _build_schema {
+    my $self = shift;
+    return IronMan::Schema->connect(
+        $self->cfg->{db}{dsn},
+        $self->cfg->{db}{username},
+        $self->cfg->{db}{password},
+    );
+}
+
+around 'select_entries' => sub {
+    my $orig = shift;
+    my ($self, @feeds) = @_;
+    my @all = $self->$orig();
+    return $self->schema->resultset('Feed')->filter_unseen(@all);
+};
+
+override 'render' => sub {
+    my ($self, $feed) = shift;
+    $self->schema->resultset('Post')->populate(
+        map {
+            +{
+                feed_id => ?,
+                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
+    );
+};
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+1;

Added: ironman/Perlanet-IronMan/t/testrc
===================================================================
--- ironman/Perlanet-IronMan/t/testrc	                        (rev 0)
+++ ironman/Perlanet-IronMan/t/testrc	2009-12-12 20:19:06 UTC (rev 8088)
@@ -0,0 +1,22 @@
+title: planet test
+description: Testing stuff
+url: http://theplanetarium.org/
+self_link: http://theplanetarium.org/
+agent: Testing Perlanet
+author:
+  name: Dave Cross
+  email: dave at dave.org.uk
+entries: 20
+opml: opml.xml
+page:
+  file: index.html
+  template: index.tt
+feed:
+  file: rss.xml
+  format: RSS
+feeds:
+  - url: file:data/davblog.xml
+    title: davblog
+    web: http://blogs.dave.org.uk/
+db:
+  dsn: dbi:SQLite:t/var/test.db




More information about the Bast-commits mailing list