| 1 | package Perlanet; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use 5.34.0; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use feature 'try'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | # After Moose because Moose turns on warnings | ||||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | no warnings 'experimental::try'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use DateTime::Duration; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use Perlanet::Entry; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 12 | ▶ | use Perlanet::Feed; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | use URI::Fetch; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | 12 | ▶ | use XML::Feed; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 12 | ▶ | use Perlanet::Types; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | 12 | our $VERSION = '3.3.5'; | |||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 12 | with 'MooseX::Traits'; | |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 12 | $XML::Atom::ForceUnicode = 1; | |||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 12 | has 'config' => ( | |||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 32 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 12 | has 'ua' => ( | |||||||||||||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 37 | isa => 'LWP::UserAgent', | ||||||||||||||||||||||||||||||||||||||
| 38 | lazy_build => 1 | ||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 11 | ▶ | sub _build_ua { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_ua: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||
| 42 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 43 | 11 | my $ua = LWP::UserAgent->new( | |||||||||||||||||||||||||||||||||||||
| 44 | agent => "Perlanet/$VERSION", | ||||||||||||||||||||||||||||||||||||||
| 45 | timeout => 20, | ||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | $ua->show_progress(1) if -t STDOUT; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 48 | 11 | $ua->env_proxy; | |||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | 11 | return $ua; | |||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | 12 | has 'cutoff_duration' => ( | |||||||||||||||||||||||||||||||||||||
| 54 | isa => 'Perlanet::DateTime::Duration', | ||||||||||||||||||||||||||||||||||||||
| 55 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 56 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||
| 57 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | 10 | ▶ | sub _build_cutoff_duration { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_cutoff_duration: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 61 | 10 | return { years => 1_000 }; | |||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | 12 | has 'cutoff' => ( | |||||||||||||||||||||||||||||||||||||
| 65 | isa => 'Perlanet::DateTime', | ||||||||||||||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 67 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||
| 68 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 10 | ▶ | sub _build_cutoff { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_cutoff: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 72 | 10 | return DateTime->now - shift->cutoff_duration; | |||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | 12 | has 'spam_regex' => ( | |||||||||||||||||||||||||||||||||||||
| 76 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||||||||||||
| 77 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 78 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | 10 | ▶ | sub _build_spam_regex { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_spam_regex: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 82 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | 10 | ▶ | return unless $self->config->{spam_filter}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my $re = '(' . join('|', @{$self->config->{spam_filter}}) . ')'; | |||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | 1 | return $re; | |||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | 12 | has 'entries' => ( | |||||||||||||||||||||||||||||||||||||
| 92 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||
| 93 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 94 | default => 10, | ||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | 12 | has 'entries_per_feed' => ( | |||||||||||||||||||||||||||||||||||||
| 98 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||
| 99 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 100 | default => 5, | ||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | has 'feeds' => ( | ||||||||||||||||||||||||||||||||||||||
| 104 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||||||||||||
| 105 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 107 | 12 | ); | |||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | 12 | has 'author' => ( | |||||||||||||||||||||||||||||||||||||
| 110 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||
| 111 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | has $_ => ( | ||||||||||||||||||||||||||||||||||||||
| 115 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||
| 116 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 117 | 12 | ) for qw( self_link title description url agent ); | |||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||
| 119 | 12 | has entry_sort_order => ( | |||||||||||||||||||||||||||||||||||||
| 120 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||
| 121 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 122 | default => 'modified', | ||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||
| 127 | Perlanet - A program for creating programs that aggregate web feeds (both | ||||||||||||||||||||||||||||||||||||||
| 128 | RSS and Atom). | ||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | my $perlanet = Perlanet->new; | ||||||||||||||||||||||||||||||||||||||
| 133 | $perlanet->run; | ||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||
| 135 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | Perlanet is a program for creating programs that aggregate web feeds (both | ||||||||||||||||||||||||||||||||||||||
| 138 | RSS and Atom). Web pages like this are often called "Planets" after the Python | ||||||||||||||||||||||||||||||||||||||
| 139 | software which originally popularised them. Perlanet is a planet builder | ||||||||||||||||||||||||||||||||||||||
| 140 | written in Perl - hence "Perlanet". | ||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | You are probably interested in L<Perlanet::Simple> to get started straight | ||||||||||||||||||||||||||||||||||||||
| 143 | out of the box, batteries included style. | ||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | Perlanet itself is the driving force behind everything, however. Perlanet | ||||||||||||||||||||||||||||||||||||||
| 146 | reads a series of web feeds (filtering only those that are valid), sorts | ||||||||||||||||||||||||||||||||||||||
| 147 | and selects entries from these web feeds, and then creates a new aggregate | ||||||||||||||||||||||||||||||||||||||
| 148 | feed and renders this aggregate feed. Perlanet allows the user to customize | ||||||||||||||||||||||||||||||||||||||
| 149 | all of these steps through subclassing and roles. | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | For most uses, you probably don't want to use the Perlanet module. The | ||||||||||||||||||||||||||||||||||||||
| 152 | L<perlanet> command line program is far more likely to be useful. | ||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | =head2 new | ||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | my $perlanet = Perlanet->new | ||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | The constructor method. Can be passed a hashref of initialisers. | ||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||
| 162 | See L</ATTRIBUTES> below for details of the key/value pairs to pass in. | ||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||
| 164 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||
| 166 | =over | ||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||
| 168 | =item config | ||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||
| 170 | A hash reference that contains the complete contents of the configuration | ||||||||||||||||||||||||||||||||||||||
| 171 | file. | ||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||
| 173 | =item ua | ||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||
| 175 | An instance of L<LWP::UserAgent>. Defaults to a simple agent using C<< | ||||||||||||||||||||||||||||||||||||||
| 176 | $config->{agent} >> as the user agent name, or C< Perlanet/$VERSION >. | ||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||
| 178 | =item cutoff | ||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||
| 180 | An instance of L<DateTime> which represents the earliest date for | ||||||||||||||||||||||||||||||||||||||
| 181 | which feed posts will be fetched/shown. | ||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||
| 183 | =item feeds | ||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||
| 185 | An arrayref of L<Perlanet::Feed> objects representing the feeds to | ||||||||||||||||||||||||||||||||||||||
| 186 | collect data from. | ||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||
| 188 | =back | ||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | =head2 fetch_feed | ||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||
| 194 | Attempt to fetch a web feed. Returns the response object | ||||||||||||||||||||||||||||||||||||||
| 195 | (or "undef"). | ||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | sub fetch_feed { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_feed: called CC=3 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 200 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 201 | 1 | my ($url) = @_; | |||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||
| 203 | 1 | my $response = URI::Fetch->fetch( | |||||||||||||||||||||||||||||||||||||
| 204 | $url, | ||||||||||||||||||||||||||||||||||||||
| 205 | UserAgent => $self->ua, | ||||||||||||||||||||||||||||||||||||||
| 206 | ForceResponse => 1, | ||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | if ($response->is_error) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 210 | 0 | warn "Error retrieving $url\n"; | |||||||||||||||||||||||||||||||||||||
| 211 | 0 | warn $response->http_response->status_line, "\n"; | |||||||||||||||||||||||||||||||||||||
| 212 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | unless (length $response->content) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 216 | 0 | warn "No data returned from $url\n"; | |||||||||||||||||||||||||||||||||||||
| 217 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||
| 220 | 1 | return $response; | |||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||
| 223 | =head2 fetch_feeds | ||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||
| 225 | Called internally by L</run> and passed the list of feeds in L</feeds>. | ||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||
| 227 | Attempt to download all given feeds, as specified in the C<feeds> attribute. | ||||||||||||||||||||||||||||||||||||||
| 228 | Returns a list of L<Perlanet::Feed> objects, with the actual feed data | ||||||||||||||||||||||||||||||||||||||
| 229 | loaded. | ||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||
| 231 | NB: This method also modifies the contents of L</feeds>. | ||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||
| 235 | 12 | ▶ | sub fetch_feeds { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_feeds: called CC=8 SCAR=23.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 236 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 237 | 12 | my ($feeds) = @_; | |||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||
| 239 | 12 | my @valid_feeds; | |||||||||||||||||||||||||||||||||||||
| 240 | 12 | for my $feed (@$feeds) { | |||||||||||||||||||||||||||||||||||||
| 241 | 14 | ▶ | next unless $feed->feed; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | 14 | try { | |||||||||||||||||||||||||||||||||||||
| 244 | 14 | my $response = $self->fetch_feed($feed->feed); | |||||||||||||||||||||||||||||||||||||
| 245 | 14 | my $data = $response->content; | |||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||
| 247 | 14 | ▶ | die 'No data from ' . $feed->feed . "\n" unless $data; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||
| 249 | 14 | my $xml_feed = XML::Feed->parse(\$data); | |||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||
| 251 | 11 | ▶ | unless ($xml_feed) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 252 | 0 | warn "Can't make an object from " . $feed->feed . "\n"; | |||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $content_type = $response->content_type; | |||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | warn "Content type: $content_type\n" if $content_type; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $extract = substr $data, 0, 100; | |||||||||||||||||||||||||||||||||||||
| 256 | 0 | die "[$extract]\n"; | |||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | 11 | $feed->_xml_feed($xml_feed); | |||||||||||||||||||||||||||||||||||||
| 260 | 11 | ▶ | $feed->title($xml_feed->title) unless $feed->title; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||
| 262 | 11 | push @valid_feeds, $feed; | |||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||
| 264 | catch ($e) { | ||||||||||||||||||||||||||||||||||||||
| 265 | 3 | warn 'Errors parsing ' . $feed->feed, "\n"; | |||||||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | warn "$e\n" if defined $e; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||
| 270 | 12 | return \@valid_feeds; | |||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||
| 273 | =head2 select_entries | ||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||
| 275 | Called internally by L</run> and passed the list of feeds from | ||||||||||||||||||||||||||||||||||||||
| 276 | L</fetch_feeds>. | ||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||
| 278 | Returns a combined list of L<Perlanet::Entry> objects from all given feeds. | ||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||
| 280 | =cut | ||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||
| 282 | 11 | ▶ | sub select_entries { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
select_entries: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 283 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 284 | 11 | my ($feeds) = @_; | |||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||
| 286 | 11 | my @feed_entries; | |||||||||||||||||||||||||||||||||||||
| 287 | 11 | for my $feed (@$feeds) { | |||||||||||||||||||||||||||||||||||||
| 288 | 11 | for ($self->select_feed_entries($feed)->@*) { | |||||||||||||||||||||||||||||||||||||
| 289 | 69 | push @feed_entries, | |||||||||||||||||||||||||||||||||||||
| 290 | Perlanet::Entry->new( | ||||||||||||||||||||||||||||||||||||||
| 291 | _entry => $_, | ||||||||||||||||||||||||||||||||||||||
| 292 | feed => $feed, | ||||||||||||||||||||||||||||||||||||||
| 293 | ); | ||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||
| 297 | 11 | return \@feed_entries; | |||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||
| 300 | =head2 select_feed_entries | ||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||
| 302 | Called by L</select_entries> and passed one of the feeds from | ||||||||||||||||||||||||||||||||||||||
| 303 | L</fetch_feeds>. | ||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | Returns a list of the required entries from that feed. | ||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||
| 309 | 11 | ▶ | sub select_feed_entries { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
select_feed_entries: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 310 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 311 | 11 | my ($feed) = @_; | |||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||
| 313 | 11 | my @entries = grep { ! $self->is_spam_entry($_) } $feed->_xml_feed->entries; | |||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||
| 315 | 11 | $self->fixup_entry($_) for @entries; | |||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||
| 317 | 11 | @entries = $self->sort_entries(\@entries)->@*; | |||||||||||||||||||||||||||||||||||||
| 318 | 11 | @entries = $self->cutoff_entries(\@entries)->@*; | |||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||
| 320 | 11 | ▶ | my $number_of_entries = | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 321 | defined $feed->max_entries ? $feed->max_entries | ||||||||||||||||||||||||||||||||||||||
| 322 | : $self->entries_per_feed; | ||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||
| 324 | 11 | ▶ | if ($number_of_entries and @entries > $number_of_entries) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$number_of_entries and @entries > $number_of_entries
MC/DC50%1/2
$number_of_entries and @entries > $number_of_entries
$number_of_entries
@entries > $number_of_entries
Truth table66%2/3
A and B
A= $number_of_entriesB= @entries > $number_of_entries
| |||||||||||||||||||||||||||||||||||||||
| 325 | 8 | $#entries = $number_of_entries - 1; | |||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | 11 | return \@entries; | |||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||
| 331 | =head2 fixup_entry | ||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||
| 333 | Apply a couple of standard fix-ups to a feed entry. | ||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | =cut | ||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | 152 | ▶ | sub fixup_entry { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fixup_entry: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 338 | 152 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 339 | 152 | my ($entry) = @_; | |||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||
| 341 | 152 | state $date_zero = DateTime->from_epoch(epoch => 0); | |||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | # "Fix" entries with no dates | ||||||||||||||||||||||||||||||||||||||
| 344 | 152 | ▶ | unless ($entry->issued or $entry->modified) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$entry->issued or $entry->modified
MC/DC100%2/2
$entry->issued or $entry->modified
$entry->issued
$entry->modified
Truth table100%3/3
A or B
A= $entry->issuedB= $entry->modified
| |||||||||||||||||||||||||||||||||||||||
| 345 | 7 | $entry->issued($date_zero); | |||||||||||||||||||||||||||||||||||||
| 346 | 7 | $entry->modified($date_zero); | |||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | # Problem with XML::Feed's conversion of RSS to Atom | ||||||||||||||||||||||||||||||||||||||
| 350 | 152 | ▶ | if ($entry->issued && ! $entry->modified) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$entry->issued and not $entry->modified
MC/DC100%2/2
$entry->issued and not $entry->modified
$entry->issued
not $entry->modified
Truth table100%3/3
A and not(B)
A= $entry->issuedB= not $entry->modified
| |||||||||||||||||||||||||||||||||||||||
| 351 | 7 | $entry->modified($_->issued); | |||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||
| 354 | 152 | return $entry; | |||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||
| 357 | =head2 is_spam_entry | ||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | Called internally by L</select_entries>. | ||||||||||||||||||||||||||||||||||||||
| 360 | Called for each entry in the feed to determine if it is spam. | ||||||||||||||||||||||||||||||||||||||
| 361 | Takes a L<Perlanet::Entry> and returns true if the entry is spam. | ||||||||||||||||||||||||||||||||||||||
| 362 | If the entry is not spam, it returns false. | ||||||||||||||||||||||||||||||||||||||
| 363 | If the C<spam_regex> attribute is not set, this method will | ||||||||||||||||||||||||||||||||||||||
| 364 | return false for all entries. | ||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||
| 366 | =cut | ||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||
| 368 | 155 | ▶ | sub is_spam_entry { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_spam_entry: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 369 | 155 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 370 | 155 | my ($entry) = @_; | |||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||
| 372 | 155 | ▶ | return unless $self->spam_regex; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||
| 374 | 10 | my $re = $self->spam_regex; | |||||||||||||||||||||||||||||||||||||
| 375 | 10 | my $title = $entry->title; | |||||||||||||||||||||||||||||||||||||
| 376 | 10 | ▶ | my $content = $entry->content->{body} // $entry->summary->{body}; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$entry->content->{"body"} // $entry->summary->{"body"}
MC/DC0%0/2
$entry->content->{"body"} // $entry->summary->{"body"}
$entry->content->{"body"}
$entry->summary->{"body"}
Truth table33%1/3
A // B
A= $entry->content->{"body"}B= $entry->summary->{"body"}
| |||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||
| 378 | 10 | ▶ | return 1 if $title =~ /$re/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||
| 380 | 8 | ▶ | return unless defined $content; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||
| 382 | 8 | ▶ | return 1 if $content =~ /$re/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||
| 384 | 7 | return; | |||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||
| 387 | =head2 sort_entries | ||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||
| 389 | Called internally by L</run> and passed the list of entries from | ||||||||||||||||||||||||||||||||||||||
| 390 | L</select_entries>. | ||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||
| 392 | Sort the given list of entries into created/modified order for aggregation, | ||||||||||||||||||||||||||||||||||||||
| 393 | and filters them if necessary. | ||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||
| 395 | Takes a list of L<Perlanet::Entry>s, and returns an ordered list. | ||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||
| 397 | =cut | ||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||
| 399 | 17 | ▶ | sub sort_entries { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_entries: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 400 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 401 | 17 | my ($entries) = @_; | |||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||
| 403 | 17 | my @entries; | |||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||
| 405 | 17 | ▶ | if ($self->entry_sort_order eq 'modified') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 406 | 15 | @entries = sort _sort_by_modified $entries->@*; | |||||||||||||||||||||||||||||||||||||
| 407 | } elsif ($self->entry_sort_order eq 'issued') { | ||||||||||||||||||||||||||||||||||||||
| 408 | 2 | @entries = sort _sort_by_issued $entries->@*; | |||||||||||||||||||||||||||||||||||||
| 409 | } else { | ||||||||||||||||||||||||||||||||||||||
| 410 | 0 | die 'Invalid entry sort order: ' . $self->entry_sort_order; | |||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||
| 413 | 17 | return \@entries; | |||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||
| 416 | 383 | ▶ | sub _sort_by_modified ($$) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sort_by_modified: called CC=3 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||||
| 417 | 383 | ▶ | ($_[1]->modified || $_[1]->issued) | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$_[1]->modified || $_[1]->issued
$_[0]->modified || $_[0]->issued
MC/DC0%0/2
$_[1]->modified || $_[1]->issued
$_[1]->modified
$_[1]->issued
MC/DC0%0/2
$_[0]->modified || $_[0]->issued
$_[0]->modified
$_[0]->issued
Truth table33%1/3
A || B
A= $_[1]->modifiedB= $_[1]->issued
Truth table33%1/3
A || B
A= $_[0]->modifiedB= $_[0]->issued
| |||||||||||||||||||||||||||||||||||||||
| 418 | <=> | ||||||||||||||||||||||||||||||||||||||
| 419 | ($_[0]->modified || $_[0]->issued) | ||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||
| 422 | 62 | ▶ | sub _sort_by_issued ($$) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sort_by_issued: called CC=3 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||||
| 423 | 62 | ▶ | ($_[1]->issued || $_[1]->modified) | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$_[1]->issued || $_[1]->modified
$_[0]->issued || $_[0]->modified
MC/DC0%0/2
$_[1]->issued || $_[1]->modified
$_[1]->issued
$_[1]->modified
MC/DC0%0/2
$_[0]->issued || $_[0]->modified
$_[0]->issued
$_[0]->modified
Truth table33%1/3
A || B
A= $_[1]->issuedB= $_[1]->modified
Truth table33%1/3
A || B
A= $_[0]->issuedB= $_[0]->modified
| |||||||||||||||||||||||||||||||||||||||
| 424 | <=> | ||||||||||||||||||||||||||||||||||||||
| 425 | ($_[0]->issued || $_[0]->modified) | ||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||
| 428 | =head2 cutoff_entries | ||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||
| 430 | Called internally by L</run> and passed the list of entries from | ||||||||||||||||||||||||||||||||||||||
| 431 | L</sort_entries>. | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | Removes any entries that were published earlier than the cut-off | ||||||||||||||||||||||||||||||||||||||
| 434 | date for this feed. | ||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||
| 436 | =cut | ||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | 11 | ▶ | sub cutoff_entries { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cutoff_entries: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 439 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 440 | 11 | my ($entries) = @_; | |||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||
| 442 | my @entries = grep { | ||||||||||||||||||||||||||||||||||||||
| 443 | 11 | ▶ | ($_->issued || $_->modified) > $self->cutoff | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->issued || $_->modified
MC/DC0%0/2
$_->issued || $_->modified
$_->issued
$_->modified
Truth table66%2/3
A || B
A= $_->issuedB= $_->modified
| |||||||||||||||||||||||||||||||||||||||
| 444 | } @$entries; | ||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||
| 446 | 11 | return \@entries; | |||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||
| 449 | =head2 build_feed | ||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||
| 451 | Called internally by L</run> and passed the list of entries from | ||||||||||||||||||||||||||||||||||||||
| 452 | L</sort_entries>. | ||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||
| 454 | Takes a list of L<Perlanet::Entry>s, and returns a L<Perlanet::Feed> | ||||||||||||||||||||||||||||||||||||||
| 455 | that is the actual feed for the planet. | ||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||
| 457 | =cut | ||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||
| 459 | 4 | ▶ | sub build_feed { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
build_feed: called CC=7 SCAR=20.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 460 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 461 | 4 | my ($entries) = @_; | |||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||
| 463 | my %feed_data = ( | ||||||||||||||||||||||||||||||||||||||
| 464 | modified => DateTime->now, | ||||||||||||||||||||||||||||||||||||||
| 465 | feed => $self->config->{url}, | ||||||||||||||||||||||||||||||||||||||
| 466 | 4 | ); | |||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||
| 468 | 4 | for (qw[title description]) { | |||||||||||||||||||||||||||||||||||||
| 469 | 8 | ▶ | $feed_data{$_} = $self->$_ if defined $self->$_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||
| 472 | 4 | ▶ | if (defined $self->author) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 473 | 4 | ▶ | $feed_data{author} = $self->author->{name} if defined $self->author->{name}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 474 | 4 | ▶ | $feed_data{email} = $self->author->{email} if defined $self->author->{email}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||
| 477 | 4 | ▶ | if (defined $self->url) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 478 | 4 | $feed_data{self_link} = $self->url; | |||||||||||||||||||||||||||||||||||||
| 479 | 4 | $feed_data{id} = $self->url | |||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||
| 482 | 4 | $feed_data{entries} = $entries; | |||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||
| 484 | 4 | my $f = Perlanet::Feed->new( | |||||||||||||||||||||||||||||||||||||
| 485 | %feed_data, | ||||||||||||||||||||||||||||||||||||||
| 486 | ); | ||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||
| 488 | 4 | return $f; | |||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||
| 492 | =head2 clean_html | ||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||
| 494 | Clean a HTML string so it is suitable for display. | ||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||
| 496 | Takes a HTML string and returns a "cleaned" HTML string. | ||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||
| 498 | =cut | ||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||
| 500 | 7 | ▶ | sub clean_html { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_html: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 501 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 502 | 7 | my ($entry) = @_; | |||||||||||||||||||||||||||||||||||||
| 503 | 7 | return $entry; | |||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||
| 506 | =head2 clean_entries | ||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||
| 508 | Clean all entries for the planet. | ||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||
| 510 | Takes a list of entries, runs them through C<clean> and returns a list of | ||||||||||||||||||||||||||||||||||||||
| 511 | cleaned entries. | ||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||
| 513 | =cut | ||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||
| 515 | 4 | ▶ | sub clean_entries { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_entries: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 516 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 517 | 4 | my ($entries) = @_; | |||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||
| 519 | 4 | my @clean_entries; | |||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||
| 521 | 4 | foreach (@$entries) { | |||||||||||||||||||||||||||||||||||||
| 522 | 4 | ▶ | if (my $body = $_->content->body) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 523 | 3 | my $cleaned = $self->clean_html($body); | |||||||||||||||||||||||||||||||||||||
| 524 | 3 | $_->content->body($cleaned); | |||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||
| 527 | 4 | ▶ | if (my $summary = $_->summary->body) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 528 | 4 | my $cleaned = $self->clean_html($summary); | |||||||||||||||||||||||||||||||||||||
| 529 | 4 | $_->summary->body($cleaned); | |||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||
| 532 | 4 | push @clean_entries, $_; | |||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||
| 535 | 4 | return \@clean_entries; | |||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||
| 538 | =head2 render | ||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||
| 540 | Called internally by L</run> and passed the feed from L</build_feed>. | ||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||
| 542 | This is the hook where you generate some type of page to display the result | ||||||||||||||||||||||||||||||||||||||
| 543 | of aggregating feeds together (ie, inserting the posts into a database, | ||||||||||||||||||||||||||||||||||||||
| 544 | running a HTML templating library, etc) | ||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||
| 546 | Takes a L<Perlanet::Feed> as input (as generated by L<build_feed>. | ||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||
| 548 | =cut | ||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||
| 550 | 2 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 551 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 552 | 2 | my ($feed) = @_; | |||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||
| 555 | =head2 run | ||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||
| 557 | The main method which runs the perlanet process. | ||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||
| 559 | =cut | ||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||
| 561 | 2 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 562 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||
| 564 | 2 | my $feeds = $self->fetch_feeds($self->feeds); | |||||||||||||||||||||||||||||||||||||
| 565 | 2 | my $selected = $self->select_entries($feeds); | |||||||||||||||||||||||||||||||||||||
| 566 | 2 | my $sorted = $self->sort_entries($selected); | |||||||||||||||||||||||||||||||||||||
| 567 | 2 | my $cleaned = $self->clean_entries($sorted); | |||||||||||||||||||||||||||||||||||||
| 568 | 2 | my $feed = $self->build_feed($cleaned); | |||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||
| 570 | 2 | $self->render($feed); | |||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||
| 573 | 12 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 574 | 12 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||
| 576 | =head1 TO DO | ||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||
| 578 | See L<https://github.com/davorg/perlanet/issues> | ||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||
| 580 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||
| 582 | To report bugs in Perlanet, please use the ticket queue at | ||||||||||||||||||||||||||||||||||||||
| 583 | L<https://github.com/davorg/perlanet/issues>. | ||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||
| 585 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||
| 587 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||
| 589 | =item * | ||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||
| 591 | L<perlanet> | ||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||
| 593 | =item * | ||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||
| 595 | L<Plagger> | ||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||
| 597 | =back | ||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||
| 599 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||
| 601 | Dave Cross, <dave@perlhacks.com> | ||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||
| 603 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||
| 605 | Copyright (c) 2010 by Magnum Solutions Ltd. | ||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||
| 607 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||
| 608 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||||||||||||||||||||||||||||||||||||||
| 609 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||
| 611 | =cut | ||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||
| 613 | 12 | 1; | |||||||||||||||||||||||||||||||||||||