Skip to content

Commit 89a5e65

Browse files
committed
refactor contributor handling to allow display on module pages
1 parent 2ff3bb2 commit 89a5e65

File tree

6 files changed

+48
-36
lines changed

6 files changed

+48
-36
lines changed

lib/MetaCPAN/Web/Controller/Pod.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ sub view : Private {
161161
my $dist = $release->{distribution};
162162
$c->stash( $c->model('API::Favorite')->find_plussers($dist) );
163163

164+
my $contribs = $self->groom_contributors( $c, $release );
165+
164166
$c->stash(
165167
{
166168
module => $data,
@@ -169,6 +171,7 @@ sub view : Private {
169171
template => 'pod.html',
170172
canonical => $canonical,
171173
documented_module => $documented_module,
174+
contributors => $contribs,
172175
}
173176
);
174177
unless ( $reqs->{pod}->{raw} ) {

lib/MetaCPAN/Web/Controller/Release.pm

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ sub view : Private {
101101

102102
$c->res->last_modified( $out->{date} );
103103

104-
$self->groom_contributors( $c, $out );
104+
my $contribs = $self->groom_contributors( $c, $out );
105105

106106
$c->stash( $c->model('API::Favorite')->find_plussers($distribution) );
107107

@@ -123,6 +123,8 @@ sub view : Private {
123123
examples => \@examples,
124124
files => \@view_files,
125125

126+
contributors => $contribs,
127+
126128
# TODO: Put this in a more general place.
127129
# Maybe make a hash for feature flags?
128130
(
@@ -135,35 +137,4 @@ sub view : Private {
135137
);
136138
}
137139

138-
# massage the x_contributors field into what we want
139-
sub groom_contributors {
140-
my ( $self, $c, $out ) = @_;
141-
142-
return unless $out->{metadata}{x_contributors};
143-
144-
# just in case a lonely contributor makes it as a scalar
145-
$out->{metadata}{x_contributors} = [ $out->{metadata}{x_contributors} ]
146-
unless ref $out->{metadata}{x_contributors};
147-
148-
my @contributors = map {
149-
s/<(.*)>//;
150-
{ name => $_, email => $1 }
151-
} @{ $out->{metadata}{x_contributors} };
152-
153-
$out->{metadata}{x_contributors} = \@contributors;
154-
155-
for my $contributor ( @{ $out->{metadata}{x_contributors} } ) {
156-
157-
# heuristic to autofill pause accounts
158-
$contributor->{pauseid} = uc $1
159-
if !$contributor->{pauseid}
160-
and $contributor->{email} =~ /^(.*)\@cpan.org/;
161-
162-
next unless $contributor->{pauseid};
163-
164-
$contributor->{url} = $c->uri_for_action( '/author/index',
165-
[ $contributor->{pauseid} ] );
166-
}
167-
}
168-
169140
1;

lib/MetaCPAN/Web/Role/ReleaseInfo.pm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,40 @@ sub recv_all {
6767
return { map { $_ => $condvars->{$_}->recv } keys %$condvars };
6868
}
6969

70+
# massage the x_contributors field into what we want
71+
sub groom_contributors {
72+
my ( $self, $c, $release ) = @_;
73+
74+
my $contribs = $release->{metadata}{x_contributors} || [];
75+
76+
# just in case a lonely contributor makes it as a scalar
77+
$contribs = [$contribs]
78+
if !ref $contribs;
79+
80+
my @contribs;
81+
for my $contrib (@$contribs) {
82+
my $name = $contrib;
83+
$name =~ s/\s*<([^<>]+@[^<>]+)>//;
84+
my $info = {
85+
name => $name,
86+
$1 ? ( email => $1 ) : (),
87+
};
88+
89+
# heuristic to autofill pause accounts
90+
if ( !$info->{pauseid}
91+
and $info->{email} =~ /^(.*)\@cpan\.org$/ )
92+
{
93+
$info->{pauseid} = uc $1;
94+
}
95+
96+
if ( $info->{pauseid} ) {
97+
$info->{url}
98+
= $c->uri_for_action( '/author/index', [ $info->{pauseid} ] );
99+
}
100+
push @contribs, $info;
101+
}
102+
103+
return \@contribs;
104+
}
105+
70106
1;

root/inc/contributors.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% IF contributors %>
1+
<% IF contributors and contributors.size %>
22

33
<div id="contributors">
44
<strong>and <% contributors.size %> contributors</strong>

root/pod.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
</ul>
3737

3838
<div class="pull-right">
39-
<div class="pull-right"><% INCLUDE inc/author-pic.html author = author %></div>
39+
<div class="pull-right">
40+
<% INCLUDE inc/author-pic.html author = author %>
41+
<% INCLUDE inc/contributors.html contributors = contributors %>
42+
</div>
4043
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>
4144
</div>
4245
<% IF req.cookies.hideTOC.value %><style>#index { display:none}</style><% END %>

root/release.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727

2828
<div class="pull-right hidden-phone">
2929
<% INCLUDE inc/author-pic.html author = author %>
30-
<% INCLUDE inc/contributors.html
31-
contributors = release.metadata.x_contributors %>
30+
<% INCLUDE inc/contributors.html contributors = contributors %>
3231
</div>
3332
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>
3433

0 commit comments

Comments
 (0)