|
Revision 972, 0.9 kB
(checked in by tokuhirom, 6 years ago)
|
|
lang/perl/mobirc: implemented keyword support, likes limechat ;-) idea from id:miyagawa++
|
| Line | |
|---|
| 1 | package Mobirc::HTTPD::Router; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use Carp; |
|---|
| 5 | use HTTP::Response; |
|---|
| 6 | use URI::Escape; |
|---|
| 7 | use Mobirc::Util; |
|---|
| 8 | |
|---|
| 9 | sub route { |
|---|
| 10 | my ($class, $c, $uri) = @_; |
|---|
| 11 | croak 'uri missing' unless $uri; |
|---|
| 12 | |
|---|
| 13 | if ( $uri eq '/' ) { |
|---|
| 14 | return 'index'; |
|---|
| 15 | } |
|---|
| 16 | elsif ( $uri eq '/topics' ) { |
|---|
| 17 | return 'topics'; |
|---|
| 18 | } |
|---|
| 19 | elsif ( $uri =~ m{^/recent(?:\?t=\d+)?$} ) { |
|---|
| 20 | return 'recent'; |
|---|
| 21 | } |
|---|
| 22 | elsif ( $uri =~ m{^/keyword(-recent)?$} ) { |
|---|
| 23 | return 'keyword', $1 ? true : false; |
|---|
| 24 | } |
|---|
| 25 | elsif ($uri =~ m{^/channels(-recent)?/([^?]+)(?:\?time=\d+)?$}) { |
|---|
| 26 | my $recent_mode = $1 ? true : false; |
|---|
| 27 | my $channel_name = $2; |
|---|
| 28 | return 'show_channel', $recent_mode, uri_unescape($channel_name); |
|---|
| 29 | } else { |
|---|
| 30 | warn "dan the 404 not found: $uri"; |
|---|
| 31 | my $response = HTTP::Response->new(404); |
|---|
| 32 | $response->content("Dan the 404 not found: $uri"); |
|---|
| 33 | return $response; |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | 1; |
|---|