| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | App::FeedDeduplicator::Aggregator - Aggregator class for App::FeedDeduplicator | ||||||||||
| 4 | |||||||||||
| 5 | =head1 DESCRIPTION | ||||||||||
| 6 | |||||||||||
| 7 | This module is part of the App::FeedDeduplicator application. It is | ||||||||||
| 8 | responsible for aggregating feeds from multiple sources. | ||||||||||
| 9 | |||||||||||
| 10 | It fetches the feeds using LWP::UserAgent and parses them using XML::Feed. | ||||||||||
| 11 | The aggregated entries are stored in an array for further processing. | ||||||||||
| 12 | |||||||||||
| 13 | It is designed to be used in conjunction with the Deduplicator and Publisher | ||||||||||
| 14 | classes to provide a complete feed deduplication and publishing solution. | ||||||||||
| 15 | |||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||
| 17 | |||||||||||
| 18 | use App::FeedDeduplicator::Aggregator; | ||||||||||
| 19 | |||||||||||
| 20 | my $aggregator = App::FeedDeduplicator::Aggregator->new( | ||||||||||
| 21 | feeds => [{ | ||||||||||
| 22 | name => 'Feed 1', | ||||||||||
| 23 | feed => 'http://example.com/feed1', | ||||||||||
| 24 | web => 'http://example.com', | ||||||||||
| 25 | }, { | ||||||||||
| 26 | name => 'Feed 2', | ||||||||||
| 27 | feed => 'http://example.com/feed2', | ||||||||||
| 28 | web => 'http://example.com', | ||||||||||
| 29 | }], | ||||||||||
| 30 | ua => LWP::UserAgent->new(), | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | $aggregator->aggregate(); | ||||||||||
| 34 | |||||||||||
| 35 | =head1 METHODS | ||||||||||
| 36 | |||||||||||
| 37 | =head2 new | ||||||||||
| 38 | |||||||||||
| 39 | Creates a new instance of App::FeedDeduplicator::Aggregator. The constructor | ||||||||||
| 40 | accepts a list of feeds and a user agent as parameters. | ||||||||||
| 41 | |||||||||||
| 42 | The feeds should be an array reference containing hash references with the | ||||||||||
| 43 | keys 'name', 'feed', and 'web'. | ||||||||||
| 44 | |||||||||||
| 45 | The user agent should be an instance of LWP::UserAgent. | ||||||||||
| 46 | |||||||||||
| 47 | =head2 aggregate | ||||||||||
| 48 | |||||||||||
| 49 | The main method that aggregates feeds from the specified sources. It fetches | ||||||||||
| 50 | each feed using the provided user agent and parses it using XML::Feed. | ||||||||||
| 51 | |||||||||||
| 52 | It stores the aggregated entries in an array for further processing. The | ||||||||||
| 53 | entries are stored as hash references containing the entry and the | ||||||||||
| 54 | corresponding feed information. | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 1 | ▶ | use v5.40; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 1 | ▶ | use feature 'class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 1 | ▶ | no warnings 'experimental::class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 61 | |||||||||||
| 62 | 1 | class App::FeedDeduplicator::Aggregator { | |||||||||
| 63 | 1 | ▶ | use XML::Feed; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 65 | |||||||||||
| 66 | 1 | field $feeds :param; | |||||||||
| 67 | 1 | field $ua :param; | |||||||||
| 68 | 1 | field $entries :reader; | |||||||||
| 69 | |||||||||||
| 70 | 1 | ▶ | method aggregate { | ||||||||
|
Subroutine
aggregate: called CC=5 SCAR=32.4
Pod
documented
| |||||||||||
| 71 | |||||||||||
| 72 | 1 | for (@$feeds) { | |||||||||
| 73 | 0 | my $response = $ua->get($_->{feed}); | |||||||||
| 74 | 0 | ▶ | unless ($response->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 0 | warn "$_->{feed}\n"; | |||||||||
| 76 | 0 | warn $response->status_line, "\n"; | |||||||||
| 77 | 0 | next; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 0 | my $feed = XML::Feed->parse(\$response->decoded_content); | |||||||||
| 81 | 0 | ▶ | unless ($feed) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | warn "Unable to parse $_->{feed}\n"; | |||||||||
| 83 | 0 | next; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | for my $entry ($feed->entries) { | |||||||||
| 87 | 0 | push @$entries, { | |||||||||
| 88 | entry => $entry, | ||||||||||
| 89 | feed => $_, | ||||||||||
| 90 | } | ||||||||||
| 91 | } | ||||||||||
| 92 | } | ||||||||||
| 93 | } | ||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | =head1 AUTHOR | ||||||||||
| 97 | |||||||||||
| 98 | Dave Cross <dave@perlhacks.com> | ||||||||||
| 99 | |||||||||||
| 100 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 101 | |||||||||||
| 102 | This software is copyright (c) 2025 Magnum Solutions Ltd. | ||||||||||
| 103 | All rights reserved. | ||||||||||
| 104 | |||||||||||
| 105 | This program is free software; you can redistribute it and/or modify it under | ||||||||||
| 106 | the same terms as Perl itself. | ||||||||||
| 107 | |||||||||||
| 108 | See L<http://dev.perl.org/licenses/artistic.html> for more details. | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||
| 111 | |||||||||||
| 112 | 1 | 1; | |||||||||