root/Mixxi/trunk/lib/Mixxi/Controller/Root.pm

Revision 2067 (checked in by miyagawa, 14 years ago)

import Mixxi tinyurl

Line 
1 package Mixxi::Controller::Root;
2
3 use strict;
4 use warnings;
5 use base 'Catalyst::Controller';
6
7 #
8 # Sets the actions in this controller to be registered with no prefix
9 # so they function identically to actions created in MyApp.pm
10 #
11 __PACKAGE__->config->{namespace} = '';
12
13 =head1 NAME
14
15 Mixxi::Controller::Root - Root Controller for Mixxi
16
17 =head1 DESCRIPTION
18
19 [enter your description here]
20
21 =head1 METHODS
22
23 =cut
24
25 =head2 default
26
27 =cut
28
29 sub u : Global {
30     my ( $self, $c ) = @_;
31
32     eval {
33         my $id = $c->req->args->[0];
34         $id = Mixxi::Schema::Url->to_id($id) or die "No decodable ID";
35
36         my $url = $c->model('DBIC::Url')->find($id)
37             or die "No object with id=$id";
38
39         $c->res->redirect($url->url);
40     };
41
42     if ($@) {
43         $c->res->redirect($c->uri_for('/url'));
44     }
45 }
46
47 sub default : Private {
48     my($self, $c) = @_;
49
50     my $alias = $c->req->args->[0];
51     my $rs = $c->model('DBIC::Url')->search(alias => $alias);
52
53     unless ($rs->count) {
54         return $c->res->redirect($c->uri_for('/url'));
55     }
56
57     $c->res->redirect($rs->first->url);
58 }
59
60 =head2 end
61
62 Attempt to render a view, if needed.
63
64 =cut
65
66 sub end : ActionClass('RenderView') {}
67
68 =head1 AUTHOR
69
70 Tatsuhiko Miyagawa,,,
71
72 =head1 LICENSE
73
74 This library is free software, you can redistribute it and/or modify
75 it under the same terms as Perl itself.
76
77 =cut
78
79 1;
Note: See TracBrowser for help on using the browser.