Skip to content

Commit 23b78a7

Browse files
committed
handle more forms of IRC links, and stop handling x_WebIRC
1 parent e790392 commit 23b78a7

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

lib/MetaCPAN/Web/Role/ReleaseInfo.pm

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package MetaCPAN::Web::Role::ReleaseInfo;
22

33
use Moose::Role;
4+
use URI;
5+
use URI::Escape qw(uri_escape uri_unescape);
6+
use URI::QueryParam;
47

58
# TODO: are there other controllers that do (or should) include this?
69

@@ -116,14 +119,38 @@ sub groom_irc {
116119

117120
my $irc = $release->{metadata}{resources}{x_IRC};
118121
my $irc_info = ref $irc ? {%$irc} : { url => $irc };
119-
$irc_info->{web} ||= $release->{metadata}{resources}{x_WebIRC};
120122

121123
if ( !$irc_info->{web} && $irc_info->{url} ) {
122-
if ( $irc_info->{url} =~ m{^irc://freenode\.net/#?(.*)} ) {
123-
$irc_info->{web} = "https://webchat.freenode.net/?channels=#$1";
124-
}
125-
elsif ( $irc_info->{url} =~ m{^irc://([^/]+)/#?(.*)} ) {
126-
$irc_info->{web} = "https://chat.mibbit.com/$2\@$1";
124+
my $url = URI->new( $irc_info->{url} );
125+
my $scheme = $url->scheme;
126+
if ( $scheme && ( $scheme eq 'irc' || $scheme eq 'ircs' ) ) {
127+
my $ssl = $scheme eq 'ircs';
128+
my $host = $url->authority;
129+
$host =~ s/:(\d+)$//;
130+
my $port = $1;
131+
$host =~ s/^(.*)@//;
132+
my $user = $1;
133+
my $path = uri_unescape( $url->path );
134+
$path =~ s{^/}{};
135+
my $channel
136+
= $path || $url->fragment || $url->query_param('channel');
137+
$channel =~ s/^(?![#~!+])/#/;
138+
$channel = uri_escape($channel);
139+
140+
if ( $host eq 'freenode.net' ) {
141+
$irc_info->{web}
142+
= "https://webchat.freenode.net/?randomnick=1&prompt=1&channels=${channel}";
143+
}
144+
else {
145+
my $server = $host
146+
. (
147+
$ssl ? q{:+} . ( $port || 6697 )
148+
: $port ? ":$port"
149+
: q{}
150+
);
151+
$irc_info->{web}
152+
= "https://chat.mibbit.com/?channel=${channel}&server=${server}";
153+
}
127154
}
128155
}
129156

0 commit comments

Comments
 (0)