Venus::Hash
Hash Class
Hash Class for Perl 5
method: all method: any method: call method: cast method: count method: default method: delete method: each method: empty method: eq method: exists method: find method: ge method: gele method: grep method: gt method: gtlt method: iterator method: keys method: le method: length method: list method: lt method: map method: merge method: ne method: none method: one method: pairs method: path method: puts method: random method: reset method: reverse method: slice method: tv
package main;
use Venus::Hash;
my $hash = Venus::Hash->new({1..8});
# $hash->random;
This package provides methods for manipulating hash data.
Venus::Kind::Value
Venus::Role::Mappable
The all method returns true if the callback returns true for all of the elements.
all(coderef $code) (boolean)
{ since => '0.01', }
=example-1 all
# given: synopsis;
my $all = $hash->all(sub {
$_ > 1
});
# 1
The any method returns true if the callback returns true for any of the elements.
any(coderef $code) (boolean)
{ since => '0.01', }
=example-1 any
# given: synopsis;
my $any = $hash->any(sub {
$_ < 1
});
# 0
The call method executes the given method (named using the first argument) which performs an iteration (i.e. takes a callback) and calls the method (named using the second argument) on the object (or value) and returns the result of the iterable method.
call(string $iterable, string $method) (any)
{ since => '1.02', }
=example-1 call
# given: synopsis
package main;
my $call = $hash->call('map', 'incr');
# ['1', 3, '3', 5, '5', 7, '7', 9]
The cast method converts "value" objects between different "value" object types, based on the name of the type provided. This method will return undef if the invocant is not a Venus::Kind::Value.
cast(string $kind) (object | undef)
{ since => '0.08', }
=example-1 cast
package main;
use Venus::Hash;
my $hash = Venus::Hash->new;
my $cast = $hash->cast('array');
# bless({ value => [{}] }, "Venus::Array")
The count method returns the total number of keys defined.
count() (number)
{ since => '0.01', }
=example-1 count
# given: synopsis;
my $count = $hash->count;
# 4
The default method returns the default value, i.e. {}.
default() (hashref)
{ since => '0.01', }
=example-1 default
# given: synopsis;
my $default = $hash->default;
# {}
The delete method returns the value matching the key specified in the argument and returns the value.
delete(string $key) (any)
{ since => '0.01', }
=example-1 delete
# given: synopsis;
my $delete = $hash->delete(1);
# 2
The each method executes callback for each element in the hash passing the routine the key and value at the current position in the loop. This method can return a list of values in list-context.
each(coderef $code) (arrayref)
{ since => '0.01', }
=example-1 each
# given: synopsis;
my $each = $hash->each(sub {
[$_]
});
# [[2], [4], [6], [8]]
The empty method drops all elements from the hash.
empty() (hashref)
{ since => '0.01', }
=example-1 empty
# given: synopsis;
my $empty = $hash->empty;
# {}
The eq method performs an "equals" operation using the argument provided.
eq(any $arg) (boolean)
{ since => '0.08', }
=example-1 eq
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->eq($rvalue);
# 0
The exists method returns true if the value matching the key specified in the argument exists, otherwise returns false.
exists(string $key) (boolean)
{ since => '0.01', }
=example-1 exists
# given: synopsis;
my $exists = $hash->exists(1);
# 1
The find method traverses the data structure using the keys and indices provided, returning the value found or undef. In list-context, this method returns a tuple, i.e. the value found and boolean representing whether the match was successful.
find(string @data) (any)
{ since => '0.01', }
=example-1 find
package main;
use Venus::Hash;
my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
my $find = $hash->find('foo', 'bar');
# "baz"
The ge method performs a "greater-than-or-equal-to" operation using the argument provided.
ge(any $arg) (boolean)
{ since => '0.08', }
=example-1 ge
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->ge($rvalue);
# 0
The gele method performs a "greater-than-or-equal-to" operation on the 1st argument, and "lesser-than-or-equal-to" operation on the 2nd argument.
gele(any $arg1, any $arg2) (boolean)
{ since => '0.08', }
=example-1 gele
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->gele($rvalue);
# 0
The grep method executes callback for each key/value pair in the hash passing the routine the key and value at the current position in the loop and returning a new hash reference containing the elements for which the argument evaluated true. This method can return a list of values in list-context.
grep(coderef $code) (arrayref)
{ since => '0.01', }
=example-1 grep
# given: synopsis;
my $grep = $hash->grep(sub {
$_ >= 3
});
# [3..8]
The gt method performs a "greater-than" operation using the argument provided.
gt(any $arg) (boolean)
{ since => '0.08', }
=example-1 gt
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->gt($rvalue);
# 0
The gtlt method performs a "greater-than" operation on the 1st argument, and "lesser-than" operation on the 2nd argument.
gtlt(any $arg1, any $arg2) (boolean)
{ since => '0.08', }
=example-1 gtlt
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->gtlt($rvalue);
# 0
The iterator method returns a code reference which can be used to iterate over the hash. Each time the iterator is executed it will return the values of the next element in the hash until all elements have been seen, at which point the iterator will return an undefined value. This method can return a tuple with the key and value in list-context.
iterator() (coderef)
{ since => '0.01', }
=example-1 iterator
# given: synopsis;
my $iterator = $hash->iterator;
# sub { ... }
# while (my $value = $iterator->()) {
# say $value; # 1
# }
The keys method returns an array reference consisting of all the keys in the hash.
keys() (arrayref)
{ since => '0.01', }
=example-1 keys
# given: synopsis;
my $keys = $hash->keys;
# [1, 3, 5, 7]
The le method performs a "lesser-than-or-equal-to" operation using the argument provided.
le(any $arg) (boolean)
{ since => '0.08', }
=example-1 le
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->le($rvalue);
# 0
The length method returns the total number of keys defined, and is an alias for the "count" method.
length() (number)
{ since => '0.08', }
=example-1 length
# given: synopsis;
my $length = $hash->length;
# 4
The list method returns a shallow copy of the underlying hash reference as an array reference.
list() (any)
{ since => '0.01', }
=example-1 list
# given: synopsis;
my $list = $hash->list;
# 4
The lt method performs a "lesser-than" operation using the argument provided.
lt(any $arg) (boolean)
{ since => '0.08', }
=example-1 lt
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->lt($rvalue);
# 0
The map method executes callback for each key/value in the hash passing the routine the value at the current position in the loop and returning a new hash reference containing the elements for which the argument returns a value or non-empty list. This method can return a list of values in list-context.
map(coderef $code) (arrayref)
{ since => '0.01', }
=example-1 map
# given: synopsis;
my $map = $hash->map(sub {
$_ * 2
});
# [4, 8, 12, 16]
The merge method returns a hash reference where the elements in the hash and the elements in the argument(s) are merged. This operation performs a deep merge and clones the datasets to ensure no side-effects.
merge(hashref @data) (hashref)
{ since => '0.01', }
=example-1 merge
# given: synopsis;
my $merge = $hash->merge({1 => 'a'});
# { 1 => "a", 3 => 4, 5 => 6, 7 => 8 }
The ne method performs a "not-equal-to" operation using the argument provided.
ne(any $arg) (boolean)
{ since => '0.08', }
=example-1 ne
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->ne($rvalue);
# 1
The none method returns true if none of the elements in the array meet the criteria set by the operand and rvalue.
none(coderef $code) (boolean)
{ since => '0.01', }
=example-1 none
# given: synopsis;
my $none = $hash->none(sub {
$_ < 1
});
# 1
The one method returns true if only one of the elements in the array meet the criteria set by the operand and rvalue.
one(coderef $code) (boolean)
{ since => '0.01', }
=example-1 one
# given: synopsis;
my $one = $hash->one(sub {
$_ == 2
});
# 1
The pairs method is an alias to the pairs_array method. This method can return a list of values in list-context.
pairs() (arrayref)
{ since => '0.01', }
=example-1 pairs
# given: synopsis;
my $pairs = $hash->pairs;
# [[1, 2], [3, 4], [5, 6], [7, 8]]
The path method traverses the data structure using the path expr provided, returning the value found or undef. In list-context, this method returns a tuple, i.e. the value found and boolean representing whether the match was successful.
path(string $expr) (any)
{ since => '0.01', }
=example-1 path
package main;
use Venus::Hash;
my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
my $path = $hash->path('/foo/bar');
# "baz"
The puts method select values from within the underlying data structure using "path" in Venus::Hash, optionally assigning the value to the preceeding scalar reference and returns all the values selected.
puts(any @args) (arrayref)
{ since => '3.20', }
The random method returns a random element from the array.
random() (any)
{ since => '0.01', }
=example-1 random
# given: synopsis;
my $random = $hash->random;
# 6
# my $random = $hash->random;
# 4
The reset method returns nullifies the value of each element in the hash.
reset() (arrayref)
{ since => '0.01', }
=example-1 reset
# given: synopsis;
my $reset = $hash->reset;
# { 1 => undef, 3 => undef, 5 => undef, 7 => undef }
The reverse method returns a hash reference consisting of the hash's keys and values inverted. Note, keys with undefined values will be dropped.
reverse() (hashref)
{ since => '0.01', }
=example-1 reverse
# given: synopsis;
my $reverse = $hash->reverse;
# { 2 => 1, 4 => 3, 6 => 5, 8 => 7 }
The slice method returns an array reference of the values that correspond to the key(s) specified in the arguments.
slice(string @keys) (arrayref)
{ since => '0.01', }
=example-1 slice
# given: synopsis;
my $slice = $hash->slice(1, 3);
# [2, 4]
The tv method performs a "type-and-value-equal-to" operation using argument provided.
tv(any $arg) (boolean)
{ since => '0.08', }
=example-1 tv
package main;
use Venus::Array;
use Venus::Hash;
my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->tv($rvalue);
# 0
t/Venus.t: present: authors t/Venus.t: present: license
220 POD Errors
The following errors were encountered while parsing the POD:
- Around line 13:
Unknown directive: =name
- Around line 21:
Unknown directive: =tagline
- Around line 29:
Unknown directive: =abstract
- Around line 37:
Unknown directive: =includes
- Around line 80:
Unknown directive: =synopsis
- Around line 100:
Unknown directive: =description
- Around line 108:
Unknown directive: =inherits
- Around line 116:
Unknown directive: =integrates
- Around line 124:
Unknown directive: =method
- Around line 129:
Unknown directive: =signature
- Around line 133:
Unknown directive: =metadata
- Around line 171:
=cut found outside a pod block. Skipping to next block.
- Around line 181:
Unknown directive: =method
- Around line 186:
Unknown directive: =signature
- Around line 190:
Unknown directive: =metadata
- Around line 228:
=cut found outside a pod block. Skipping to next block.
- Around line 238:
Unknown directive: =method
- Around line 245:
Unknown directive: =signature
- Around line 249:
Unknown directive: =metadata
- Around line 285:
=cut found outside a pod block. Skipping to next block.
- Around line 295:
Unknown directive: =method
- Around line 301:
Unknown directive: =signature
- Around line 305:
Unknown directive: =metadata
- Around line 347:
=cut found outside a pod block. Skipping to next block.
- Around line 371:
=cut found outside a pod block. Skipping to next block.
- Around line 395:
=cut found outside a pod block. Skipping to next block.
- Around line 419:
=cut found outside a pod block. Skipping to next block.
- Around line 443:
=cut found outside a pod block. Skipping to next block.
- Around line 467:
=cut found outside a pod block. Skipping to next block.
- Around line 491:
=cut found outside a pod block. Skipping to next block.
- Around line 515:
=cut found outside a pod block. Skipping to next block.
- Around line 539:
=cut found outside a pod block. Skipping to next block.
- Around line 551:
Unknown directive: =method
- Around line 555:
Unknown directive: =signature
- Around line 559:
Unknown directive: =metadata
- Around line 583:
Unknown directive: =method
- Around line 587:
Unknown directive: =signature
- Around line 591:
Unknown directive: =metadata
- Around line 615:
Unknown directive: =method
- Around line 620:
Unknown directive: =signature
- Around line 624:
Unknown directive: =metadata
- Around line 648:
Unknown directive: =method
- Around line 654:
Unknown directive: =signature
- Around line 658:
Unknown directive: =metadata
- Around line 696:
=cut found outside a pod block. Skipping to next block.
- Around line 706:
Unknown directive: =method
- Around line 710:
Unknown directive: =signature
- Around line 714:
Unknown directive: =metadata
- Around line 738:
Unknown directive: =method
- Around line 742:
Unknown directive: =signature
- Around line 746:
Unknown directive: =metadata
- Around line 790:
=cut found outside a pod block. Skipping to next block.
- Around line 814:
=cut found outside a pod block. Skipping to next block.
- Around line 837:
=cut found outside a pod block. Skipping to next block.
- Around line 861:
=cut found outside a pod block. Skipping to next block.
- Around line 885:
=cut found outside a pod block. Skipping to next block.
- Around line 909:
=cut found outside a pod block. Skipping to next block.
- Around line 933:
=cut found outside a pod block. Skipping to next block.
- Around line 957:
=cut found outside a pod block. Skipping to next block.
- Around line 967:
Unknown directive: =method
- Around line 972:
Unknown directive: =signature
- Around line 976:
Unknown directive: =metadata
- Around line 1008:
=cut found outside a pod block. Skipping to next block.
- Around line 1018:
Unknown directive: =method
- Around line 1025:
Unknown directive: =signature
- Around line 1029:
Unknown directive: =metadata
- Around line 1069:
=cut found outside a pod block. Skipping to next block.
- Around line 1091:
=cut found outside a pod block. Skipping to next block.
- Around line 1113:
=cut found outside a pod block. Skipping to next block.
- Around line 1125:
Unknown directive: =method
- Around line 1130:
Unknown directive: =signature
- Around line 1134:
Unknown directive: =metadata
- Around line 1178:
=cut found outside a pod block. Skipping to next block.
- Around line 1202:
=cut found outside a pod block. Skipping to next block.
- Around line 1225:
=cut found outside a pod block. Skipping to next block.
- Around line 1249:
=cut found outside a pod block. Skipping to next block.
- Around line 1273:
=cut found outside a pod block. Skipping to next block.
- Around line 1297:
=cut found outside a pod block. Skipping to next block.
- Around line 1321:
=cut found outside a pod block. Skipping to next block.
- Around line 1345:
=cut found outside a pod block. Skipping to next block.
- Around line 1355:
Unknown directive: =method
- Around line 1360:
Unknown directive: =signature
- Around line 1364:
Unknown directive: =metadata
- Around line 1408:
=cut found outside a pod block. Skipping to next block.
- Around line 1432:
=cut found outside a pod block. Skipping to next block.
- Around line 1455:
=cut found outside a pod block. Skipping to next block.
- Around line 1479:
=cut found outside a pod block. Skipping to next block.
- Around line 1503:
=cut found outside a pod block. Skipping to next block.
- Around line 1527:
=cut found outside a pod block. Skipping to next block.
- Around line 1551:
=cut found outside a pod block. Skipping to next block.
- Around line 1575:
=cut found outside a pod block. Skipping to next block.
- Around line 1585:
Unknown directive: =method
- Around line 1592:
Unknown directive: =signature
- Around line 1596:
Unknown directive: =metadata
- Around line 1634:
=cut found outside a pod block. Skipping to next block.
- Around line 1644:
Unknown directive: =method
- Around line 1648:
Unknown directive: =signature
- Around line 1652:
Unknown directive: =metadata
- Around line 1696:
=cut found outside a pod block. Skipping to next block.
- Around line 1720:
=cut found outside a pod block. Skipping to next block.
- Around line 1743:
=cut found outside a pod block. Skipping to next block.
- Around line 1767:
=cut found outside a pod block. Skipping to next block.
- Around line 1791:
=cut found outside a pod block. Skipping to next block.
- Around line 1815:
=cut found outside a pod block. Skipping to next block.
- Around line 1839:
=cut found outside a pod block. Skipping to next block.
- Around line 1863:
=cut found outside a pod block. Skipping to next block.
- Around line 1873:
Unknown directive: =method
- Around line 1878:
Unknown directive: =signature
- Around line 1882:
Unknown directive: =metadata
- Around line 1926:
=cut found outside a pod block. Skipping to next block.
- Around line 1950:
=cut found outside a pod block. Skipping to next block.
- Around line 1973:
=cut found outside a pod block. Skipping to next block.
- Around line 1997:
=cut found outside a pod block. Skipping to next block.
- Around line 2021:
=cut found outside a pod block. Skipping to next block.
- Around line 2045:
=cut found outside a pod block. Skipping to next block.
- Around line 2069:
=cut found outside a pod block. Skipping to next block.
- Around line 2093:
=cut found outside a pod block. Skipping to next block.
- Around line 2103:
Unknown directive: =method
- Around line 2111:
Unknown directive: =signature
- Around line 2115:
Unknown directive: =metadata
- Around line 2157:
=cut found outside a pod block. Skipping to next block.
- Around line 2170:
Unknown directive: =method
- Around line 2175:
Unknown directive: =signature
- Around line 2179:
Unknown directive: =metadata
- Around line 2203:
Unknown directive: =method
- Around line 2208:
Unknown directive: =signature
- Around line 2212:
Unknown directive: =metadata
- Around line 2256:
=cut found outside a pod block. Skipping to next block.
- Around line 2280:
=cut found outside a pod block. Skipping to next block.
- Around line 2303:
=cut found outside a pod block. Skipping to next block.
- Around line 2327:
=cut found outside a pod block. Skipping to next block.
- Around line 2351:
=cut found outside a pod block. Skipping to next block.
- Around line 2375:
=cut found outside a pod block. Skipping to next block.
- Around line 2399:
=cut found outside a pod block. Skipping to next block.
- Around line 2423:
=cut found outside a pod block. Skipping to next block.
- Around line 2433:
Unknown directive: =method
- Around line 2438:
Unknown directive: =signature
- Around line 2442:
Unknown directive: =metadata
- Around line 2466:
Unknown directive: =method
- Around line 2471:
Unknown directive: =signature
- Around line 2475:
Unknown directive: =metadata
- Around line 2507:
=cut found outside a pod block. Skipping to next block.
- Around line 2517:
Unknown directive: =method
- Around line 2521:
Unknown directive: =signature
- Around line 2525:
Unknown directive: =metadata
- Around line 2569:
=cut found outside a pod block. Skipping to next block.
- Around line 2593:
=cut found outside a pod block. Skipping to next block.
- Around line 2616:
=cut found outside a pod block. Skipping to next block.
- Around line 2640:
=cut found outside a pod block. Skipping to next block.
- Around line 2664:
=cut found outside a pod block. Skipping to next block.
- Around line 2688:
=cut found outside a pod block. Skipping to next block.
- Around line 2712:
=cut found outside a pod block. Skipping to next block.
- Around line 2736:
=cut found outside a pod block. Skipping to next block.
- Around line 2746:
Unknown directive: =method
- Around line 2753:
Unknown directive: =signature
- Around line 2757:
Unknown directive: =metadata
- Around line 2795:
=cut found outside a pod block. Skipping to next block.
- Around line 2805:
Unknown directive: =method
- Around line 2811:
Unknown directive: =signature
- Around line 2815:
Unknown directive: =metadata
- Around line 2847:
=cut found outside a pod block. Skipping to next block.
- Around line 2857:
Unknown directive: =method
- Around line 2861:
Unknown directive: =signature
- Around line 2865:
Unknown directive: =metadata
- Around line 2909:
=cut found outside a pod block. Skipping to next block.
- Around line 2933:
=cut found outside a pod block. Skipping to next block.
- Around line 2956:
=cut found outside a pod block. Skipping to next block.
- Around line 2980:
=cut found outside a pod block. Skipping to next block.
- Around line 3004:
=cut found outside a pod block. Skipping to next block.
- Around line 3028:
=cut found outside a pod block. Skipping to next block.
- Around line 3052:
=cut found outside a pod block. Skipping to next block.
- Around line 3076:
=cut found outside a pod block. Skipping to next block.
- Around line 3086:
Unknown directive: =method
- Around line 3091:
Unknown directive: =signature
- Around line 3095:
Unknown directive: =metadata
- Around line 3133:
=cut found outside a pod block. Skipping to next block.
- Around line 3143:
Unknown directive: =method
- Around line 3148:
Unknown directive: =signature
- Around line 3152:
Unknown directive: =metadata
- Around line 3190:
=cut found outside a pod block. Skipping to next block.
- Around line 3200:
Unknown directive: =method
- Around line 3205:
Unknown directive: =signature
- Around line 3209:
Unknown directive: =metadata
- Around line 3233:
Unknown directive: =method
- Around line 3240:
Unknown directive: =signature
- Around line 3244:
Unknown directive: =metadata
- Around line 3284:
=cut found outside a pod block. Skipping to next block.
- Around line 3306:
=cut found outside a pod block. Skipping to next block.
- Around line 3328:
=cut found outside a pod block. Skipping to next block.
- Around line 3340:
Unknown directive: =method
- Around line 3346:
Unknown directive: =signature
- Around line 3350:
Unknown directive: =metadata
- Around line 3377:
=cut found outside a pod block. Skipping to next block.
- Around line 3408:
=cut found outside a pod block. Skipping to next block.
- Around line 3444:
=cut found outside a pod block. Skipping to next block.
- Around line 3474:
=cut found outside a pod block. Skipping to next block.
- Around line 3484:
Unknown directive: =method
- Around line 3488:
Unknown directive: =signature
- Around line 3492:
Unknown directive: =metadata
- Around line 3519:
Unknown directive: =method
- Around line 3523:
Unknown directive: =signature
- Around line 3527:
Unknown directive: =metadata
- Around line 3551:
Unknown directive: =method
- Around line 3556:
Unknown directive: =signature
- Around line 3560:
Unknown directive: =metadata
- Around line 3584:
Unknown directive: =method
- Around line 3589:
Unknown directive: =signature
- Around line 3593:
Unknown directive: =metadata
- Around line 3617:
Unknown directive: =method
- Around line 3622:
Unknown directive: =signature
- Around line 3626:
Unknown directive: =metadata
- Around line 3670:
=cut found outside a pod block. Skipping to next block.
- Around line 3694:
=cut found outside a pod block. Skipping to next block.
- Around line 3717:
=cut found outside a pod block. Skipping to next block.
- Around line 3741:
=cut found outside a pod block. Skipping to next block.
- Around line 3765:
=cut found outside a pod block. Skipping to next block.
- Around line 3789:
=cut found outside a pod block. Skipping to next block.
- Around line 3813:
=cut found outside a pod block. Skipping to next block.
- Around line 3837:
=cut found outside a pod block. Skipping to next block.
- Around line 3847:
Unknown directive: =partials