Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modify return value of #set

  • Loading branch information...
commit ae618c752ef1ce05ecf21286a0ed7cf4da008fcb 1 parent 011657f
Ryo Anazawa authored
Showing with 20 additions and 4 deletions.
  1. +4 −2 lib/CGI/Header.pm
  2. +16 −2 t/10_basic.t
View
6 lib/CGI/Header.pm
@@ -72,7 +72,7 @@ sub set {
my ( $self, @pairs ) = @_;
my $header = $self->header;
- croak "Odd number of elements passed to 'set'" if @pairs % 2;
+ croak 'Odd number of arguments passed to set()' if @pairs % 2;
my @values;
while ( my ($key, $value) = splice @pairs, 0, 2 ) {
@@ -80,7 +80,7 @@ sub set {
push @values, $header->{$prop} = $value;
}
- @values == 1 ? $values[0] : @values;
+ wantarray ? @values : $values[0];
}
sub exists {
@@ -101,6 +101,8 @@ sub clear {
$self;
}
+# See also Moose::Meta::Method::Accessor::Native::Hash
+
BEGIN {
for my $method (qw/
attachment
View
18 t/10_basic.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
use CGI::Header;
-use Test::More tests => 8;
+use Test::More tests => 9;
use Test::Exception;
use Test::Output;
@@ -38,13 +38,27 @@ subtest 'CGI::Header#new' => sub {
};
subtest 'header fields' => sub {
- my $header = CGI::Header->new;
+ my $header = CGI::Header->new( header => { foo => 'bar' } );
is $header->set( 'Foo' => 'bar' ), 'bar';
is $header->get('Foo'), 'bar';
ok $header->exists('Foo');
is $header->delete('Foo'), 'bar';
};
+subtest '#set' => sub {
+ my $header = CGI::Header->new;
+
+ throws_ok { $header->set('Foo') } qr{^Odd number of arguments passed};
+
+ my @got = $header->set(
+ Foo => 'bar',
+ Bar => 'baz',
+ );
+
+ is_deeply \@got, [qw/bar baz/];
+ is_deeply $header->header, { foo => 'bar', bar => 'baz' };
+};
+
subtest 'header props.' => sub {
my $header = CGI::Header->new;
Please sign in to comment.
Something went wrong with that request. Please try again.