[Bast-commits] r9577 - in ironman/branches/mk-ii/Perlanet-IronMan-0.02: bin lib/Perlanet t

aCiD2 at dev.catalyst.perl.org aCiD2 at dev.catalyst.perl.org
Thu Jun 3 10:54:57 GMT 2010


Author: aCiD2
Date: 2010-06-03 11:54:57 +0100 (Thu, 03 Jun 2010)
New Revision: 9577

Modified:
   ironman/branches/mk-ii/Perlanet-IronMan-0.02/bin/ironman-collector.pl
   ironman/branches/mk-ii/Perlanet-IronMan-0.02/lib/Perlanet/IronMan.pm
   ironman/branches/mk-ii/Perlanet-IronMan-0.02/t/01_basic.t
Log:
Bring Perlanet-IronMan up to date with my Perlanet changes

Modified: ironman/branches/mk-ii/Perlanet-IronMan-0.02/bin/ironman-collector.pl
===================================================================
--- ironman/branches/mk-ii/Perlanet-IronMan-0.02/bin/ironman-collector.pl	2010-06-03 10:53:50 UTC (rev 9576)
+++ ironman/branches/mk-ii/Perlanet-IronMan-0.02/bin/ironman-collector.pl	2010-06-03 10:54:57 UTC (rev 9577)
@@ -10,6 +10,9 @@
 use Perlanet::IronMan;
 use IronMan::Schema;
 
+use FindBin '$Bin';
+use lib "$Bin/../lib";
+
 my ($cli_dsn, $cli_feed, $DEBUG);
 
 GetOptions(
@@ -19,34 +22,35 @@
 ) or die pod2usage;
 
 # Perlanet configuration settings
-my $cfg = {};
-$cfg->{title} = "all.things.per.ly";
-$cfg->{description} = "all.things.per.ly IronMan agregation";
-$cfg->{url} = "http://ironboy.enlightenedperl.org/";
-$cfg->{self_link} = "http://ironboy.enlightenedperl.org/";
-$cfg->{agent} = "Perlanet";
-$cfg->{author}->{name} = "Perlanet";
-$cfg->{feed}->{format} = "Atom";
-$cfg->{entries} = 10;
+my $cfg = {
+    title       => "all.things.per.ly",
+    description => "all.things.per.ly IronMan agregation",
+    url         => "http://ironboy.enlightenedperl.org/",
+    self_link   => "http://ironboy.enlightenedperl.org/",
+    agent       => "Perlanet",
+    author_name => "Perlanet",
+    feed_format => "Atom",
+    entries     => 10,
+};
 
 $cfg->{filter}->{keywords} = ["cpan", "ironman", "perl"];
 
 # Database DSN
 if(defined($cli_dsn)) {
-    $cfg->{db}{dsn} = $cli_dsn;
+    $cfg->{dsn} = $cli_dsn;
 }
 
 else {
-    $cfg->{db}{dsn} = "dbi:SQLite:/var/www/ironboy.enlightenedperl.org/ironman/subscriptions.db";
+    $cfg->{dsn} = "dbi:SQLite:/var/www/ironboy.enlightenedperl.org/ironman/subscriptions.db";
     #$cfg->{db}{dsn} = "dbi:SQLite:/var/www/ironboy.enlightenedperl.org/ironman/testsubscriptions.db";
 }
 
 # Get me a Perlanet::IronMan thingy using our config from above
-my $p = Perlanet::IronMan->new( cfg => $cfg );
+my $p = Perlanet::IronMan->new( $cfg );
 
 # Should be calling run here
-#$p->run;
-#exit;
+$p->run;
+exit;
 
 # I'm taking run apart here
 $p->update_opml;

Modified: ironman/branches/mk-ii/Perlanet-IronMan-0.02/lib/Perlanet/IronMan.pm
===================================================================
--- ironman/branches/mk-ii/Perlanet-IronMan-0.02/lib/Perlanet/IronMan.pm	2010-06-03 10:53:50 UTC (rev 9576)
+++ ironman/branches/mk-ii/Perlanet-IronMan-0.02/lib/Perlanet/IronMan.pm	2010-06-03 10:54:57 UTC (rev 9577)
@@ -13,6 +13,11 @@
 use Carp;
 
 extends 'Perlanet';
+with qw(
+    Perlanet::Trait::Scrubber
+    Perlanet::Trait::Tidy
+   );
+
 use Perlanet::Entry;
 
 our $VERSION = '0.01_01';
@@ -26,7 +31,6 @@
 
 =head1 SYNOPSIS
 
-
 =head1 DESCRIPTION
 
 This module uses an IronMan::Schema database to define feeds, collect the feeds
@@ -43,14 +47,18 @@
     lazy_build => 1,
 );
 
