Skip to content

Commit

Permalink
Merge pull request #2947 from metacpan/haarg/feed-date-rdf
Browse files Browse the repository at this point in the history
re-add RDF recent feed for use by CPAN.pm
  • Loading branch information
haarg authored Oct 23, 2023
2 parents 917b03c + c69d325 commit 3570672
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ requires 'Try::Tiny', '0.24';
requires 'Type::Library';
requires 'Types::Common::Numeric';
requires 'Types::Common::String';
requires 'Types::DateTime';
requires 'Types::LoadableClass';
requires 'Types::Path::Tiny';
requires 'Types::Standard';
Expand Down
13 changes: 13 additions & 0 deletions cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5706,6 +5706,19 @@ DISTRIBUTIONS
Exporter::Tiny 1.006000
ExtUtils::MakeMaker 6.17
perl 5.008001
Types-DateTime-0.002
pathname: T/TO/TOBYINK/Types-DateTime-0.002.tar.gz
provides:
Types::DateTime 0.002
requirements:
DateTime 0
DateTime::Duration 0
DateTime::Locale 0
DateTime::TimeZone 0
ExtUtils::MakeMaker 6.17
Module::Runtime 0
Type::Tiny 0.041
perl 5.008
Types-LoadableClass-0.003
pathname: T/TO/TOBYINK/Types-LoadableClass-0.003.tar.gz
provides:
Expand Down
35 changes: 30 additions & 5 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ use namespace::autoclean;

BEGIN { extends 'MetaCPAN::Web::Controller' }

use HTML::Escape qw( escape_html );
use MetaCPAN::Web::Types qw( ArrayRef Enum HashRef Str Undef Uri );
use DateTime ();
use HTML::Escape qw( escape_html );
use MetaCPAN::Web::Types qw( ArrayRef Enum HashRef Str Undef Uri DateTime );
use Params::ValidationCompiler qw( validation_for );
use Path::Tiny qw( path );
use Text::MultiMarkdown qw( markdown );
use URI ();
use XML::FeedPP ();

sub recent_rdf : Path('/recent.rdf') Args(0) {
my ( $self, $c ) = @_;
$c->detach( 'recent', ['rdf'] );
}

sub recent_rss : Path('/recent.rss') Args(0) {
my ( $self, $c ) = @_;
$c->detach( 'recent', ['rss'] );
Expand Down Expand Up @@ -46,6 +53,8 @@ sub recent : Private {
entries => $c->stash->{recent},
host => URI->new( $c->config->{web_host} ),
title => 'Recent CPAN uploads - MetaCPAN',
link => '/recent',
date => DateTime::->now,
);
}

Expand Down Expand Up @@ -179,7 +188,19 @@ my $feed_check = validation_for(
entries => { type => ArrayRef [HashRef] },
host => { type => Uri, optional => 0, },
title => { type => Str },
format => {
link => {
type => Uri,
default => '/',
},
date => {
type => DateTime,
optional => 1,
},
description => {
type => Str,
optional => 1,
},
format => {
type => Enum( [qw(atom rdf rss)] )
->plus_coercions( Undef, '"rdf"', Str, 'lc $_' ),
default => 'rdf'
Expand Down Expand Up @@ -233,11 +254,15 @@ sub build_feed {
: $params{format} eq 'atom' ? 'Atom::Atom10'
: die 'invalid format';

my $feed_class = sprintf( '%s::%s', XML::FeedPP::, $format );
my $feed_class = "XML::FeedPP::$format";

my $feed = $feed_class->new;
$feed->title( $params{title} );
$feed->link('/');
$feed->link("$params{link}");
$feed->pubDate( $params{date}->iso8601 )
if $params{date};
$feed->description( $params{description} )
if $params{description};

foreach my $entry ( @{ $params{entries} } ) {
$feed->add_item( $self->build_entry(
Expand Down
1 change: 1 addition & 0 deletions lib/MetaCPAN/Web/Types.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ BEGIN {
Types::Standard
Types::Common::Numeric
Types::Common::String
Types::DateTime
Types::LoadableClass
Types::Path::Tiny
Types::URI
Expand Down

0 comments on commit 3570672

Please sign in to comment.