Permalink
Browse files

remove CGI::Header::Extended#merge and #replace

  • Loading branch information...
Ryo Anazawa
Ryo Anazawa committed Jul 31, 2013
1 parent 98aab5f commit 1a5fcb4f48b0048c10c790603b5f9a6685e9a9e3
Showing with 22 additions and 44 deletions.
  1. +15 −22 examples/lib/CGI/Header/Extended.pm
  2. +7 −22 examples/t/cgi_header_extended.t
@@ -2,6 +2,21 @@ package CGI::Header::Extended;
use strict;
use warnings;
use parent 'CGI::Header';
+use Carp qw/croak/;
+
+sub set {
+ my ( $self, @args ) = @_;
+ my $header = $self->header;
+
+ croak "Odd number of elements passed to 'set'" if @args % 2;
+
+ my @values;
+ while ( my ($key, $value) = splice @args, 0, 2 ) {
+ push @values, $self->SUPER::set( $key => $value );
+ }
+
+ @values;
+}
sub get {
my ( $self, @keys ) = @_;
@@ -15,26 +30,4 @@ sub delete {
wantarray ? @values : $values[-1];
}
-sub merge {
- my ( $self, @args ) = @_;
-
- if ( @args == 1 ) {
- my $header = $self->header;
- my $other = ref( $self )->new( header => { %{$args[0]} } );
- %$header = ( %$header, %{ $other->header } );
- }
- else {
- while ( my ($key, $value) = splice @args, 0, 2 ) {
- $self->set( $key => $value ); # overwrite
- }
- }
-
- $self;
-}
-
-sub replace {
- my $self = shift;
- $self->clear->merge(@_);
-}
-
1;
@@ -1,32 +1,11 @@
use strict;
use warnings;
-use Test::More tests => 5;
+use Test::More tests => 4;
BEGIN {
use_ok 'CGI::Header::Extended';
}
-subtest '#merge' => sub {
- my $header = CGI::Header::Extended->new(
- header => {
- foo => 'bar',
- },
- );
- is $header->merge( bar => 'baz' ), $header;
- is_deeply $header->header, { foo => 'bar', bar => 'baz' };
-};
-
-subtest '#replace' => sub {
- my $header = CGI::Header::Extended->new(
- header => {
- foo => 'bar',
- bar => 'baz',
- },
- );
- is $header->replace( baz => 'qux' ), $header;
- is_deeply $header->header, { baz => 'qux' };
-};
-
subtest '#get' => sub {
my $header = CGI::Header::Extended->new(
header => {
@@ -37,6 +16,12 @@ subtest '#get' => sub {
is_deeply [ $header->get(qw/foo bar/) ], [qw/bar baz/];
};
+subtest '#set' => sub {
+ my $header = CGI::Header::Extended->new;
+ is_deeply [ $header->set(foo => 'bar', bar => 'baz') ], [qw/bar baz/];
+ is_deeply $header->header, { foo => 'bar', bar => 'baz' };
+};
+
subtest '#delete' => sub {
my $header = CGI::Header::Extended->new(
header => {

0 comments on commit 1a5fcb4

Please sign in to comment.