+has 'dsn'     => ( isa => 'Str', is => 'ro' );
+has 'db_user' => ( isa => 'Str', is => 'ro' );
+has 'db_pass' => ( isa => 'Str', is => 'ro' );
+
 has 'truncator' => (
     is         => 'rw',
     lazy_build => 1
 );
 
-sub _build_scrubber {
+around '_build_scrubber' => sub {
   my $self = shift;
-  
+
   my %scrub_rules = (
       img => {
           src => qr{^http://},    # only URL with http://
@@ -60,7 +68,7 @@
       style  => 0,
       script => 0,
   );
-    
+
   # Definitions for HTML::Scrub
   my %scrub_def = (
       '*'    => 1,                        # default rule, allow all attributes
@@ -96,9 +104,9 @@
   my $scrub = HTML::Scrubber->new;
   $scrub->rules(%scrub_rules);
   $scrub->default(1, \%scrub_def);
-  
+
   return $scrub;
-}
+};
 
 =head2 select_entries
 
@@ -219,9 +227,9 @@
                 title            => $post->_entry->title,
                 posted_on        => $post->_entry->issued || DateTime->now,
                 summary          => $summary,
-                summary_filtered => $self->clean($summary),
+                summary_filtered => $self->clean_html($summary),
                 body             => $post->_entry->content->body,
-                body_filtered    => $self->clean($post->_entry->content->body),
+                body_filtered    => $self->clean_html($post->_entry->content->body),
             } );
         }
 
@@ -236,14 +244,6 @@
     }
 };
 
-=head2 save
-
-Save is not required within the context of this module so we override it.
-
-=cut
-
-override 'save' => sub { };
-
 =head2 _build_feeds
 
 Feeds are built from the Schema::IronMan database overriding the internal
@@ -252,18 +252,21 @@
 
 =cut
 
-override '_build_feeds' => sub {
-    my $self = shift;
-    return [ map {
-        Perlanet::Feed->new(
-            id => $_->id,
-            url => $_->url || $_->link,
-            website => $_->link || $_->url,
-            title => $_->title,
-            author => $_->owner,
-        );
-    } $self->schema->resultset('Feed')->all ];
-};
+has '+feeds' => (
+    lazy => 1,
+    default => sub {
+        my $self = shift;
+        return [ map {
+            Perlanet::Feed->new(
+                id => $_->id,
+                url => $_->url || $_->link,
+                website => $_->link || $_->url,
+                title => $_->title,
+                author => $_->owner,
+            );
+        } $self->schema->resultset('Feed')->all ];
+    }
+);
 
 =head2 _build_schema
 
@@ -274,10 +277,11 @@
 
 sub _build_schema {
     my $self = shift;
+
     return IronMan::Schema->connect(
-        $self->cfg->{db}{dsn},
-        $self->cfg->{db}{username},
-        $self->cfg->{db}{password},
+        $self->dsn,
+        $self->db_user,
+        $self->db_pass,
     );
 }
 
@@ -377,15 +381,22 @@
     return 0;
 }
 
+# We'll do the cleaning ourselves, as we need the dirty and clean versions
+around 'clean_entries' => sub {
+    my $orig = shift;
+    my $self = shift;
+    return @_;
+};
+
 # We don't want to remove the style attribute completely, but a clear: both will
 # screw our layout up...
-around 'clean' => sub {
+around 'clean_html' => sub {
     my $orig = shift;
-    my ($self, $input) = @_;
+    my ($self, $html) = @_;
+    $html = $self->$orig($html);
 
-    my $output = $self->$orig($input);
-    $output =~ s/style="(.*?)clear:(.*?);/style="$1/;
-    return $output;
+    $html =~ s/style="(.*?)clear:(.*?);/style="$1/;
+    return $html;
 };
 
 =head1 AUTHOR

Modified: ironman/branches/mk-ii/Perlanet-IronMan-0.02/t/01_basic.t
===================================================================
--- ironman/branches/mk-ii/Perlanet-IronMan-0.02/t/01_basic.t	2010-06-03 10:53:50 UTC (rev 9576)
+++ ironman/branches/mk-ii/Perlanet-IronMan-0.02/t/01_basic.t	2010-06-03 10:54:57 UTC (rev 9577)
@@ -33,20 +33,15 @@
                                      tags => 'perl'
                                    });
 
-my $p = Perlanet::IronMan->new('t/testrc');
+my $p = Perlanet::IronMan->new(
+    dsn => 'dbi:SQLite:t/var/test.db',
+    title => 'planet test',
+    description => 'Testing stuff',
+    url => 'http://google.com',
+    self_link => 'http://google.com',
+);
 
-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};
-}
-
 is($schema->resultset('Post')->count, 1);
 $p->run;
 is($schema->resultset('Post')->count, 2);




More information about the Bast-commits mailing list