Skip to content

Instantly share code, notes, and snippets.

@nichtich
Created June 16, 2011 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nichtich/1029557 to your computer and use it in GitHub Desktop.
Save nichtich/1029557 to your computer and use it in GitHub Desktop.
Quick draft of Plack::App::LocalRedirect
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