Skip to content
Browse files

add CGI::Application::Header to examples/

  • Loading branch information...
1 parent 8ac7377 commit 0b052ec16397502bd06011f4951fd2ecb3bf72e5 Ryo Anazawa committed Jun 16, 2013
Showing with 61 additions and 0 deletions.
  1. +48 −0 examples/lib/CGI/Application/Header.pm
  2. +13 −0 examples/t/cgi_application_header.t
View
48 examples/lib/CGI/Application/Header.pm
@@ -0,0 +1,48 @@
+package CGI::Application::Header;
+use strict;
+use warnings;
+use parent 'CGI::Header';
+
+sub handler {
+ my $self = shift;
+ return $self->{handler} ||= 'header' unless @_;
+ $self->{handler} = shift;
+ $self->_clear_alias;
+ $self->_rehash;
+}
+
+sub _build_alias {
+ my $self = shift;
+ my $alias = $self->SUPER::_build_alias;
+
+ if ( $self->handler eq 'redirect' ) {
+ $alias->{uri} = 'location';
+ $alias->{url} = 'location';
+ }
+
+ $alias;
+}
+
+sub _clear_alias {
+ delete $_[0]->{_alias};
+}
+
+sub location {
+ my $self = shift;
+ return $self->header->{location} unless @_;
+ $self->header->{location} = shift;
+ $self;
+}
+
+sub finalize {
+ my $self = shift;
+ my $query = $self->query;
+ my $args = $self->header;
+ my $method = $self->handler;
+
+ $query->print( $query->$method($args) );
+
+ return;
+}
+
+1;
View
13 examples/t/cgi_application_header.t
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+use Test::Output;
+
+BEGIN {
+ use_ok 'CGI::Application::Header';
+}
+
+my $header = CGI::Application::Header->new;
+
+stdout_like { $header->finalize } qr{^Content-Type: };
+stdout_like { $header->handler('redirect')->finalize } qr{^Status: 302 Found};

0 comments on commit 0b052ec

Please sign in to comment.
Something went wrong with that request. Please try again.