Created
June 16, 2011 15:53
-
-
Save nichtich/1029557 to your computer and use it in GitHub Desktop.
Quick draft of Plack::App::LocalRedirect
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
use strict; | |
use warnings; | |
package Plack::App::LocalRedirect; | |
use parent 'Plack::Component'; | |
use Plack::Request; | |
use URI::Escape; | |
# use Plack::Util::Accessor qw(path); | |
sub call { | |
my ($self, $env) = @_; | |
my $req = Plack::Request->new( $env ); | |
my $path = $self->path($env) || '/'; | |
$path =~ s!^/!!; | |
my $location = $req->base . uri_escape( $path ); | |
[ 302, [ Location => $location ], | |
[ "<html><body><a href=\"$location\">$location</a></body></html>"] ]; | |
} | |
sub path { # override this in you subclass or use accessor ? | |
my ($self, $env) = @_; | |
return '/'; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment