Skip to content

Instantly share code, notes, and snippets.

@jyotty
Created October 31, 2008 06:07
Show Gist options
  • Save jyotty/21237 to your computer and use it in GitHub Desktop.
Save jyotty/21237 to your computer and use it in GitHub Desktop.
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