| 1 | package Perlanet::DBIx::Class::Role::PostResultSet; | ||
| 2 | # ABSTRACT: Role for the ResultSet which contains a list of saved posts | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings FATAL => 'all'; | ||
| 6 | |||
| 7 | use Moose::Role; | ||
| 8 | use Method::Signatures::Simple; | ||
| 9 | use namespace::autoclean; | ||
| 10 | |||
| 11 | method create_from_perlanet ($post) | ||
| 12 | { | ||
| 13 | $self->create($self->munge_from_perlanet($post)); | ||
| 14 | } | ||
| 15 | |||
| 16 | method munge_from_perlanet ($post) | ||
| 17 | { | ||
| 18 | return { | ||
| 19 | feed_id => $post->feed->id, | ||
| 20 | author => $post->_entry->author || $post->feed->title, | ||
| 21 | url => $post->_entry->link, | ||
| 22 | title => $post->_entry->title, | ||
| 23 | posted_on => $post->_entry->issued || DateTime->now, | ||
| 24 | summary => $post->_entry->summary->body || | ||
| 25 | $post->_entry->content->body, | ||
| 26 | body => $post->_entry->content->body, | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | method has_post ($post) | ||
| 31 | { | ||
| 32 | return $self->search( { url => $post->link } )->count > 0; | ||
| 33 | } | ||
| 34 | |||
| 35 | 1; | ||
| 36 | |||
| 37 | __END__ |