From 89a5e656a0051a1abe54ce00d3b631b620f28b05 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 13 Aug 2014 17:15:05 -0400 Subject: [PATCH 1/3] refactor contributor handling to allow display on module pages --- lib/MetaCPAN/Web/Controller/Pod.pm | 3 +++ lib/MetaCPAN/Web/Controller/Release.pm | 35 +++---------------------- lib/MetaCPAN/Web/Role/ReleaseInfo.pm | 36 ++++++++++++++++++++++++++ root/inc/contributors.html | 2 +- root/pod.html | 5 +++- root/release.html | 3 +-- 6 files changed, 48 insertions(+), 36 deletions(-) diff --git a/lib/MetaCPAN/Web/Controller/Pod.pm b/lib/MetaCPAN/Web/Controller/Pod.pm index 579a98620b2..52c2ed15fda 100644 --- a/lib/MetaCPAN/Web/Controller/Pod.pm +++ b/lib/MetaCPAN/Web/Controller/Pod.pm @@ -161,6 +161,8 @@ sub view : Private { my $dist = $release->{distribution}; $c->stash( $c->model('API::Favorite')->find_plussers($dist) ); + my $contribs = $self->groom_contributors( $c, $release ); + $c->stash( { module => $data, @@ -169,6 +171,7 @@ sub view : Private { template => 'pod.html', canonical => $canonical, documented_module => $documented_module, + contributors => $contribs, } ); unless ( $reqs->{pod}->{raw} ) { diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index 54e13360488..0534bbb7fb5 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -101,7 +101,7 @@ sub view : Private { $c->res->last_modified( $out->{date} ); - $self->groom_contributors( $c, $out ); + my $contribs = $self->groom_contributors( $c, $out ); $c->stash( $c->model('API::Favorite')->find_plussers($distribution) ); @@ -123,6 +123,8 @@ sub view : Private { examples => \@examples, files => \@view_files, + contributors => $contribs, + # TODO: Put this in a more general place. # Maybe make a hash for feature flags? ( @@ -135,35 +137,4 @@ sub view : Private { ); } -# massage the x_contributors field into what we want -sub groom_contributors { - my ( $self, $c, $out ) = @_; - - return unless $out->{metadata}{x_contributors}; - - # just in case a lonely contributor makes it as a scalar - $out->{metadata}{x_contributors} = [ $out->{metadata}{x_contributors} ] - unless ref $out->{metadata}{x_contributors}; - - my @contributors = map { - s/<(.*)>//; - { name => $_, email => $1 } - } @{ $out->{metadata}{x_contributors} }; - - $out->{metadata}{x_contributors} = \@contributors; - - for my $contributor ( @{ $out->{metadata}{x_contributors} } ) { - - # heuristic to autofill pause accounts - $contributor->{pauseid} = uc $1 - if !$contributor->{pauseid} - and $contributor->{email} =~ /^(.*)\@cpan.org/; - - next unless $contributor->{pauseid}; - - $contributor->{url} = $c->uri_for_action( '/author/index', - [ $contributor->{pauseid} ] ); - } -} - 1; diff --git a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm index e02f1f2ecbf..285c14fadfe 100644 --- a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm +++ b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm @@ -67,4 +67,40 @@ sub recv_all { return { map { $_ => $condvars->{$_}->recv } keys %$condvars }; } +# massage the x_contributors field into what we want +sub groom_contributors { + my ( $self, $c, $release ) = @_; + + my $contribs = $release->{metadata}{x_contributors} || []; + + # just in case a lonely contributor makes it as a scalar + $contribs = [$contribs] + if !ref $contribs; + + my @contribs; + for my $contrib (@$contribs) { + my $name = $contrib; + $name =~ s/\s*<([^<>]+@[^<>]+)>//; + my $info = { + name => $name, + $1 ? ( email => $1 ) : (), + }; + + # heuristic to autofill pause accounts + if ( !$info->{pauseid} + and $info->{email} =~ /^(.*)\@cpan\.org$/ ) + { + $info->{pauseid} = uc $1; + } + + if ( $info->{pauseid} ) { + $info->{url} + = $c->uri_for_action( '/author/index', [ $info->{pauseid} ] ); + } + push @contribs, $info; + } + + return \@contribs; +} + 1; diff --git a/root/inc/contributors.html b/root/inc/contributors.html index 90cf5d3da1d..5415256c862 100644 --- a/root/inc/contributors.html +++ b/root/inc/contributors.html @@ -1,4 +1,4 @@ -<% IF contributors %> +<% IF contributors and contributors.size %>
and <% contributors.size %> contributors diff --git a/root/pod.html b/root/pod.html index 71c8ce9b79e..d93082dc51b 100644 --- a/root/pod.html +++ b/root/pod.html @@ -36,7 +36,10 @@
-
<% INCLUDE inc/author-pic.html author = author %>
+
+<% INCLUDE inc/author-pic.html author = author %> +<% INCLUDE inc/contributors.html contributors = contributors %> +
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>
<% IF req.cookies.hideTOC.value %><% END %> diff --git a/root/release.html b/root/release.html index a739e253833..162f72e97ba 100644 --- a/root/release.html +++ b/root/release.html @@ -27,8 +27,7 @@
<% INCLUDE inc/author-pic.html author = author %> -<% INCLUDE inc/contributors.html - contributors = release.metadata.x_contributors %> +<% INCLUDE inc/contributors.html contributors = contributors %>
<% INCLUDE inc/dependencies.html dependencies = release.dependency %> From 3bd923f46ad915623c4e63ebe2e84b29546e3e7d Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 13 Aug 2014 17:17:10 -0400 Subject: [PATCH 2/3] include authors in contributors list --- lib/MetaCPAN/Web/Role/ReleaseInfo.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm index 285c14fadfe..99b52700b62 100644 --- a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm +++ b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm @@ -72,13 +72,18 @@ sub groom_contributors { my ( $self, $c, $release ) = @_; my $contribs = $release->{metadata}{x_contributors} || []; + my $authors = $release->{metadata}{author} || []; # just in case a lonely contributor makes it as a scalar $contribs = [$contribs] if !ref $contribs; + $authors = [$authors] + if !ref $authors; + my %seen = ( lc "$release->{author}\@cpan.org" => 1, ); my @contribs; - for my $contrib (@$contribs) { + + for my $contrib ( @$authors, @$contribs ) { my $name = $contrib; $name =~ s/\s*<([^<>]+@[^<>]+)>//; my $info = { @@ -86,6 +91,9 @@ sub groom_contributors { $1 ? ( email => $1 ) : (), }; + next + if $seen{ $info->{email} }++; + # heuristic to autofill pause accounts if ( !$info->{pauseid} and $info->{email} =~ /^(.*)\@cpan\.org$/ ) From 17b89b8dafdb1b860c759641ceea9e411062ad30 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 13 Aug 2014 17:38:24 -0400 Subject: [PATCH 3/3] clean up formatting of contributors list --- root/inc/contributors.html | 8 ++++---- root/static/css/style.css | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/root/inc/contributors.html b/root/inc/contributors.html index 5415256c862..d4d9ddd4dab 100644 --- a/root/inc/contributors.html +++ b/root/inc/contributors.html @@ -1,13 +1,13 @@ <% IF contributors and contributors.size %>
- and <% contributors.size %> contributors +
and <% contributors.size %> contributors
-
    +