[Bast-commits] r9582 -
ironman/branches/mk-ii/Perlanet-IronMan-0.02/lib/Perlanet
aCiD2 at dev.catalyst.perl.org
aCiD2 at dev.catalyst.perl.org
Mon Jun 7 23:38:58 GMT 2010
Author: aCiD2
Date: 2010-06-08 00:38:58 +0100 (Tue, 08 Jun 2010)
New Revision: 9582
Modified:
ironman/branches/mk-ii/Perlanet-IronMan-0.02/lib/Perlanet/IronMan.pm
Log:
Use Perlanet::DBIx::Class
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-07 11:53:45 UTC (rev 9581)
+++ ironman/branches/mk-ii/Perlanet-IronMan-0.02/lib/Perlanet/IronMan.pm 2010-06-07 23:38:58 UTC (rev 9582)
@@ -1,37 +1,22 @@
package Perlanet::IronMan;
# ABSTRACT: IronMan specific instance of Perlanet
-use 5.8.0;
-use strict;
-use warnings;
-
use Moose;
-use IronMan::Schema;
+
+use Carp;
+use Data::Dumper;
use HTML::Truncate;
+use IronMan::Schema;
+use Perlanet::Entry;
use Perlanet::Feed;
-use Data::Dumper;
use Try::Tiny;
-use Carp;
-extends 'Perlanet';
+extends 'Perlanet::DBIx::Class';
with qw(
Perlanet::Trait::Scrubber
Perlanet::Trait::Tidy
);
-use Perlanet::Entry;
-
-our $VERSION = '0.01_01';
-
-=head1 NAME
-
-Perlanet::IronMan
-
-This module extends Perlanet for the specific requirements of the Enlightened
-Perl Organisation IronMan project.
-
-=head1 SYNOPSIS
-
=head1 DESCRIPTION
This module uses an IronMan::Schema database to define feeds, collect the feeds
@@ -52,6 +37,16 @@
has 'db_user' => ( isa => 'Str', is => 'ro' );
has 'db_pass' => ( isa => 'Str', is => 'ro' );
+has '+post_resultset' => (
+ lazy => 1,
+ default => sub { shift->schema->resultset('Post') },
+);
+
+has '+feed_resultset' => (
+ lazy => 1,
+ default => sub { shift->schema->resultset('Feed') },
+);
+
has 'truncator' => (
is => 'rw',
lazy_build => 1
@@ -175,100 +170,46 @@
return @feed_entries;
};
-=head2 render
-Given a Perlanet::Entry object, store the entry as a post in the
-Schema::IronMan database
+override 'insert_post' => sub {
+ my ($self, $post) = @_;
-=cut
+ # Set the summary text to the summary or body if not supplied
+ # This should probably be in config rather than hard coded.
+ my $summary = $post->_entry->summary->body || $post->_entry->content->body;
-override 'render' => sub {
- my $self = shift;
- my $post = shift;
+ my $truncated = eval { $self->truncator->truncate($summary) };
+ if ($@) {
+ warn "Truncate failed: $@";
+ $truncated = $summary;
+ }
- my $posts = $post->entries;
+ $summary = $truncated;
- #print(Dumper($posts));
- #exit;
+ # Can't store a post if we can't work out the URL to link to it.
+ unless(defined($post->_entry->link)) {
+ print("ERROR. Can't deal with lack of URL returned from XML::Feed::Entry for feed '" . $post->feed->url . "'\n");
+ return;
+ }
- foreach my $post (@{$posts}) {
+ # Get the entry tags
+ my @tags = $post->_entry->category;
- # Set the summary text to the summary or body if not supplied
- # This should probably be in config rather than hard coded.
- my $summary = $post->_entry->summary->body || $post->_entry->content->body;
-
-
- my $truncated = eval { $self->truncator->truncate($summary) };
- if ($@) {
- warn "Truncate failed: $@";
- $truncated = $summary;
- }
-
- $summary = $truncated;
-
- #print(Dumper($post));
- #exit;
-
- # Can't store a post if we can't work out the URL to link to it.
- unless(defined($post->_entry->link)) {
- print("ERROR. Can't deal with lack of URL returned from XML::Feed::Entry for feed '" . $post->feed->url . "'\n");
- next;
- }
-
- # Get the entry tags
- my @tags = $post->_entry->category;
-
- try {
- # Do that whole insert thing...
- $self->schema->resultset('Post')->create( {
- feed_id => $post->feed->id,
- author => $post->_entry->author || $post->feed->title,
- tags => join(",", @tags),
- url => $post->_entry->link,
- title => $post->_entry->title,
- posted_on => $post->_entry->issued || DateTime->now,
- summary => $summary,
- summary_filtered => $self->clean_html($summary),
- body => $post->_entry->content->body,
- body_filtered => $self->clean_html($post->_entry->content->body),
- } );
- }
-
- catch {
- Carp::cluck("ERROR: $_\n");
- Carp::cluck("ERROR: Post is:\n" . Dumper($post) . "\n");
- Carp::cluck("ERROR: Link URL is '" . $post->_entry->link . "'\n");
- };
-
- #print(Dumper($post));
-
- }
+ # Do that whole insert thing...
+ $self->schema->resultset('Post')->create( {
+ feed_id => $post->feed->id,
+ author => $post->_entry->author || $post->feed->title,
+ tags => join(",", @tags),
+ url => $post->_entry->link,
+ title => $post->_entry->title,
+ posted_on => $post->_entry->issued || DateTime->now,
+ summary => $summary,
+ summary_filtered => $self->clean_html($summary),
+ body => $post->_entry->content->body,
+ body_filtered => $self->clean_html($post->_entry->content->body),
+ } );
};
-=head2 _build_feeds
-
-Feeds are built from the Schema::IronMan database overriding the internal
-defaults of utilising feeds specified in either the configuration file or as
-configuration options when creating the Perlanet object.
-
-=cut
-
-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
Build and return a schema object the first time that the schema attribute of
More information about the Bast-commits
mailing list