From e790392398b13fe1ee2174e2a1c9a90349e06489 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 13 Aug 2014 17:18:05 -0400 Subject: [PATCH 1/2] add irc links if included in metadata --- lib/MetaCPAN/Web/Controller/Release.pm | 2 ++ lib/MetaCPAN/Web/Role/ReleaseInfo.pm | 19 +++++++++++++++++++ root/inc/release-info.html | 7 ++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index 0534bbb7fb5..99a0effb2c3 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -102,6 +102,7 @@ sub view : Private { $c->res->last_modified( $out->{date} ); my $contribs = $self->groom_contributors( $c, $out ); + my $irc = $self->groom_irc( $c, $out ); $c->stash( $c->model('API::Favorite')->find_plussers($distribution) ); @@ -124,6 +125,7 @@ sub view : Private { files => \@view_files, contributors => $contribs, + irc => $irc, # TODO: Put this in a more general place. # Maybe make a hash for feature flags? diff --git a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm index 99b52700b62..18f77b5eaf0 100644 --- a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm +++ b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm @@ -111,4 +111,23 @@ sub groom_contributors { return \@contribs; } +sub groom_irc { + my ( $self, $c, $release ) = @_; + + my $irc = $release->{metadata}{resources}{x_IRC}; + my $irc_info = ref $irc ? {%$irc} : { url => $irc }; + $irc_info->{web} ||= $release->{metadata}{resources}{x_WebIRC}; + + if ( !$irc_info->{web} && $irc_info->{url} ) { + if ( $irc_info->{url} =~ m{^irc://freenode\.net/#?(.*)} ) { + $irc_info->{web} = "https://webchat.freenode.net/?channels=#$1"; + } + elsif ( $irc_info->{url} =~ m{^irc://([^/]+)/#?(.*)} ) { + $irc_info->{web} = "https://chat.mibbit.com/$2\@$1"; + } + } + + return $irc_info; +} + 1; diff --git a/root/inc/release-info.html b/root/inc/release-info.html index 515a08142c2..7bbc59c0589 100644 --- a/root/inc/release-info.html +++ b/root/inc/release-info.html @@ -48,6 +48,11 @@
  • Kwalitee
  • +<% IF irc.web %> +
  • +
    Chat with Maintainers
    +
  • +<% END %> <% IF release.license %>
  • License: <% release.license.join(', ') %>
  • <% END %> @@ -69,4 +74,4 @@ <% END %> -<% END; END %> \ No newline at end of file +<% END; END %> From 23b78a7b36c1c6316a006e6b9043efd40ca1d169 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 26 Aug 2014 15:31:03 -0400 Subject: [PATCH 2/2] handle more forms of IRC links, and stop handling x_WebIRC --- lib/MetaCPAN/Web/Role/ReleaseInfo.pm | 39 +++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm index 18f77b5eaf0..20655af7e91 100644 --- a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm +++ b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm @@ -1,6 +1,9 @@ package MetaCPAN::Web::Role::ReleaseInfo; use Moose::Role; +use URI; +use URI::Escape qw(uri_escape uri_unescape); +use URI::QueryParam; # TODO: are there other controllers that do (or should) include this? @@ -116,14 +119,38 @@ sub groom_irc { my $irc = $release->{metadata}{resources}{x_IRC}; my $irc_info = ref $irc ? {%$irc} : { url => $irc }; - $irc_info->{web} ||= $release->{metadata}{resources}{x_WebIRC}; if ( !$irc_info->{web} && $irc_info->{url} ) { - if ( $irc_info->{url} =~ m{^irc://freenode\.net/#?(.*)} ) { - $irc_info->{web} = "https://webchat.freenode.net/?channels=#$1"; - } - elsif ( $irc_info->{url} =~ m{^irc://([^/]+)/#?(.*)} ) { - $irc_info->{web} = "https://chat.mibbit.com/$2\@$1"; + my $url = URI->new( $irc_info->{url} ); + my $scheme = $url->scheme; + if ( $scheme && ( $scheme eq 'irc' || $scheme eq 'ircs' ) ) { + my $ssl = $scheme eq 'ircs'; + my $host = $url->authority; + $host =~ s/:(\d+)$//; + my $port = $1; + $host =~ s/^(.*)@//; + my $user = $1; + my $path = uri_unescape( $url->path ); + $path =~ s{^/}{}; + my $channel + = $path || $url->fragment || $url->query_param('channel'); + $channel =~ s/^(?![#~!+])/#/; + $channel = uri_escape($channel); + + if ( $host eq 'freenode.net' ) { + $irc_info->{web} + = "https://webchat.freenode.net/?randomnick=1&prompt=1&channels=${channel}"; + } + else { + my $server = $host + . ( + $ssl ? q{:+} . ( $port || 6697 ) + : $port ? ":$port" + : q{} + ); + $irc_info->{web} + = "https://chat.mibbit.com/?channel=${channel}&server=${server}"; + } } }