Created
May 14, 2009 01:10
-
-
Save sekimura/111412 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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