App-FeedDeduplicator
view release on metacpan or search on metacpan
lib/App/FeedDeduplicator/Aggregator.pm view on Meta::CPAN
my $aggregator = App::FeedDeduplicator::Aggregator->new(
feeds => [{
name => 'Feed 1',
feed => 'http://example.com/feed1',
web => 'http://example.com',
}, {
name => 'Feed 2',
feed => 'http://example.com/feed2',
web => 'http://example.com',
}],
ua => LWP::UserAgent->new(),
);
$aggregator->aggregate();
=head1 METHODS
=head2 new
Creates a new instance of App::FeedDeduplicator::Aggregator. The constructor
accepts a list of feeds and a user agent as parameters.
The feeds should be an array reference containing hash references with the
keys 'name', 'feed', and 'web'.
The user agent should be an instance of LWP::UserAgent.
=head2 aggregate
The main method that aggregates feeds from the specified sources. It fetches
each feed using the provided user agent and parses it using XML::Feed.
It stores the aggregated entries in an array for further processing. The
entries are stored as hash references containing the entry and the
corresponding feed information.
=cut
use v5.40;
use feature 'class';
no warnings 'experimental::class';
class App::FeedDeduplicator::Aggregator {
use XML::Feed;
use LWP::UserAgent;
field $feeds :param;
field $ua :param;
field $entries :reader;
method aggregate {
for (@$feeds) {
my $response = $ua->get($_->{feed});
unless ($response->is_success) {
warn "$_->{feed}\n";
warn $response->status_line, "\n";
next;
}
my $feed = XML::Feed->parse(\$response->decoded_content);
unless ($feed) {
warn "Unable to parse $_->{feed}\n";
next;
}
for my $entry ($feed->entries) {
push @$entries, {
entry => $entry,
feed => $_,
}
}
}
}
}
=head1 AUTHOR
Dave Cross <dave@perlhacks.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2025 Magnum Solutions Ltd.
All rights reserved.
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
See L<http://dev.perl.org/licenses/artistic.html> for more details.
=cut
1;
( run in 0.522 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )