root/lang/perl/mobirc/trunk/mobirc/lib/Mobirc/HTTPD/Router.pm @ 972

Revision 972, 0.9 kB (checked in by tokuhirom, 7 years ago)

lang/perl/mobirc: implemented keyword support, likes limechat ;-) idea from id:miyagawa++

Line 
1package Mobirc::HTTPD::Router;
2use strict;
3use warnings;
4use Carp;
5use HTTP::Response;
6use URI::Escape;
7use Mobirc::Util;
8
9sub 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
371;
Note: See TracBrowser for help on using the browser.