Skip to content

Commit

Permalink
Adds Params::CheckCompiler to cpanfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Nov 19, 2016
1 parent 8be043c commit 0eca0e5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 18 deletions.
3 changes: 2 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ requires 'MetaCPAN::Role', '0.05';
requires 'MooseX::Types::Common::Numeric';
requires 'MooseX::Types::Common::String';
requires 'MooseX::Types::Moose';
requires 'MooseX::Types::URI';
requires 'MooseX::Types::URI', '0.08';
requires 'Net::Fastly', '1.05';
requires 'Path::Tiny', '0.076';
requires 'Params::CheckCompiler';
requires 'Plack', '1.0039';
requires 'Plack::Middleware::ReverseProxy';
requires 'Plack::Middleware::Runtime';
Expand Down
17 changes: 17 additions & 0 deletions cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4067,6 +4067,23 @@ DISTRIBUTIONS
JSON 0
Test::More 0
Test::Warn 0
Params-CheckCompiler-0.07
pathname: D/DR/DROLSKY/Params-CheckCompiler-0.07.tar.gz
provides:
Params::CheckCompiler 0.07
Params::CheckCompiler::Compiler 0.07
Params::CheckCompiler::Exceptions 0.07
requirements:
Eval::Closure 0
Exception::Class 0
Exporter 0
ExtUtils::MakeMaker 0
List::SomeUtils 0
Scalar::Util 0
Sub::Name 0
overload 0
strict 0
warnings 0
Params-Util-1.07
pathname: A/AD/ADAMK/Params-Util-1.07.tar.gz
provides:
Expand Down
54 changes: 41 additions & 13 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package MetaCPAN::Web::Controller::Feed;

use Moose;
use namespace::autoclean;
use feature qw( state );

BEGIN { extends 'MetaCPAN::Web::Controller' }
use XML::Feed;

use DateTime::Format::ISO8601 ();
use HTML::Escape qw/escape_html/;
use DateTime::Format::ISO8601;
use MetaCPAN::Web::Types qw( ArrayRef HashRef Str Uri );
use Params::CheckCompiler qw( validation_for );
use Path::Tiny qw/path/;
use Text::Markdown qw/markdown/;
use XML::Feed ();

use Importer 'MetaCPAN::Web::Elasticsearch::Adapter' =>
qw/ single_valued_arrayref_to_scalar /;
Expand All @@ -23,9 +27,8 @@ sub recent : Chained('feed_index') PathPart Args(0) {
# Set surrogate key and ttl from here as well
$c->forward('/recent/index');

my $data = $c->stash;
$c->stash->{feed} = $self->build_feed(
entries => $data->{recent},
entries => $c->stash->{recent},
host => URI->new( $c->config->{web_host} ),
title => 'Recent CPAN uploads - MetaCPAN',
);
Expand Down Expand Up @@ -68,8 +71,9 @@ sub news : Local : Args(0) {
}

$c->stash->{feed} = $self->build_feed(
title => 'Recent MetaCPAN News',
entries => \@entries,
host => $c->config->{web_host},
title => 'Recent MetaCPAN News',
);
}

Expand Down Expand Up @@ -118,6 +122,7 @@ sub author : Local : Args(1) {
: [];

$c->stash->{feed} = $self->build_feed(
host => $c->config->{web_host},
title => "Recent CPAN activity of $author - MetaCPAN",
entries => [
sort { $b->{date} cmp $a->{date} }
Expand All @@ -136,6 +141,7 @@ sub distribution : Local : Args(1) {

my $data = $c->model('API::Release')->versions($distribution)->recv;
$c->stash->{feed} = $self->build_feed(
host => $c->config->{web_host},
title => "Recent CPAN uploads of $distribution - MetaCPAN",
entries => [
map { single_valued_arrayref_to_scalar($_) }
Expand All @@ -145,17 +151,27 @@ sub distribution : Local : Args(1) {
}

sub build_entry {
my ( $self, $entry, $host ) = @_;
my $self = shift;

state $check = validation_for(
params => {
entry => { type => HashRef },
host => { type => Uri },
}
);

my %args = $check->(@_);
my $entry = $args{entry};

single_valued_arrayref_to_scalar($entry);
my $e = XML::Feed::Entry->new('RSS');

$e->title( $entry->{name} );
unless ( $entry->{link} ) {
my $uri = $host->clone;
$entry->{link} ||= do {
my $uri = $args{host}->clone;
$uri->path(
join( q{/}, 'release', $entry->{author}, $entry->{name} ) );
$entry->{link} = $uri->as_string;
}
$uri->as_string;
};
$e->link( $entry->{link} );
$e->author( $entry->{author} );
$e->issued( DateTime::Format::ISO8601->parse_datetime( $entry->{date} ) );
Expand All @@ -164,13 +180,25 @@ sub build_entry {
}

sub build_feed {
my ( $self, %params ) = @_;
my $self = shift;

state $check = validation_for(
params => {
entries => { type => ArrayRef },
host => { type => Uri, optional => 0, },
title => Str,
}
);

my %params = $check->(@_);

my $feed = XML::Feed->new( 'RSS', version => 2.0 );
$feed->title( $params{title} );
$feed->link('/');

foreach my $entry ( @{ $params{entries} } ) {
$feed->add_entry( $self->build_entry( $entry, $params{host} ) );
$feed->add_entry(
$self->build_entry( entry => $entry, host => $params{host} ) );
}
return $feed->as_xml;
}
Expand Down
9 changes: 5 additions & 4 deletions t/controller/feed.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use strict;
use warnings;
use Test::More;

use MetaCPAN::Web ();
use MetaCPAN::Web::Controller::Feed ();
use MetaCPAN::Web::Test;
use Try::Tiny;
use MetaCPAN::Web;
use MetaCPAN::Web::Controller::Feed;
use Test::More;
use Try::Tiny qw( catch try );

sub get_feed_ok {
my ( $cb, $test, $extra ) = @_;
Expand Down

0 comments on commit 0eca0e5

Please sign in to comment.