diff -Nru libhash-multivalue-perl-0.09/Changes libhash-multivalue-perl-0.10/Changes --- libhash-multivalue-perl-0.09/Changes 2011-06-15 22:22:24.000000000 +0000 +++ libhash-multivalue-perl-0.10/Changes 2011-09-18 19:52:01.000000000 +0000 @@ -1,5 +1,8 @@ Revision history for Perl extension Hash::MultiValue +0.10 Sun Sep 18 12:51:49 PDT 2011 + - Implemented set (aristotle) + 0.09 Wed Jun 15 15:22:12 PDT 2011 - Implemented thread safety (chansen) diff -Nru libhash-multivalue-perl-0.09/debian/changelog libhash-multivalue-perl-0.10/debian/changelog --- libhash-multivalue-perl-0.09/debian/changelog 2011-06-18 21:33:30.000000000 +0000 +++ libhash-multivalue-perl-0.10/debian/changelog 2011-11-09 21:35:45.000000000 +0000 @@ -1,3 +1,19 @@ +libhash-multivalue-perl (0.10-1) unstable; urgency=low + + [ Ansgar Burchardt ] + * debian/control: Convert Vcs-* fields to Git. + + [ Salvatore Bonaccorso ] + * debian/copyright: Replace DEP5 Format-Specification URL from + svn.debian.org to anonscm.debian.org URL. + + [ Fabrizio Regalli ] + * Imported Upstream version 0.10 + * Update d/copyright according to latest DEP5 revision + * Fixed comma-separated-files-in-dep5-copyright lintian message + + -- Fabrizio Regalli Mon, 19 Sep 2011 17:14:51 +0200 + libhash-multivalue-perl (0.09-1) unstable; urgency=low [ Fabrizio Regalli ] diff -Nru libhash-multivalue-perl-0.09/debian/control libhash-multivalue-perl-0.10/debian/control --- libhash-multivalue-perl-0.09/debian/control 2011-06-18 21:28:23.000000000 +0000 +++ libhash-multivalue-perl-0.10/debian/control 2011-11-09 21:35:45.000000000 +0000 @@ -8,8 +8,8 @@ Fabrizio Regalli Standards-Version: 3.9.2 Homepage: http://search.cpan.org/dist/Hash-MultiValue/ -Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libhash-multivalue-perl/ -Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libhash-multivalue-perl/ +Vcs-Git: git://git.debian.org/pkg-perl/packages/libhash-multivalue-perl.git +Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-perl/packages/libhash-multivalue-perl.git Package: libhash-multivalue-perl Architecture: all diff -Nru libhash-multivalue-perl-0.09/debian/copyright libhash-multivalue-perl-0.10/debian/copyright --- libhash-multivalue-perl-0.09/debian/copyright 2011-06-18 21:33:13.000000000 +0000 +++ libhash-multivalue-perl-0.10/debian/copyright 2011-11-09 21:35:45.000000000 +0000 @@ -1,7 +1,7 @@ -Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 -Maintainer: Tatsuhiko Miyagawa +Format: http://anonscm.debian.org/viewvc/dep/web/deps/dep5.mdwn?view=markup&pathrev=174 +Upstream-Contact: Tatsuhiko Miyagawa Source: http://search.cpan.org/dist/Hash-MultiValue/ -Name: Hash-MultiValue +Upstream-Name: Hash-MultiValue Files: * Copyright: 2009-2010, Tatsuhiko Miyagawa @@ -27,7 +27,7 @@ Copyright: 2001-2008, Michael G Schwern License: Artistic or GPL-1+ -Files: inc/Test/Builder.pm, inc/Test/Builder/* +Files: inc/Test/Builder.pm inc/Test/Builder/* Copyright: 2002-2008, chromatic 2002-2008, Michael G Schwern License: Artistic or GPL-1+ diff -Nru libhash-multivalue-perl-0.09/lib/Hash/MultiValue.pm libhash-multivalue-perl-0.10/lib/Hash/MultiValue.pm --- libhash-multivalue-perl-0.09/lib/Hash/MultiValue.pm 2011-06-15 22:23:24.000000000 +0000 +++ libhash-multivalue-perl-0.10/lib/Hash/MultiValue.pm 2011-09-18 19:53:05.000000000 +0000 @@ -2,7 +2,7 @@ use strict; use 5.008_001; -our $VERSION = '0.09'; +our $VERSION = '0.10'; use Carp (); use Scalar::Util qw(refaddr); @@ -88,6 +88,43 @@ Carp::croak "Multiple values match: $key"; } +sub set { + my $self = shift; + my $key = shift; + + my $this = refaddr $self; + my $k = $keys{$this}; + my $v = $values{$this}; + + my @idx = grep { $key eq $k->[$_] } 0 .. $#$k; + + my $added = @_ - @idx; + if ($added > 0) { + my $start = $#$k + 1; + push @$k, ($key) x $added; + push @idx, $start .. $#$k; + } + elsif ($added < 0) { + my ($start, @drop, @keep) = splice @idx, $added; + for ($start+1 .. $#$k) { + shift @drop, next if $_ == $drop[0]; + push @keep, $_; + } + splice @$k, $start, 0+@$k, @$k[@keep]; + splice @$v, $start, 0+@$v, @$v[@keep]; + } + + if (@_) { + @$v[@idx] = @_; + $self->{$key} = $_[-1]; + } + else { + delete $self->{$key}; + } + + $self; +} + sub add { my $self = shift; my $key = shift; @@ -127,14 +164,7 @@ sub remove { my ($self, $key) = @_; - delete $self->{$key}; - - my $this = refaddr $self; - my $k = $keys{$this}; - my $v = $values{$this}; - my @keep = grep { $key ne $k->[$_] } 0 .. $#$k; - @$k = @$k[@keep]; - @$v = @$v[@keep]; + $self->set($key); $self; } @@ -252,7 +282,7 @@ Hash::MultiValue is an object (and a plain hash reference) that may contain multiple values per key, inspired by MultiDict of WebOb. -=head1 WHY THIS MODULE +=head1 RATIONALE In a typical web application, the request parameters (a.k.a CGI parameters) can be single value or multi values. Using CGI.pm style @@ -362,6 +392,15 @@ Returns a list of all values, in the same order as C<< $hash->keys >>. +=item set + + $hash->set($key [, $value ... ]); + +Changes the stored value(s) of the given C<$key>. This removes or adds +pairs as necessary to store the new list but otherwise preserves order +of existing pairs. C<< $hash->{$key} >> is updated to point to the last +value. + =item add $hash->add($key, $value [, $value ... ]); @@ -410,9 +449,9 @@ # 2: c = 3 # 3: a = 4 -Be careful not to change C<@_> inside your coderef! It will update the -tracking object but not the plain hash. In the future, this limitation may be -removed. +Be careful B to change C<@_> inside your coderef! It will update +the tracking object but not the plain hash. In the future, this +limitation I be removed. =item clone @@ -445,8 +484,8 @@ =item as_hashref_multi, multi - $multi = $hash->as_hashref_multi - $multi = $hash->multi + $multi = $hash->as_hashref_multi; + $multi = $hash->multi; Creates a new plain (unblessed) hash reference where values are all array references, regardless of there are single or multiple values @@ -507,6 +546,12 @@ and then all C calls to Hash::MultiValue objects will return I. +=head1 THREAD SAFETY + +Prior to version 0.09, this module wasn't safe in a threaded +environment, including win32 fork() emulation. Versions newer than +0.09 is considered thread safe. + =head1 AUTHOR Tatsuhiko Miyagawa Emiyagawa@bulknews.netE diff -Nru libhash-multivalue-perl-0.09/MANIFEST libhash-multivalue-perl-0.10/MANIFEST --- libhash-multivalue-perl-0.09/MANIFEST 2011-06-15 22:22:52.000000000 +0000 +++ libhash-multivalue-perl-0.10/MANIFEST 2011-09-18 19:53:02.000000000 +0000 @@ -29,6 +29,7 @@ t/hash.t t/multi.t t/ref.t +t/set.t t/threads.t t/write.t tools/benchmark.pl diff -Nru libhash-multivalue-perl-0.09/META.yml libhash-multivalue-perl-0.10/META.yml --- libhash-multivalue-perl-0.09/META.yml 2011-06-15 22:23:37.000000000 +0000 +++ libhash-multivalue-perl-0.10/META.yml 2011-09-18 19:53:15.000000000 +0000 @@ -24,4 +24,4 @@ resources: license: http://dev.perl.org/licenses/ repository: git://github.com/miyagawa/Hash-MultiValue.git -version: 0.09 +version: 0.10 diff -Nru libhash-multivalue-perl-0.09/README libhash-multivalue-perl-0.10/README --- libhash-multivalue-perl-0.09/README 2011-06-15 22:23:36.000000000 +0000 +++ libhash-multivalue-perl-0.10/README 2011-09-18 19:53:15.000000000 +0000 @@ -22,7 +22,7 @@ Hash::MultiValue is an object (and a plain hash reference) that may contain multiple values per key, inspired by MultiDict of WebOb. -WHY THIS MODULE +RATIONALE In a typical web application, the request parameters (a.k.a CGI parameters) can be single value or multi values. Using CGI.pm style "param" is one way to deal with this problem (and it is good, as long as @@ -119,6 +119,14 @@ Returns a list of all values, in the same order as "$hash->keys". + set + $hash->set($key [, $value ... ]); + + Changes the stored value(s) of the given $key. This removes or adds + pairs as necessary to store the new list but otherwise preserves + order of existing pairs. "$hash->{$key}" is updated to point to the + last value. + add $hash->add($key, $value [, $value ... ]); @@ -164,7 +172,7 @@ Be careful not to change @_ inside your coderef! It will update the tracking object but not the plain hash. In the future, this - limitation may be removed. + limitation *may* be removed. clone $new = $hash->clone; @@ -193,8 +201,8 @@ does exactly the opposite of "from_mixed". as_hashref_multi, multi - $multi = $hash->as_hashref_multi - $multi = $hash->multi + $multi = $hash->as_hashref_multi; + $multi = $hash->multi; Creates a new plain (unblessed) hash reference where values are all array references, regardless of there are single or multiple values @@ -251,6 +259,11 @@ and then all "ref" calls to Hash::MultiValue objects will return *HASH*. +THREAD SAFETY + Prior to version 0.09, this module wasn't safe in a threaded + environment, including win32 fork() emulation. Versions newer than 0.09 + is considered thread safe. + AUTHOR Tatsuhiko Miyagawa diff -Nru libhash-multivalue-perl-0.09/t/set.t libhash-multivalue-perl-0.10/t/set.t --- libhash-multivalue-perl-0.09/t/set.t 1970-01-01 00:00:00.000000000 +0000 +++ libhash-multivalue-perl-0.10/t/set.t 2011-09-18 19:51:40.000000000 +0000 @@ -0,0 +1,28 @@ +use strict; +use Test::More; +use Hash::MultiValue; + +my @l = qw( foo a bar baz foo b bar quux ); + +my $hash = Hash::MultiValue->new( @l ); + +$hash->set(foo => 1 .. 3); +is_deeply [ $hash->flatten ], [ qw( foo 1 bar baz foo 2 bar quux foo 3 ) ], 'more items than before'; +is $hash->{'foo'}, 3; + +$hash->add(bar => 'qux'); +$hash->set(bar => 'a' .. 'c'); +is_deeply [ $hash->flatten ], [ qw( foo 1 bar a foo 2 bar b foo 3 bar c ) ], 'exactly as many items as before'; +is $hash->{'bar'}, 'c'; + +$hash->set(foo => qw(x y)); +is_deeply [ $hash->flatten ], [ qw( foo x bar a foo y bar b bar c ) ], 'fewer items than before'; +is $hash->{'foo'}, 'y'; + +$hash->set('bar'); +is_deeply [ $hash->flatten ], [ qw( foo x foo y ) ], 'no items'; +is $hash->{'bar'}, undef; + +isa_ok $hash, 'Hash::MultiValue'; + +done_testing;