Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove "handler"

  • Loading branch information...
commit e9c542c3554fffbc03777c732f3278d52680f90d 1 parent c446df9
Ryo Anazawa authored
View
3  Changes
@@ -1,7 +1,6 @@
Revision history for Perl extension CGI::Header.
- - Remove CGI::Header#redirect
- - Add CGI::Header#handler
+ - Remove CGI::Header#redirect and location
0.58 (1.00-RC11) Jun 5th, 2013
View
69 lib/CGI/Header.pm
@@ -7,18 +7,8 @@ use Carp qw/croak/;
our $VERSION = '0.58';
sub new {
- my $class = shift;
- my $self = bless { @_ }, $class;
- my $header = $self->header;
-
- for my $key ( keys %$header ) {
- my $prop = $self->_normalize( $key );
- next if $key eq $prop; # $key is normalized
- croak "Property '$prop' already exists" if exists $header->{$prop};
- $header->{$prop} = delete $header->{$key}; # rename $key to $prop
- }
-
- $self;
+ my ( $class, @args ) = @_;
+ ( bless { @args }, $class )->_rehash;
}
sub header {
@@ -35,29 +25,16 @@ sub _build_query {
CGI::self_or_default();
}
-sub handler {
- $_[0]->{handler} ||= 'header';
-}
-
sub _alias {
my $self = shift;
$self->{_alias} ||= $self->_build_alias;
}
sub _build_alias {
- my $self = shift;
-
- my %alias = (
+ +{
'content-type' => 'type',
'cookie' => 'cookies',
- );
-
- if ( $self->handler eq 'redirect' ) {
- $alias{uri} = 'location';
- $alias{url} = 'location';
- }
-
- \%alias;
+ };
}
sub _normalize {
@@ -70,6 +47,20 @@ sub _normalize {
$prop;
}
+sub _rehash {
+ my $self = shift;
+ my $header = $self->header;
+
+ for my $key ( keys %$header ) {
+ my $prop = $self->_normalize( $key );
+ next if $key eq $prop; # $key is normalized
+ croak "Property '$prop' already exists" if exists $header->{$prop};
+ $header->{$prop} = delete $header->{$key}; # rename $key to $prop
+ }
+
+ $self;
+}
+
sub get {
my ( $self, $key ) = @_;
my $prop = $self->_normalize( $key );
@@ -106,7 +97,6 @@ BEGIN {
charset
cookies
expires
- location
nph
p3p
status
@@ -126,12 +116,11 @@ BEGIN {
}
sub finalize {
- my $self = shift;
- my $query = $self->query;
- my $args = $self->header;
- my $method = $self->handler;
+ my $self = shift;
+ my $query = $self->query;
+ my $args = $self->header;
- $query->print( $query->$method($args) );
+ $query->print( $query->header($args) );
return;
}
@@ -406,14 +395,6 @@ expiration interval. The following forms are all valid for this field:
# at the indicated time & date
$header->expires( 'Thu, 25 Apr 1999 00:40:33 GMT' );
-=item $self = $header->location( $url )
-
-=item $url = $header->location
-
-Get or set the Location header.
-
- $header->location('http://somewhere.else/in/movie/land');
-
=item $self = $header->nph( $bool )
=item $bool = $header->nph
@@ -486,10 +467,8 @@ Normalized property names are:
CGI.pm's C<header> method also accepts aliases of property names.
This module converts them as follows:
- 'content-type' -> 'type'
- 'cookie' -> 'cookies'
- 'set-cookie' -> 'cookies'
- 'window-target' -> 'target'
+ 'content-type' -> 'type'
+ 'cookie' -> 'cookies'
If a property name is duplicated, throws an exception:
View
12 lib/CGI/Header/Adapter.pm
@@ -60,16 +60,8 @@ sub process_newline {
}
sub as_arrayref {
- my $self = shift;
- my $query = $self->query;
-
- if ( $self->handler eq 'redirect' ) {
- $self = $self->clone;
- $self->location( $query->self_url ) if !$self->location;
- $self->status( '302 Found' ) if !defined $self->status;
- $self->type( q{} ) if !$self->_has_type;
- }
-
+ my $self = shift;
+ my $query = $self->query;
my %header = %{ $self->header };
my ( $attachment, $charset, $cookies, $expires, $nph, $p3p, $status, $target, $type )
View
7 t/10_basic.t
@@ -26,7 +26,6 @@ subtest 'CGI::Header#new' => sub {
isa_ok $header, 'CGI::Header';
isa_ok $header->header, 'HASH';
isa_ok $header->query, 'CGI';
- is $header->handler, 'header';
throws_ok {
CGI::Header->new(
@@ -61,8 +60,8 @@ subtest 'header props.' => sub {
is $header->expires('+3d'), $header;
is $header->expires, '+3d';
- is $header->location('http://somewhere.else/in/movie/land'), $header;
- is $header->location, 'http://somewhere.else/in/movie/land';
+ #is $header->location('http://somewhere.else/in/movie/land'), $header;
+ #is $header->location, 'http://somewhere.else/in/movie/land';
is $header->nph(1), $header;
ok $header->nph;
@@ -84,7 +83,7 @@ subtest 'header props.' => sub {
charset => 'utf-8',
cookies => 'ID=123456; path=/',
expires => '+3d',
- location => 'http://somewhere.else/in/movie/land',
+ #location => 'http://somewhere.else/in/movie/land',
nph => '1',
p3p => 'CAO DSP LAW CURa',
status => '304 Not Modified',
Please sign in to comment.
Something went wrong with that request. Please try again.