Permalink
Browse files

"handler" is writable

  • Loading branch information...
1 parent 57c692b commit 6c46d3bed091b80f73b0d9da9171670f75c0fd92 Ryo Anazawa committed Jun 7, 2013
Showing with 27 additions and 15 deletions.
  1. +2 −1 Changes
  2. +25 −14 lib/CGI/Header.pm
View
@@ -1,6 +1,7 @@
Revision history for Perl extension CGI::Header.
- - Remove CGI::Header#location and redirect
+ - Remove CGI::Header#redirect
+ - Add CGI::Header#handler
0.58 (1.00-RC11) Jun 5th, 2013
View
@@ -7,19 +7,8 @@ use Carp qw/croak/;
our $VERSION = '0.58';
sub new {
- my $class = shift;
- my %args = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
- my $self = bless { %args }, $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 {
@@ -37,7 +26,11 @@ sub _build_query {
}
sub handler {
- $_[0]->{handler} ||= 'header';
+ my $self = shift;
+ return $self->{handler} ||= 'header' unless @_;
+ $self->{handler} = shift;
+ $self->_clear_alias;
+ $self->_rehash;
}
sub _alias {
@@ -63,6 +56,10 @@ sub _build_alias {
\%alias;
}
+sub _clear_alias {
+ delete $_[0]->{_alias};
+}
+
sub _normalize {
my ( $self, $key ) = @_;
my $alias = $self->_alias;
@@ -73,6 +70,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 );

0 comments on commit 6c46d3b

Please sign in to comment.