1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
From: Frank Lichtenheld <djpig@debian.org>
Date: Tue, 3 Jun 2008 21:29:53 +0000
Subject: Fix header() to act according to documentation when called more than
once.
---
lib/REST/Application.pm | 4 ++--
t/01-basic.t | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/REST/Application.pm b/lib/REST/Application.pm
index 4070f5a..7298ef0 100644
--- a/lib/REST/Application.pm
+++ b/lib/REST/Application.pm
@@ -305,9 +305,9 @@ sub header {
# Arguments can be passed in as a hash-ref or as an even sized list.
if (@_) {
if (@_%2 == 0) { # even-sized list, must be hash
- %{ $self->{__header} } = @_;
+ %{ $self->{__header} } = ( %{$self->{__header}}, @_ );
} elsif (ref($_[0]) eq 'HASH') { # First item must be a hash reference
- $self->{__header} = shift;
+ %{ $self->{__header} } = ( %{$self->{__header}}, %{$_[0]} );
} else {
croak "Expected even-sized list or hash reference.";
}
diff --git a/t/01-basic.t b/t/01-basic.t
index b587dca..49a1574 100644
--- a/t/01-basic.t
+++ b/t/01-basic.t
@@ -283,8 +283,10 @@ BEGIN {
my %hash = $rest->header();
is_deeply(\%hash, {}, "Retrieving default header values.");
$rest->header(-type => 'text/html', -foobar => 5);
+ $rest->header(-baz => 10);
%hash = $rest->header();
- is_deeply(\%hash, {-type => 'text/html', -foobar => 5}, "Retrieving custom header values.");
+ is_deeply(\%hash, {-type => 'text/html', -foobar => 5, -baz => 10},
+ "Retrieving custom header values.");
}
# TEST: resetHeader()
|