Hello community,
here is the log from the commit of package perl-Hash-MoreUtils for
openSUSE:Factory checked in at 2013-10-11 09:00:34
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Hash-MoreUtils (Old)
and /work/SRC/openSUSE:Factory/.perl-Hash-MoreUtils.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Hash-MoreUtils"
Changes:
--------
--- /work/SRC/openSUSE:Factory/perl-Hash-MoreUtils/perl-Hash-MoreUtils.changes
2013-10-06 19:36:36.000000000 +0200
+++
/work/SRC/openSUSE:Factory/.perl-Hash-MoreUtils.new/perl-Hash-MoreUtils.changes
2013-10-11 09:00:34.000000000 +0200
@@ -1,0 +2,7 @@
+Tue Oct 8 06:15:48 UTC 2013 - [email protected]
+
+- updated to 0.04
+ - add slice_map family
+ - Changes reformatted as per CPAN::Changes::Spec
+
+-------------------------------------------------------------------
Old:
----
Hash-MoreUtils-0.03.tar.gz
New:
----
Hash-MoreUtils-0.04.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-Hash-MoreUtils.spec ++++++
--- /var/tmp/diff_new_pack.svN11P/_old 2013-10-11 09:00:36.000000000 +0200
+++ /var/tmp/diff_new_pack.svN11P/_new 2013-10-11 09:00:36.000000000 +0200
@@ -17,7 +17,7 @@
Name: perl-Hash-MoreUtils
-Version: 0.03
+Version: 0.04
Release: 0
%define cpan_name Hash-MoreUtils
Summary: Provide the stuff missing in Hash::Util
++++++ Hash-MoreUtils-0.03.tar.gz -> Hash-MoreUtils-0.04.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Hash-MoreUtils-0.03/Build.PL
new/Hash-MoreUtils-0.04/Build.PL
--- old/Hash-MoreUtils-0.03/Build.PL 2013-09-07 16:11:41.000000000 +0200
+++ new/Hash-MoreUtils-0.04/Build.PL 2013-10-04 21:08:43.000000000 +0200
@@ -6,13 +6,17 @@
module_name => 'Hash::MoreUtils',
license => 'perl',
dist_version_from => 'lib/Hash/MoreUtils.pm',
- build_requires => { 'Test::More' => '0.90', },
-
+ build_requires => {
+ 'Test::More' => '0.90',
+ },
dist_author => [ 'Hans Dieter Pearcey <[email protected]>', 'Jens Rehsack
<[email protected]>' ],
- meta_merge => { resources => { repository =>
"https://github.com/perl5-utils/Hash-MoreUtils", }, },
+ meta_merge => {
+ resources => {
+ repository =>
"https://github.com/perl5-utils/Hash-MoreUtils",
+ },
+ },
add_to_cleanup => ['Hash-MoreUtils-*'],
test_files => [ "t/*.t", "xt/*.t" ],
-
);
$builder->create_build_script();
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Hash-MoreUtils-0.03/Changes
new/Hash-MoreUtils-0.04/Changes
--- old/Hash-MoreUtils-0.03/Changes 2013-09-07 16:11:41.000000000 +0200
+++ new/Hash-MoreUtils-0.04/Changes 2013-10-04 21:08:43.000000000 +0200
@@ -1,5 +1,9 @@
Revision history for Hash-MoreUtils
+0.04 2013-10-04
+ - add slice_map family
+ - Changes reformatted as per CPAN::Changes::Spec
+
0.03 2013-09-07
- Add documentation about intended behaviour of slice* when no
list given (fixing RT#77429 and RT#57095), thanks to Titi Ala'ilima
@@ -7,7 +11,7 @@
- Changes reformatted as per CPAN::Changes::Spec
- Move to GitHub.com
-0.02 2010-04-28
+0.02 2010-04-28
- Taking maintainership (Jens Rehsack)
- Implement optimized versions for slice, slice_exists and
slice_def
@@ -15,6 +19,5 @@
- Add safe_reverse as wished in RT#48403 (Ed Davis)
- Add test for hashsort
-0.01 Date/time
+0.01 2005-11-05
- First version, released on an unsuspecting world.
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Hash-MoreUtils-0.03/META.json
new/Hash-MoreUtils-0.04/META.json
--- old/Hash-MoreUtils-0.03/META.json 2013-09-07 16:11:41.000000000 +0200
+++ new/Hash-MoreUtils-0.04/META.json 2013-10-04 21:08:43.000000000 +0200
@@ -5,7 +5,7 @@
"Jens Rehsack <[email protected]>"
],
"dynamic_config" : 1,
- "generated_by" : "Module::Build version 0.4007, CPAN::Meta::Converter
version 2.132140",
+ "generated_by" : "Module::Build version 0.4007, CPAN::Meta::Converter
version 2.132661",
"license" : [
"perl_5"
],
@@ -29,7 +29,7 @@
"provides" : {
"Hash::MoreUtils" : {
"file" : "lib/Hash/MoreUtils.pm",
- "version" : "0.03"
+ "version" : "0.04"
}
},
"release_status" : "stable",
@@ -41,5 +41,5 @@
"url" : "https://github.com/perl5-utils/Hash-MoreUtils"
}
},
- "version" : "0.03"
+ "version" : "0.04"
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Hash-MoreUtils-0.03/META.yml
new/Hash-MoreUtils-0.04/META.yml
--- old/Hash-MoreUtils-0.03/META.yml 2013-09-07 16:11:41.000000000 +0200
+++ new/Hash-MoreUtils-0.04/META.yml 2013-10-04 21:08:43.000000000 +0200
@@ -8,7 +8,7 @@
configure_requires:
Module::Build: 0.40
dynamic_config: 1
-generated_by: 'Module::Build version 0.4007, CPAN::Meta::Converter version
2.132140'
+generated_by: 'Module::Build version 0.4007, CPAN::Meta::Converter version
2.132661'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -17,8 +17,8 @@
provides:
Hash::MoreUtils:
file: lib/Hash/MoreUtils.pm
- version: 0.03
+ version: 0.04
resources:
license: http://dev.perl.org/licenses/
repository: https://github.com/perl5-utils/Hash-MoreUtils
-version: 0.03
+version: 0.04
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Hash-MoreUtils-0.03/lib/Hash/MoreUtils.pm
new/Hash-MoreUtils-0.04/lib/Hash/MoreUtils.pm
--- old/Hash-MoreUtils-0.03/lib/Hash/MoreUtils.pm 2013-09-07
16:11:41.000000000 +0200
+++ new/Hash-MoreUtils-0.04/lib/Hash/MoreUtils.pm 2013-10-04
21:08:43.000000000 +0200
@@ -11,15 +11,15 @@
%EXPORT_TAGS = (
all => [
- qw(slice slice_def slice_exists slice_grep
- hashsort safe_reverse
- )
+ qw(slice slice_def slice_exists slice_grep),
+ qw(slice_map slice_def_map slice_exists_map slice_grep_map),
+ qw(hashsort safe_reverse)
],
);
@EXPORT_OK = ( @{ $EXPORT_TAGS{all} } );
-$VERSION = '0.03';
+$VERSION = '0.04';
=head1 NAME
@@ -43,27 +43,27 @@
Returns a hash containing the (key, value) pair for every
key in LIST.
-If no C<< LIST >> is given, all keys are assumed as C<< LIST >>.
+If no C<LIST> is given, all keys are assumed as C<LIST>.
=head2 C<slice_def> HASHREF[, LIST]
As C<slice>, but only includes keys whose values are
defined.
-If no C<< LIST >> is given, all keys are assumed as C<< LIST >>.
+If no C<LIST> is given, all keys are assumed as C<LIST>.
=head2 C<slice_exists> HASHREF[, LIST]
As C<slice> but only includes keys which exist in the
hashref.
-If no C<< LIST >> is given, all keys are assumed as C<< LIST >>.
+If no C<LIST> is given, all keys are assumed as C<LIST>.
=head2 C<slice_grep> BLOCK, HASHREF[, LIST]
As C<slice>, with an arbitrary condition.
-If no C<< LIST >> is given, all keys are assumed as C<< LIST >>.
+If no C<LIST> is given, all keys are assumed as C<LIST>.
Unlike C<grep>, the condition is not given aliases to
elements of anything. Instead, C<< %_ >> is set to the
@@ -77,37 +77,97 @@
sub slice
{
my ( $href, @list ) = @_;
- if( @list )
- {
- return map { $_ => $href->{$_} } @list;
- }
+ @list and return map { $_ => $href->{$_} } @list;
%{$href};
}
sub slice_exists
{
my ( $href, @list ) = @_;
- if( @list )
- {
- return map { $_ => $href->{$_} } grep {exists( $href->{$_} ) } @list;
- }
- %{$href};
+ @list or @list = keys %{$href};
+ return map { $_ => $href->{$_} } grep {exists( $href->{$_} ) } @list;
}
sub slice_def
{
my ( $href, @list ) = @_;
- @list = keys %{$href} unless @list;
+ @list or @list = keys %{$href};
return map { $_ => $href->{$_} } grep { defined( $href->{$_} ) } @list;
}
sub slice_grep (&@)
{
- my ( $code, $hash, @keys ) = @_;
- local %_ = %{$hash};
- @keys = keys %_ unless @keys;
+ my ( $code, $href, @list ) = @_;
+ local %_ = %{$href};
+ @list or @list = keys %{$href};
+ no warnings 'uninitialized';
+ return map { ( $_ => $_{$_} ) } grep { $code->($_) } @list;
+}
+
+=head2 C<slice_map> HASHREF[, MAP]
+
+Returns a hash containing the (key, value) pair for every
+key in C<MAP>.
+
+If no C<MAP> is given, all keys of C<HASHREF> are assumed mapped to theirself.
+
+=head2 C<slice_def_map> HASHREF[, MAP]
+
+As C<slice_map>, but only includes keys whose values are
+defined.
+
+If no C<MAP> is given, all keys of C<HASHREF> are assumed mapped to theirself.
+
+=head2 C<slice_exists_map> HASHREF[, MAP]
+
+As C<slice_map> but only includes keys which exist in the
+hashref.
+
+If no C<MAP> is given, all keys of C<HASHREF> are assumed mapped to theirself.
+
+=head2 C<slice_grep_map> BLOCK, HASHREF[, MAP]
+
+As C<slice_map>, with an arbitrary condition.
+
+If no C<MAP> is given, all keys of C<HASHREF> are assumed mapped to theirself.
+
+Unlike C<grep>, the condition is not given aliases to
+elements of anything. Instead, C<< %_ >> is set to the
+contents of the hashref, to avoid accidentally
+auto-vivifying when checking keys or values. Also,
+'uninitialized' warnings are turned off in the enclosing
+scope.
+
+=cut
+
+sub slice_map
+{
+ my ( $href, %map ) = @_;
+ %map and return map { $map{$_} => $href->{$_} } keys %map;
+ %{$href};
+}
+
+sub slice_exists_map
+{
+ my ( $href, %map ) = @_;
+ %map or return slice_exists($href);
+ return map { $map{$_} => $href->{$_} } grep {exists( $href->{$_} ) } keys
%map;
+}
+
+sub slice_def_map
+{
+ my ( $href, %map ) = @_;
+ %map or return slice_def($href);
+ return map { $map{$_} => $href->{$_} } grep { defined( $href->{$_} ) }
keys %map;
+}
+
+sub slice_grep_map (&@)
+{
+ my ( $code, $href, %map ) = @_;
+ %map or return goto &slice_grep;
+ local %_ = %{$href};
no warnings 'uninitialized';
- return map { ( $_ => $_{$_} ) } grep { $code->($_) } @keys;
+ return map { ( $map{$_} => $_{$_} ) } grep { $code->($_) } keys %map;
}
=head2 C<hashsort> [BLOCK,] HASHREF
@@ -206,7 +266,7 @@
=head1 AUTHOR
-Hans Dieter Pearcey, C<< <[email protected]> >>
+Hans Dieter Pearcey, C<< <[email protected]> >>,
Jens Rehsack, C<< <[email protected]> >>
=head1 BUGS
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Hash-MoreUtils-0.03/t/01-hash.t
new/Hash-MoreUtils-0.04/t/01-hash.t
--- old/Hash-MoreUtils-0.03/t/01-hash.t 2013-09-07 16:11:41.000000000 +0200
+++ new/Hash-MoreUtils-0.04/t/01-hash.t 2013-10-04 21:08:43.000000000 +0200
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More;
use Hash::MoreUtils qw(:all);
my %h = (a => 1,
@@ -66,6 +66,69 @@
"slice_grep on values",
);
+# slice_map and friends
+
+is_deeply(
+ { slice_map(\%h, (a => "A")) },
+ { A => 1 },
+ "simple_map slice",
+);
+
+is_deeply(
+ { slice_map(\%h, (a => "A", d => "D")) },
+ { A => 1, D => undef },
+ "slice_map to nonexistent",
+);
+
+is_deeply(
+ { slice_map(\%h) },
+ { a => 1, b => 2, c => undef },
+ "slice_map with default keys",
+);
+
+is_deeply(
+ { slice_def_map(\%h, (a => "A", c => "C", d => "D")) },
+ { A => 1 },
+ "slice_def_map undef + nonexistent",
+);
+ok(!exists $h{d}, "slice_def_map didn't autovivify d");
+ok(!exists $h{D}, "slice_def_map didn't autovivify D");
+
+is_deeply(
+ { slice_exists_map(\%h, (a => "A", c => "C", d => "D")) },
+ { A => 1, C => undef },
+ "slice_exists_map nonexistent",
+);
+ok(!exists $h{d}, "slice_exists_map didn't autovivify d");
+ok(!exists $h{D}, "slice_exists_map didn't autovivify D");
+
+is_deeply(
+ { slice_exists_map(\%h) },
+ { a => 1, b => 2, c => undef },
+ "slice_exists_map with default keys",
+);
+
+is_deeply(
+ { slice_def_map \%h },
+ { a => 1, b => 2 },
+ "slice_def_map with default keys",
+);
+
+is_deeply(
+ { slice_grep_map { $_ gt 'a' } \%h, (a => "A", b => "B", c => "C") },
+ { B => 2, C => undef },
+ "slice_grep_map on keys",
+);
+
+is_deeply(
+ { slice_grep_map { $_{$_} && $_{$_} > 1 } \%h, (a => "A", b => "B", c =>
"C") },
+ { B => 2 },
+ "slice_grep_map on values",
+);
+
+
+# hashsort and safe_reverse
+
is_deeply(
[ hashsort \%h ],
[ 'a', 1, 'b', 2, 'c', undef ],
@@ -86,3 +149,5 @@
[ 1, qw(a b) ],
"safe revert with duplicate values and default function",
);
+
+done_testing;
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]