summaryrefslogtreecommitdiffstats
path: root/lib/Narwhal/Component/Redirect.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-01-26 14:56:23 -0600
committerJesse Luehrs <doy@tozt.net>2011-01-26 14:56:23 -0600
commit0d2b29fd9d932f909f46209d17963752379ea545 (patch)
treee27792b5aa077339b22d8d6c6bd9597d296f519a /lib/Narwhal/Component/Redirect.pm
parentaf5867fd48b84c7ea1cba67574294334bb2cc19e (diff)
downloadnarwhal-0d2b29fd9d932f909f46209d17963752379ea545.tar.gz
narwhal-0d2b29fd9d932f909f46209d17963752379ea545.zip
initial sketch
Diffstat (limited to 'lib/Narwhal/Component/Redirect.pm')
-rw-r--r--lib/Narwhal/Component/Redirect.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Narwhal/Component/Redirect.pm b/lib/Narwhal/Component/Redirect.pm
new file mode 100644
index 0000000..58a8478
--- /dev/null
+++ b/lib/Narwhal/Component/Redirect.pm
@@ -0,0 +1,31 @@
+package Narwhal::Component::Redirect;
+use Moose;
+
+sub permanent {
+ my $self = shift;
+ my ($req) = @_;
+ my $res = $req->new_response(301);
+ $res->location($self->_get_location($req));
+ return $res;
+}
+
+sub temporary {
+ my $self = shift;
+ my ($req) = @_;
+ my $res = $req->new_response(302);
+ $res->location($self->_get_location($req));
+ return $res;
+}
+
+sub _get_location {
+ my $self = shift;
+ my ($req) = @_;
+ my $to = $req->env->{'plack.router.match'}->route->defaults->{to};
+ die "must supply a location to redirect to" unless $to;
+ return $to;
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;