Skip to content
Browse files

merge CGI::Header::Extended

  • Loading branch information...
1 parent eee9211 commit 011657f8c6674fc0611be6082038402e7ddc998b Ryo Anazawa committed Aug 1, 2013
Showing with 18 additions and 9 deletions.
  1. +18 −9 lib/CGI/Header.pm
View
27 lib/CGI/Header.pm
@@ -63,15 +63,24 @@ sub _rehash {
}
sub get {
- my ( $self, $key ) = @_;
- my $prop = $self->_normalize( $key );
- $self->header->{$prop};
+ my ( $self, @keys ) = @_;
+ my @props = map { $self->_normalize($_) } @keys;
+ @{ $self->header }{ @props };
}
sub set {
- my ( $self, $key, $value ) = @_;
- my $prop = $self->_normalize( $key );
- $self->header->{$prop} = $value;
+ my ( $self, @pairs ) = @_;
+ my $header = $self->header;
+
+ croak "Odd number of elements passed to 'set'" if @pairs % 2;
+
+ my @values;
+ while ( my ($key, $value) = splice @pairs, 0, 2 ) {
+ my $prop = $self->_normalize( $key );
+ push @values, $header->{$prop} = $value;
+ }
+
+ @values == 1 ? $values[0] : @values;
}
sub exists {
@@ -81,9 +90,9 @@ sub exists {
}
sub delete {
- my ( $self, $key ) = @_;
- my $prop = $self->_normalize( $key );
- delete $self->header->{$prop};
+ my ( $self, @keys ) = @_;
+ my @props = map { $self->_normalize($_) } @keys;
+ delete @{ $self->header }{ @props };
}
sub clear {

0 comments on commit 011657f

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