App-FeedDeduplicator

 view release on metacpan or  search on metacpan

lib/App/FeedDeduplicator/Publisher.pm  view on Meta::CPAN

should contain a hash reference with the feed information.

The format should be either 'Atom' or 'JSON', and the maximum number of
entries specifies how many entries to include in the output.

=head2 publish

The main method that publishes the deduplicated entries to the specified
format (Atom or JSON).

It sorts the entries based on their issued, modified, updated, or date
attributes and limits the output to the specified maximum number of entries.

It generates the output in the specified format and prints it to STDOUT.

=cut

use v5.40;
use feature 'class';
no warnings 'experimental::class';

class App::FeedDeduplicator::Publisher {
  use XML::Feed;
  use JSON::MaybeXS;

  field $entries     :param;
  field $format      :param //= 'Atom';
  field $max_entries :param //= 10;

  method publish {
    my @sorted = sort {
      ($b->{entry}->issued || $b->{entry}->modified || $b->{entry}->updated || $b->{entry}->date || 0)
        <=>
      ($a->{entry}->issued || $a->{entry}->modified || $a->{entry}->updated || $a->{entry}->date || 0)
    } @$entries;

    if (@sorted > $max_entries) {
      $#sorted = $max_entries - 1;
    }

    if ($format eq 'json') {
      say encode_json([ map { {
        title => $_->{entry}->title,
        link  => $_->{entry}->link,



( run in 0.949 second using v1.01-cache-2.11-cpan-364913b4093 )