Created
October 31, 2008 06:07
-
-
Save jyotty/21237 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub route { | |
my ($url) = @_; | |
my @parts = split(m{/}, $url); | |
return _error(400) unless '' eq shift @parts; # doesn't begin with / | |
@parts = grep { '' ne $_ } @parts; # clean out any '//' | |
my $sub = shift @parts; | |
$sub = 'root' if !defined($sub); | |
return _error(404) if $sub =~ m/^_/; | |
my $r = eval { | |
no strict 'refs'; | |
print $q->header(-type => 'text/plain'); | |
my $tt_vars = $sub->(@parts); | |
return $tt->process($sub, $tt_vars) or die $tt->error(); | |
}; | |
print $@ if $@; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment