Skip to content

Instantly share code, notes, and snippets.

@sekimura
Created May 14, 2009 01:10
Show Gist options
  • Save sekimura/111412 to your computer and use it in GitHub Desktop.
Save sekimura/111412 to your computer and use it in GitHub Desktop.
use Lyst;
use ShortenURL;
method hello :Path('/') {
my $body =
<<' EOF';
<form method="POST">
<input name="longurl">
<input type="submit">
</form>
EOF
if ($self->request->method eq 'POST') {
my $params = $self->request->params;
my $url = ShortenURL->new(orig => $params->{longurl});
$url->save;
$body .= sprintf <<' EOF'
shotened url: <a href="%s">%s</a><br />
orig url: %s
EOF
, $url->key, $url->key, $url->orig;
}
return $body;
}
method redirect :Path('/(\w+)', (Str $key) {
my $url = ShortenURL->search( key => $key);
my $res = HTTP::Engine::Response->new(status => 302);
$res->headers->header(Location => $url->orig);
$res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment