|
1 | 1 | package MetaCPAN::Web::Role::ReleaseInfo;
|
2 | 2 |
|
3 | 3 | use Moose::Role;
|
| 4 | +use URI; |
| 5 | +use URI::Escape qw(uri_escape uri_unescape); |
| 6 | +use URI::QueryParam; |
4 | 7 |
|
5 | 8 | # TODO: are there other controllers that do (or should) include this?
|
6 | 9 |
|
@@ -116,14 +119,38 @@ sub groom_irc {
|
116 | 119 |
|
117 | 120 | my $irc = $release->{metadata}{resources}{x_IRC};
|
118 | 121 | my $irc_info = ref $irc ? {%$irc} : { url => $irc };
|
119 |
| - $irc_info->{web} ||= $release->{metadata}{resources}{x_WebIRC}; |
120 | 122 |
|
121 | 123 | 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 | + } |
127 | 154 | }
|
128 | 155 | }
|
129 | 156 |
|
|
0 commit comments