Hash-MoreUtils-0.06/ 000755 000765 000024 00000000000 13306502651 014206 5 ustar 00sno staff 000000 000000 Hash-MoreUtils-0.06/Changes 000644 000765 000024 00000002646 13306501125 015504 0 ustar 00sno staff 000000 000000 Revision history for Hash-MoreUtils
0.06 2018-06-08
- update toolchain for modern perl environments including
* automated regression test
* test coverage analyzation
* pod coverage
- introducing common code style
- introduce a bunch of missing functions:
* slice_without (Thanks to Theo van Hoesel
)
* slice_missing / slice_missing_map (Thanks to Christoph Zimmermann )
* slice_notdef / slice_notdef_map (Thanks to Christoph Zimmermann )
* slice_true / slice_true_map
* slice_false / slice_false_map
0.05 2013-12-09
- Fix hashsort with sort block (Koichi Nakashima - http://nksm.name)
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
and Bernhard Graf
- Changes reformatted as per CPAN::Changes::Spec
- Move to GitHub.com
0.02 2010-04-28
- Taking maintainership (Jens Rehsack)
- Implement optimized versions for slice, slice_exists and
slice_def
- Add test for each function to work proper with default keys
- Add safe_reverse as wished in RT#48403 (Ed Davis)
- Add test for hashsort
0.01 2005-11-05
- First version, released on an unsuspecting world.
Hash-MoreUtils-0.06/MANIFEST 000644 000765 000024 00000000440 13306502651 015335 0 ustar 00sno staff 000000 000000 Changes
lib/Hash/MoreUtils.pm
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
README.md
t/00-load.t
t/01-hash.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
Hash-MoreUtils-0.06/t/ 000755 000765 000024 00000000000 13306502650 014450 5 ustar 00sno staff 000000 000000 Hash-MoreUtils-0.06/README.md 000644 000765 000024 00000017023 13306501140 015460 0 ustar 00sno staff 000000 000000 # NAME
Hash::MoreUtils - Provide the stuff missing in Hash::Util
# SYNOPSIS
use Hash::MoreUtils qw(:all);
my %h = (foo => "bar", FOO => "BAR", true => 1, false => 0);
my %s = slice \%h, qw(true false); # (true => 1, false => 0)
my %f = slice_false \%h; # (false => 0)
my %u = slice_grep { $_ =~ m/^[A-Z]/ }, \%h; # (FOO => "BAR")
my %r = safe_reverse \%h; # (bar => "foo", BAR => "FOO", 0 => "false", 1 => "true")
# DESCRIPTION
Similar to [List::MoreUtils](https://metacpan.org/pod/List::MoreUtils), `Hash::MoreUtils` contains trivial
but commonly-used functionality for hashes. The primary focus for
the moment is providing a common API - speeding up by XS is far
away at the moment.
# FUNCTIONS
## `slice` HASHREF\[, LIST\]
Returns a hash containing the (key, value) pair for every
key in LIST.
If no `LIST` is given, all keys are assumed as `LIST`.
## `slice_def` HASHREF\[, LIST\]
As `slice`, but only includes keys whose values are
defined.
If no `LIST` is given, all keys are assumed as `LIST`.
## `slice_exists` HASHREF\[, LIST\]
As `slice` but only includes keys which exist in the
hashref.
If no `LIST` is given, all keys are assumed as `LIST`.
## `slice_without` HASHREF\[, LIST \]
As `slice` but without any (key/value) pair whose key is
in LIST.
If no `LIST` is given, in opposite to slice an empty list
is assumed, thus nothing will be deleted.
## `slice_missing` HASHREF\[, LIST\]
Returns a HASH containing the (key => undef) pair for every
`LIST` element (as key) that does not exist hashref.
If no `LIST` is given there are obviously no non-existent
keys in `HASHREF` so the returned HASH is empty.
## `slice_notdef` HASHREF\[, LIST\]
Searches for undefined slices with the given `LIST`
elements as keys in the given `HASHREF`.
Returns a `HASHREF` containing the slices (key -> undef)
for every undefined item.
To search for undefined slices `slice_notdef` needs a
`LIST` with items to search for (as keys). If no `LIST`
is given it returns an empty `HASHREF` even when the given
`HASHREF` contains undefined slices.
## `slice_true` HASHREF\[, LIST\]
A special `slice_grep` which returns only those elements
of the hash which's values evaluates to `TRUE`.
If no `LIST` is given, all keys are assumed as `LIST`.
## `slice_false` HASHREF\[, LIST\]
A special `slice_grep` which returns only those elements
of the hash which's values evaluates to `FALSE`.
If no `LIST` is given, all keys are assumed as `LIST`.
## `slice_grep` BLOCK, HASHREF\[, LIST\]
As `slice`, with an arbitrary condition.
If no `LIST` is given, all keys are assumed as `LIST`.
Unlike `grep`, the condition is not given aliases to
elements of anything. Instead, `%_` 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.
## `slice_map` HASHREF\[, MAP\]
Returns a hash containing the (key, value) pair for every
key in `MAP`.
If no `MAP` is given, all keys of `HASHREF` are assumed mapped to themselves.
## `slice_def_map` HASHREF\[, MAP\]
As `slice_map`, but only includes keys whose values are
defined.
If no `MAP` is given, all keys of `HASHREF` are assumed mapped to themselves.
## `slice_exists_map` HASHREF\[, MAP\]
As `slice_map` but only includes keys which exist in the
hashref.
If no `MAP` is given, all keys of `HASHREF` are assumed mapped to themselves.
## `slice_missing_map` HASHREF\[, MAP\]
As `slice_missing` but checks for missing keys (of `MAP`) and map to the value (of `MAP`) as key in the returned HASH.
The slices of the returned `HASHREF` are always undefined.
If no `MAP` is given, `slice_missing` will be used on `HASHREF` which will return an empty HASH.
## `slice_notdef_map` HASHREF\[, MAP\]
As `slice_notdef` but checks for undefined keys (of `MAP`) and map to the value (of `MAP`) as key in the returned HASH.
If no `MAP` is given, `slice_notdef` will be used on `HASHREF` which will return an empty HASH.
## `slice_true_map` HASHREF\[, MAP\]
As `slice_map`, but only includes pairs whose values are
`TRUE`.
If no `MAP` is given, all keys of `HASHREF` are assumed mapped to themselves.
## `slice_false_map` HASHREF\[, MAP\]
As `slice_map`, but only includes pairs whose values are
`FALSE`.
If no `MAP` is given, all keys of `HASHREF` are assumed mapped to themselves.
## `slice_grep_map` BLOCK, HASHREF\[, MAP\]
As `slice_map`, with an arbitrary condition.
If no `MAP` is given, all keys of `HASHREF` are assumed mapped to themselves.
Unlike `grep`, the condition is not given aliases to
elements of anything. Instead, `%_` 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.
## `hashsort` \[BLOCK,\] HASHREF
my @array_of_pairs = hashsort \%hash;
my @pairs_by_length = hashsort sub { length($a) <=> length($b) }, \%hash;
Returns the (key, value) pairs of the hash, sorted by some
property of the keys. By default (if no sort block given), sorts the
keys with `cmp`.
I'm not convinced this is useful yet. If you can think of
some way it could be more so, please let me know.
## `safe_reverse` \[BLOCK,\] HASHREF
my %dup_rev = safe_reverse \%hash
sub croak_dup {
my ($k, $v, $r) = @_;
exists( $r->{$v} ) and
croak "Cannot safe reverse: $v would be mapped to both $k and $r->{$v}";
$v;
};
my %easy_rev = safe_reverse \&croak_dup, \%hash
Returns safely reversed hash (value, key pairs of original hash). If no
`BLOCK` is given, following routine will be used:
sub merge_dup {
my ($k, $v, $r) = @_;
return exists( $r->{$v} )
? ( ref($r->{$v}) ? [ @{$r->{$v}}, $k ] : [ $r->{$v}, $k ] )
: $k;
};
The `BLOCK` will be called with 3 arguments:
- `key`
The key from the `( key, value )` pair in the original hash
- `value`
The value from the `( key, value )` pair in the original hash
- `ref-hash`
Reference to the reversed hash (read-only)
The `BLOCK` is expected to return the value which will used
for the resulting hash.
# AUTHOR
Hans Dieter Pearcey, ``,
Jens Rehsack, ``
# BUGS
Please report any bugs or feature requests to
`bug-hash-moreutils@rt.cpan.org`, or through the web interface at
[http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hash-MoreUtils](http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hash-MoreUtils).
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
# SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Hash::MoreUtils
You can also look for information at:
- RT: CPAN's request tracker
[http://rt.cpan.org/NoAuth/Bugs.html?Dist=Hash-MoreUtils](http://rt.cpan.org/NoAuth/Bugs.html?Dist=Hash-MoreUtils)
- AnnoCPAN: Annotated CPAN documentation
[http://annocpan.org/dist/Hash-MoreUtils](http://annocpan.org/dist/Hash-MoreUtils)
- CPAN Ratings
[http://cpanratings.perl.org/d/Hash-MoreUtils](http://cpanratings.perl.org/d/Hash-MoreUtils)
- Search CPAN
[http://search.cpan.org/dist/Hash-MoreUtils/](http://search.cpan.org/dist/Hash-MoreUtils/)
# ACKNOWLEDGEMENTS
# COPYRIGHT & LICENSE
Copyright 2005 Hans Dieter Pearcey, all rights reserved.
Copyright 2010-2018 Jens Rehsack
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
Hash-MoreUtils-0.06/MANIFEST.SKIP 000644 000765 000024 00000000515 13267356547 016126 0 ustar 00sno staff 000000 000000 \B\.svn\b
\B\.git\b
\.gitignore$
.travis.yml
\.[Bb][Aa][Kk]$
\.orig$
\.old$
\.tdy$
\.tmp$
\..*swp
^Makefile$
^Build$
^Build\.bat$
\.Inline/.*
_Inline/.*
\.bak$
\.tar$
\.tgz$
\.tar\.gz$
^mess/
^tmp/
^testdata/
^blib/
^sandbox/
^pm_to_blib$
^cover_db/
^_build/.*
~$
.*\.planner
^\..*
Hash-MoreUtils-.*
\bxt
^MYMETA\.json$
^MYMETA\..*$
Hash-MoreUtils-0.06/META.yml 000644 000765 000024 00000001521 13306502650 015455 0 ustar 00sno staff 000000 000000 ---
abstract: 'Provide the stuff missing in Hash::Util'
author:
- 'Hans Dieter Pearcey '
- 'Jens Rehsack '
build_requires:
Test::More: '0.9'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Hash-MoreUtils
no_index:
directory:
- t
- inc
requires:
perl: v5.8.1
resources:
bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=Hash-MoreUtils
homepage: https://metacpan.org/release/Hash-MoreUtils
license: http://dev.perl.org/licenses/
repository: https://github.com/perl5-utils/Hash-MoreUtils.git
version: '0.06'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
Hash-MoreUtils-0.06/lib/ 000755 000765 000024 00000000000 13306502650 014753 5 ustar 00sno staff 000000 000000 Hash-MoreUtils-0.06/Makefile.PL 000644 000765 000024 00000010725 13267373135 016176 0 ustar 00sno staff 000000 000000 use strict;
use warnings;
use 5.008001;
use ExtUtils::MakeMaker;
my %RUN_DEPS = ();
my %CONFIGURE_DEPS = (
'ExtUtils::MakeMaker' => 0,
);
my %BUILD_DEPS = ();
my %TEST_DEPS = (
'Test::More' => 0.90,
);
WriteMakefile1(
MIN_PERL_VERSION => '5.008001',
META_ADD => {
'meta-spec' => {version => 2},
resources => {
homepage => 'https://metacpan.org/release/Hash-MoreUtils',
repository => {
url => 'https://github.com/perl5-utils/Hash-MoreUtils.git',
web => 'https://github.com/perl5-utils/Hash-MoreUtils',
type => 'git',
},
bugtracker => {
web => 'http://rt.cpan.org/Public/Dist/Display.html?Name=Hash-MoreUtils',
mailto => 'bug-Hash-MoreUtils@rt.cpan.org',
},
license => 'http://dev.perl.org/licenses/',
},
prereqs => {
develop => {
requires => {
'Test::CPAN::Changes' => 0,
'Test::CheckManifest' => 0,
'Module::CPANTS::Analyse' => '0.96',
'Test::Kwalitee' => 0,
'Test::Pod' => 0,
'Test::Pod::Coverage' => 0,
'Test::Pod::Spelling::CommonMistakes' => 0,
'Test::Spelling' => 0,
'Test::Perl::Critic' => 0,
'Test::PerlTidy' => 0,
},
},
configure => {
requires => {%CONFIGURE_DEPS},
},
build => {requires => {%BUILD_DEPS}},
test => {requires => {%TEST_DEPS}},
runtime => {
requires => {
%RUN_DEPS,
perl => '5.8.1',
},
},
},
},
NAME => 'Hash::MoreUtils',
VERSION_FROM => 'lib/Hash/MoreUtils.pm',
ABSTRACT_FROM => 'lib/Hash/MoreUtils.pm',
LICENSE => 'perl',
AUTHOR => ['Hans Dieter Pearcey ', 'Jens Rehsack '],
CONFIGURE_REQUIRES => \%CONFIGURE_DEPS,
PREREQ_PM => \%RUN_DEPS,
BUILD_REQUIRES => \%BUILD_DEPS,
TEST_REQUIRES => \%TEST_DEPS,
test => {TESTS => 't/*.t xt/*.t'},
);
sub WriteMakefile1
{ # originally written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade.
my %params = @_;
my $eumm_version = $ExtUtils::MakeMaker::VERSION;
$eumm_version = eval $eumm_version;
die "EXTRA_META is deprecated" if (exists($params{EXTRA_META}));
die "License not specified" if (!exists($params{LICENSE}));
$params{TEST_REQUIRES}
and $eumm_version < 6.6303
and $params{BUILD_REQUIRES} = {%{$params{BUILD_REQUIRES} || {}}, %{delete $params{TEST_REQUIRES}}};
#EUMM 6.5502 has problems with BUILD_REQUIRES
$params{BUILD_REQUIRES}
and $eumm_version < 6.5503
and $params{PREREQ_PM} = {%{$params{PREREQ_PM} || {}}, %{delete $params{BUILD_REQUIRES}}};
ref $params{AUTHOR}
and "ARRAY" eq ref $params{AUTHOR}
and $eumm_version < 6.5702
and $params{AUTHOR} = join(", ", @{$params{AUTHOR}});
delete $params{CONFIGURE_REQUIRES} if ($eumm_version < 6.52);
delete $params{MIN_PERL_VERSION} if ($eumm_version < 6.48);
delete $params{META_MERGE} if ($eumm_version < 6.46);
delete $params{META_ADD}{prereqs} if ($eumm_version < 6.58);
delete $params{META_ADD}{'meta-spec'} if ($eumm_version < 6.58);
delete $params{META_ADD} if ($eumm_version < 6.46);
delete $params{LICENSE} if ($eumm_version < 6.31);
delete $params{AUTHOR} if ($] < 5.005);
delete $params{ABSTRACT_FROM} if ($] < 5.005);
delete $params{BINARY_LOCATION} if ($] < 5.005);
# more or less taken from Moose' Makefile.PL
if ($params{CONFLICTS})
{
my $ok = CheckConflicts(%params);
exit(0) if ($params{PREREQ_FATAL} and not $ok);
my $cpan_smoker = grep { $_ =~ m/(?:CR_SMOKER|CPAN_REPORTER|AUTOMATED_TESTING)/ } keys %ENV;
unless ($cpan_smoker || $ENV{PERL_MM_USE_DEFAULT})
{
sleep 4 unless ($ok);
}
delete $params{CONFLICTS};
}
WriteMakefile(%params);
}
Hash-MoreUtils-0.06/META.json 000644 000765 000024 00000003754 13306502651 015640 0 ustar 00sno staff 000000 000000 {
"abstract" : "Provide the stuff missing in Hash::Util",
"author" : [
"Hans Dieter Pearcey ",
"Jens Rehsack "
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Hash-MoreUtils",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"develop" : {
"requires" : {
"Module::CPANTS::Analyse" : "0.96",
"Test::CPAN::Changes" : "0",
"Test::CheckManifest" : "0",
"Test::Kwalitee" : "0",
"Test::Perl::Critic" : "0",
"Test::PerlTidy" : "0",
"Test::Pod" : "0",
"Test::Pod::Coverage" : "0",
"Test::Pod::Spelling::CommonMistakes" : "0",
"Test::Spelling" : "0"
}
},
"runtime" : {
"requires" : {
"perl" : "v5.8.1"
}
},
"test" : {
"requires" : {
"Test::More" : "0.9"
}
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"mailto" : "bug-Hash-MoreUtils@rt.cpan.org",
"web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=Hash-MoreUtils"
},
"homepage" : "https://metacpan.org/release/Hash-MoreUtils",
"license" : [
"http://dev.perl.org/licenses/"
],
"repository" : {
"type" : "git",
"url" : "https://github.com/perl5-utils/Hash-MoreUtils.git",
"web" : "https://github.com/perl5-utils/Hash-MoreUtils"
}
},
"version" : "0.06",
"x_serialization_backend" : "JSON::PP version 2.27400_02"
}
Hash-MoreUtils-0.06/lib/Hash/ 000755 000765 000024 00000000000 13306502650 015636 5 ustar 00sno staff 000000 000000 Hash-MoreUtils-0.06/lib/Hash/MoreUtils.pm 000644 000765 000024 00000030047 13306500101 020110 0 ustar 00sno staff 000000 000000 package Hash::MoreUtils;
use strict;
use warnings;
use vars qw(@EXPORT_OK %EXPORT_TAGS $VERSION);
use base 'Exporter';
%EXPORT_TAGS = (
all => [
qw(slice slice_def slice_exists slice_without slice_missing),
qw(slice_notdef slice_true slice_false slice_grep),
qw(slice_map slice_def_map slice_exists_map slice_missing_map),
qw(slice_notdef_map slice_true_map slice_false_map slice_grep_map),
qw(hashsort safe_reverse)
],
);
@EXPORT_OK = (@{$EXPORT_TAGS{all}});
$VERSION = '0.06';
=head1 NAME
Hash::MoreUtils - Provide the stuff missing in Hash::Util
=head1 SYNOPSIS
use Hash::MoreUtils qw(:all);
my %h = (foo => "bar", FOO => "BAR", true => 1, false => 0);
my %s = slice \%h, qw(true false); # (true => 1, false => 0)
my %f = slice_false \%h; # (false => 0)
my %u = slice_grep { $_ =~ m/^[A-Z]/ }, \%h; # (FOO => "BAR")
my %r = safe_reverse \%h; # (bar => "foo", BAR => "FOO", 0 => "false", 1 => "true")
=head1 DESCRIPTION
Similar to L, C contains trivial
but commonly-used functionality for hashes. The primary focus for
the moment is providing a common API - speeding up by XS is far
away at the moment.
=head1 FUNCTIONS
=head2 C HASHREF[, LIST]
Returns a hash containing the (key, value) pair for every
key in LIST.
If no C is given, all keys are assumed as C.
=head2 C HASHREF[, LIST]
As C, but only includes keys whose values are
defined.
If no C is given, all keys are assumed as C.
=head2 C HASHREF[, LIST]
As C but only includes keys which exist in the
hashref.
If no C is given, all keys are assumed as C.
=head2 C HASHREF[, LIST ]
As C but without any (key/value) pair whose key is
in LIST.
If no C is given, in opposite to slice an empty list
is assumed, thus nothing will be deleted.
=head2 C HASHREF[, LIST]
Returns a HASH containing the (key => undef) pair for every
C element (as key) that does not exist hashref.
If no C is given there are obviously no non-existent
keys in C so the returned HASH is empty.
=head2 C HASHREF[, LIST]
Searches for undefined slices with the given C
elements as keys in the given C.
Returns a C containing the slices (key -> undef)
for every undefined item.
To search for undefined slices C needs a
C with items to search for (as keys). If no C
is given it returns an empty C even when the given
C contains undefined slices.
=head2 C HASHREF[, LIST]
A special C which returns only those elements
of the hash which's values evaluates to C.
If no C is given, all keys are assumed as C.
=head2 C HASHREF[, LIST]
A special C which returns only those elements
of the hash which's values evaluates to C.
If no C is given, all keys are assumed as C.
=head2 C BLOCK, HASHREF[, LIST]
As C, with an arbitrary condition.
If no C is given, all keys are assumed as C.
Unlike C, 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
{
my ($href, @list) = @_;
@list and return map { $_ => $href->{$_} } @list;
return %{$href};
}
sub slice_exists
{
my ($href, @list) = @_;
@list or @list = keys %{$href};
return map { $_ => $href->{$_} } grep { exists($href->{$_}) } @list;
}
sub slice_without
{
my ($href, @list) = @_;
@list or return %{$href};
local %_ = %{$href};
delete $_{$_} for @list;
return %_;
}
sub slice_def
{
my ($href, @list) = @_;
@list or @list = keys %{$href};
return map { $_ => $href->{$_} } grep { defined($href->{$_}) } @list;
}
sub slice_missing
{
my ($href, @list) = @_;
@list or return ();
return map { $_ => undef } grep { !exists($href->{$_}) } @list;
}
sub slice_notdef
{
my ($href, @list) = @_;
@list or return ();
return map { $_ => undef } grep { !defined($href->{$_}) } @list;
}
sub slice_true
{
my ($href, @list) = @_;
@list or @list = keys %{$href};
return map { $_ => $href->{$_} } grep { defined $href->{$_} and $href->{$_} } @list;
}
sub slice_false
{
my ($href, @list) = @_;
@list or @list = keys %{$href};
return map { $_ => $href->{$_} } grep { not $href->{$_} } @list;
}
## no critic (Subroutines::ProhibitSubroutinePrototypes)
sub slice_grep (&@)
{
my ($code, $href, @list) = @_;
local %_ = %{$href};
@list or @list = keys %{$href};
no warnings 'uninitialized'; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
return map { ($_ => $_{$_}) } grep { $code->($_) } @list;
}
use warnings;
=head2 C HASHREF[, MAP]
Returns a hash containing the (key, value) pair for every
key in C