blib/lib/Venus/Hash.pm

filter: Statementstmt 97.9% 238 / 243 Branchbran 77.3% 82 / 106 Conditioncond 60.0% 9 / 15 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 85.4% 41 / 48 Podpod 97.1% 34 / 35 totaltotal 89.2% 408 / 457 CC 68 SCAR 15.0
CC
68
Cov
90%
sets
9.5
puts
9.2
none
6.4
CRAP 4.5
« blib/lib/Venus/Hook.pm ↑ Summary blib/lib/Venus/Json.pm »
1 package Venus::Hash;
2  
3 25 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 25 ▶use Venus::Class 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 25 base 'Venus::Kind::Value';
15  
16 # INTEGRATES
17  
18 25 with 'Venus::Role::Mappable';
19  
20 # BUILDERS
21  
22 618 ▶sub build_args {
Subroutine build_args: called CC=3 SCAR=11.0
Pod undocumented
23 618 my ($self, $data) = @_;
24  
25 618 ▶ if (keys %$data == 1 && exists $data->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::keys %$data == 1 and exists $data->{"value"}) 123 495 618
Condition100%3/3
CORE::keys %$data == 1 and exists $data->{"value"}
!ll&&!rl&&r
42471123
MC/DC100%2/2
CORE::keys %$data == 1 and exists $data->{"value"}
CORE::keys %$data == 1 exists $data->{"value"}
Truth table100%3/3
A and B
A= CORE::keys %$data == 1B= exists $data->{"value"}
ABresult
0X0
100
111
26 123 return $data;
27 }
28 return {
29 495 value => $data
30 };
31 }
32  
33 # METHODS
34  
35 4 ▶sub all {
Subroutine all: called CC=6 SCAR=17.9
Pod documented
36 4 my ($self, $code) = @_;
37  
38 4 my $data = $self->get;
39  
40 4 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 4 4
41  
42 4 my $failed = 0;
43  
44 4 for my $index (CORE::keys %$data) {
45 10 my $value = $data->{$index};
46  
47 10 local $_ = $value;
48 10 ▶ $failed++ if !$code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
unless &$code($index, $value) 1 9 10
49  
50 10 ▶ CORE::last if $failed;
Branch: 1 branch
BranchTrueFalseTotal
if $failed 1 9 10
51 }
52  
53 4 ▶ return $failed ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
$failed ? : 1 3 4
54 }
55  
56 6 ▶sub any {
Subroutine any: called CC=6 SCAR=17.9
Pod documented
57 6 my ($self, $code) = @_;
58  
59 6 my $data = $self->get;
60  
61 6 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 6 6
62  
63 6 my $found = 0;
64  
65 6 for my $index (CORE::keys %$data) {
66 12 my $value = $data->{$index};
67  
68 12 local $_ = $value;
69 12 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 2 10 12
70  
71 12 ▶ CORE::last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 2 10 12
72 }
73  
74 6 ▶ return $found ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 2 4 6
75 }
76  
77 2 ▶sub call {
Subroutine call: called CC=1 SCAR=0.0
Pod documented
78 2 my ($self, $mapper, $method, @args) = @_;
79  
80 2 require Venus::What;
81  
82 8 ▶ return $self->$mapper(sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
83 8 my ($key, $val) = @_;
84  
85 8 my $what = Venus::What->new($val)->deduce;
86  
87 8 local $_ = $what;
88  
89 8 $key, $what->$method(@args)
90 2 });
91 }
92  
93 5 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
94 5 my ($self) = @_;
95  
96 5 my $data = $self->get;
97  
98 5 return scalar(CORE::keys(%$data));
99 }
100  
101 1 ▶sub default {
Subroutine default: called CC=1 SCAR=0.0
Pod documented
102 1 return {};
103 }
104  
105 1 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
106 1 my ($self, $key) = @_;
107  
108 1 my $data = $self->get;
109  
110 1 return CORE::delete($data->{$key});
111 }
112  
113 2 ▶sub each {
Subroutine each: called CC=4 SCAR=14.0
Pod documented
114 2 my ($self, $code) = @_;
115  
116 2 my $data = $self->get;
117  
118 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
119  
120 2 my $results = [];
121  
122 2 for my $index (CORE::sort(CORE::keys(%$data))) {
123 8 my $value = $data->{$index};
124  
125 8 local $_ = $value;
126 8 CORE::push(@$results, $code->($index, $value));
127 }
128  
129 2 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
130 }
131  
132 1 ▶sub empty {
Subroutine empty: called CC=1 SCAR=0.0
Pod documented
133 1 my ($self) = @_;
134  
135 1 my $data = $self->get;
136  
137 1 CORE::delete(@$data{CORE::keys(%$data)});
138  
139 1 return $data;
140 }
141  
142 2 ▶sub exists {
Subroutine exists: called CC=2 SCAR=6.9
Pod documented
143 2 my ($self, $key) = @_;
144  
145 2 my $data = $self->get;
146  
147 2 ▶ return CORE::exists($data->{$key}) ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
exists $data->{$key} ? : 1 1 2
148 }
149  
150 238 ▶sub find {
Subroutine find: called CC=6 SCAR=18.1
Pod documented
151 238 my ($self, @args) = @_;
152  
153 238 my $seen = 0;
154 238 my $item = my $data = $self->get;
155  
156 238 ▶ for (my $i = 0; $i < @args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 380 238 618
157 380 ▶ if (ref($item) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item eq 'ARRAY') { } 15 365 380
elsif (ref $item eq 'HASH') { } 364 1 365
158 15 ▶ if ($args[$i] !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args[$i] =~ /^\d+$/u) 0 15 15
159 0 $item = undef;
160 0 $seen = 0;
161 0 CORE::last;
162 }
163 15 $seen = $args[$i] <= $#{$item};
164 15 $item = $item->[$args[$i]];
165 }
166 elsif (ref($item) eq 'HASH') {
167 364 $seen = exists $item->{$args[$i]};
168 364 $item = $item->{$args[$i]};
169 }
170 else {
171 1 $item = undef;
172 1 $seen = 0;
173 }
174 }
175  
176 238 ▶ return wantarray ? ($item, int(!!$seen)) : $item;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 81 157 238
177 }
178  
179 607 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
180 607 my ($self, @args) = @_;
181  
182 607 ▶ return $self->value if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 602 5 607
183  
184 5 my ($index) = @args;
185  
186 5 return $self->value->{$index};
187 }
188  
189 9 ▶sub gets {
Subroutine gets: called CC=2 SCAR=6.9
Pod documented
190 9 my ($self, @args) = @_;
191  
192 9 my $result = $self->puts(map +(undef, $_), @args);
193  
194 9 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 4 9
195 }
196  
197 3 ▶sub grep {
Subroutine grep: called CC=5 SCAR=16.2
Pod documented
198 3 my ($self, $code) = @_;
199  
200 3 my $data = $self->get;
201  
202 3 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 3 3
203  
204 3 my $result = [];
205  
206 3 for my $index (CORE::sort(CORE::keys(%$data))) {
207 12 my $value = $data->{$index};
208  
209 12 local $_ = $value;
210 12 ▶ CORE::push(@$result, $index, $value) if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 8 4 12
211 }
212  
213 3 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
214 }
215  
216 2 ▶sub iterator {
Subroutine iterator: called CC=1 SCAR=0.0
Pod documented
217 2 my ($self) = @_;
218  
219 2 my $data = $self->get;
220 2 my @keys = CORE::sort(CORE::keys(%{$data}));
221  
222 2 my $i = 0;
223 2 my $j = 0;
224  
225 10 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
226 10 ▶ return undef if $i > $#keys;
Branch: 1 branch
BranchTrueFalseTotal
if $i > $#keys 2 8 10
227 8 ▶ return wantarray ? ($keys[$j++], $data->{$keys[$i++]}) : $data->{$keys[$i++]};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 4 8
228 }
229 2 }
230  
231 2 ▶sub keys {
Subroutine keys: called CC=1 SCAR=0.0
Pod documented
232 2 my ($self) = @_;
233  
234 2 my $data = $self->get;
235  
236 2 return [CORE::sort(CORE::keys(%$data))];
237 }
238  
239 1 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod documented
240 1 my ($self) = @_;
241  
242 1 return $self->count;
243 }
244  
245 2 ▶sub list {
Subroutine list: called CC=2 SCAR=6.9
Pod documented
246 2 my ($self) = @_;
247  
248 2 ▶ return wantarray ? (%{$self->value}) : scalar(CORE::keys(%{$self->value}));
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
249 }
250  
251 3 ▶sub map {
Subroutine map: called CC=4 SCAR=14.0
Pod documented
252 3 my ($self, $code) = @_;
253  
254 3 my $data = $self->get;
255  
256 3 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 3 3
257  
258 3 my $result = [];
259  
260 3 for my $index (CORE::sort(CORE::keys(%$data))) {
261 12 my $value = $data->{$index};
262  
263 12 local $_ = $value;
264 12 CORE::push(@$result, ($code->($index, $value)));
265 }
266  
267 3 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
268 }
269  
270 42 ▶sub merge {
Subroutine merge: called CC=1 SCAR=0.0
Pod documented
271 42 my ($self, @rvalues) = @_;
272  
273 42 require Venus;
274  
275 42 my $lvalue = {%{$self->get}};
276  
277 42 return Venus::merge_swap($lvalue, @rvalues);
278 }
279  
280 2 ▶sub none {
Subroutine none: called CC=6 SCAR=18.6
Pod documented
281 2 my ($self, $code) = @_;
282  
283 2 my $data = $self->get;
284  
285 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
286  
287 2 my $found = 0;
288  
289 2 for my $index (CORE::sort(CORE::keys(%$data))) {
290 8 my $value = $data->{$index};
291  
292 8 local $_ = $value;
293 8 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 0 8 8
294  
295 8 ▶ CORE::last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 8 8
296 }
297  
298 2 ▶ return $found ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 0 2 2
299 }
300  
301 2 ▶sub one {
Subroutine one: called CC=6 SCAR=18.2
Pod documented
302 2 my ($self, $code) = @_;
303  
304 2 my $data = $self->get;
305  
306 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
307  
308 2 my $found = 0;
309  
310 2 for my $index (CORE::sort(CORE::keys(%$data))) {
311 8 my $value = $data->{$index};
312  
313 8 local $_ = $value;
314 8 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 2 6 8
315  
316 8 ▶ CORE::last if $found > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $found > 1 0 8 8
317 }
318  
319 2 ▶ return $found == 1 ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$found == 1 ? : 2 0 2
320 }
321  
322 11 ▶sub pairs {
Subroutine pairs: called CC=2 SCAR=6.9
Pod documented
323 11 my ($self) = @_;
324  
325 11 my $data = $self->get;
326  
327 11 my $result = [CORE::map { [$_, $data->{$_}] } CORE::sort(CORE::keys(%$data))];
328  
329 11 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 9 11
330 }
331  
332 234 ▶sub path {
Subroutine path: called CC=2 SCAR=6.9
Pod documented
333 234 my ($self, $path) = @_;
334  
335 234 my @path = CORE::grep(/./, CORE::split(/\W/, $path));
336  
337 234 ▶ return wantarray ? ($self->find(@path)) : $self->find(@path);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 80 154 234
338 }
339  
340 15 ▶sub puts {
Subroutine puts: called CC=9 SCAR=22.2
Pod documented
341 15 my ($self, @args) = @_;
342  
343 15 my $result = [];
344  
345 15 require Venus::Array;
346  
347 15 ▶ for (my $i = 0; $i < @args; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 31 15 46
348 31 my ($into, $path) = @args[$i, $i+1];
349  
350 31 ▶ next if !defined $path || $path eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or $path eq "" 0 31 31
Condition33%1/3
not defined $path or $path eq ""
l!l&&r!l&&!r
0031
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
351  
352 31 my $value;
353 my @range;
354  
355 31 ▶ ($path, @range) = @{$path} if ref $path eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $path eq "ARRAY" 1 30 31
356  
357 31 $value = $self->path($path);
358  
359 31 ▶ if (ref $value eq 'ARRAY' && @range) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY" and @range) 1 30 31
Condition100%3/3
ref $value eq "ARRAY" and @range
!ll&&!rl&&r
2461
MC/DC100%2/2
ref $value eq "ARRAY" and @range
ref $value eq "ARRAY" @range
Truth table100%3/3
A and B
A= ref $value eq "ARRAY"B= @range
ABresult
0X0
100
111
360 1 $value = Venus::Array->new($value)->range(@range);
361 }
362  
363 31 ▶ if (ref $into eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $into eq "SCALAR") 14 17 31
364 14 $$into = $value;
365 }
366  
367 31 CORE::push @{$result}, $value;
368 }
369  
370 0 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 15 15
371 }
372  
373 1 ▶sub random {
Subroutine random: called CC=1 SCAR=0.0
Pod documented
374 1 my ($self) = @_;
375  
376 1 my $data = $self->get;
377 1 my $keys = [CORE::keys(%$data)];
378  
379 1 return $data->{@$keys[rand($#{$keys}+1)]};
380 }
381  
382 1 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
383 1 my ($self) = @_;
384  
385 1 my $data = $self->get;
386  
387 1 @$data{CORE::keys(%$data)} = ();
388  
389 1 return $data;
390 }
391  
392 1 ▶sub reverse {
Subroutine reverse: called CC=2 SCAR=6.9
Pod documented
393 1 my ($self) = @_;
394  
395 1 my $data = $self->get;
396  
397 1 my $result = {};
398  
399 1 for (CORE::grep(CORE::defined($data->{$_}), CORE::sort(CORE::keys(%$data)))) {
400 4 $result->{$_} = $data->{$_};
401 }
402  
403 1 return {CORE::reverse(%$result)};
404 }
405  
406 1 ▶sub rsort {
Subroutine rsort: called CC=1 SCAR=0.0
Pod documented
407 1 my ($self) = @_;
408  
409 1 my $pairs = $self->pairs;
410  
411 1 return [CORE::sort { $b cmp $a } CORE::map $$_[1], @{$pairs}];
412 }
413  
414 82 ▶sub set {
Subroutine set: called CC=5 SCAR=17.8
Pod documented
415 82 my ($self, @args) = @_;
416  
417 82 ▶ return $self->value if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 82 82
418  
419 82 ▶ return $self->value(@args) if @args == 1 && ref $args[0] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 and ref $args[0] eq "HASH" 0 82 82
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
8200
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
420  
421 82 my ($index, $value) = @args;
422  
423 82 ▶ return if not defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 82 82
424  
425 82 return $self->value->{$index} = $value;
426 }
427  
428 60 ▶sub sets {
Subroutine sets: called CC=9 SCAR=22.5
Pod documented
429 60 my ($self, @args) = @_;
430  
431 60 my $result = [];
432  
433 60 ▶ for (my $i = 0; $i < @args; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 76 60 136
434 76 my ($path, $data) = @args[$i, $i+1];
435  
436 76 CORE::push @{$result}, $data;
437  
438 76 ▶ next if !defined $path || $path eq "";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or $path eq "" 0 76 76
Condition33%1/3
not defined $path or $path eq ""
l!l&&r!l&&!r
0076
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
439  
440 76 ▶ if (my ($first, $last) = $path =~ /^(.*)\.(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $path =~ /^(.*)\.(\w+)$/u) { } 24 52 76
441 24 ▶ my $value = $self->path($first) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $value = $self->path($first) or next 22 2 24
442  
443 22 ▶ if (ref $value eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 22 22
elsif (ref $value eq 'HASH') { } 22 0 22
444 0 $value->[$last] = $data;
445 }
446 elsif (ref $value eq 'HASH') {
447 22 $value->{$last} = $data;
448 }
449 }
450 else {
451 52 $self->set($path, $data);
452 }
453 }
454  
455 60 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 59 60
456 }
457  
458 1 ▶sub shuffle {
Subroutine shuffle: called CC=2 SCAR=6.9
Pod documented
459 1 my ($self) = @_;
460  
461 1 my $pairs = $self->pairs;
462  
463 1 my $result = [CORE::map $$_[1], @{$pairs}];
464  
465 1 for my $index (0..$#$result) {
466 10 my $other = int(rand(@$result));
467 10 my $stash = $result->[$index];
468 10 $result->[$index] = $result->[$other];
469 10 $result->[$other] = $stash;
470 }
471  
472 1 return $result;
473 }
474  
475 1 ▶sub slice {
Subroutine slice: called CC=1 SCAR=0.0
Pod documented
476 1 my ($self, @args) = @_;
477  
478 1 my $data = $self->get;
479  
480 1 return [@{$data}{@args}];
481 }
482  
483 1 ▶sub sort {
Subroutine sort: called CC=1 SCAR=0.0
Pod documented
484 1 my ($self) = @_;
485  
486 1 my $pairs = $self->pairs;
487  
488 1 return [CORE::sort { $a cmp $b } CORE::map $$_[1], @{$pairs}];
489 }
490  
491 1 ▶sub values {
Subroutine values: called CC=1 SCAR=0.0
Pod documented
492 1 my ($self) = @_;
493  
494 1 my $data = $self->get;
495  
496 1 return [CORE::values(%$data)];
497 }
498  
499 25 1;
500  
501  
502  
503 =head1 NAME
504  
505 Venus::Hash - Hash Class
506  
507 =cut
508  
509 =head1 ABSTRACT
510  
511 Hash Class for Perl 5
512  
513 =cut
514  
515 =head1 SYNOPSIS
516  
517 package main;
518  
519 use Venus::Hash;
520  
521 my $hash = Venus::Hash->new({1..8});
522  
523 # $hash->random;
524  
525 =cut
526  
527 =head1 DESCRIPTION
528  
529 This package provides methods for manipulating hash data.
530  
531 =cut
532  
533 =head1 INHERITS
534  
535 This package inherits behaviors from:
536  
537 L<Venus::Kind::Value>
538  
539 =cut
540  
541 =head1 INTEGRATES
542  
543 This package integrates behaviors from:
544  
545 L<Venus::Role::Mappable>
546  
547 =cut
548  
549 =head1 METHODS
550  
551 This package provides the following methods:
552  
553 =cut
554  
555 =head2 all
556  
557 all(coderef $code) (boolean)
558  
559 The all method returns true if the callback returns true for all of the
560 elements.
561  
562 I<Since C<0.01>>
563  
564 =over 4
565  
566 =item all example 1
567  
568 # given: synopsis;
569  
570 my $all = $hash->all(sub {
571 $_ > 1
572 });
573  
574 # 1
575  
576 =back
577  
578 =over 4
579  
580 =item all example 2
581  
582 # given: synopsis;
583  
584 my $all = $hash->all(sub {
585 my ($key, $value) = @_;
586  
587 $value > 1
588 });
589  
590 # 1
591  
592 =back
593  
594 =cut
595  
596 =head2 any
597  
598 any(coderef $code) (boolean)
599  
600 The any method returns true if the callback returns true for any of the
601 elements.
602  
603 I<Since C<0.01>>
604  
605 =over 4
606  
607 =item any example 1
608  
609 # given: synopsis;
610  
611 my $any = $hash->any(sub {
612 $_ < 1
613 });
614  
615 # 0
616  
617 =back
618  
619 =over 4
620  
621 =item any example 2
622  
623 # given: synopsis;
624  
625 my $any = $hash->any(sub {
626 my ($key, $value) = @_;
627  
628 $value < 1
629 });
630  
631 # 0
632  
633 =back
634  
635 =cut
636  
637 =head2 call
638  
639 call(string $iterable, string $method) (any)
640  
641 The call method executes the given method (named using the first argument)
642 which performs an iteration (i.e. takes a callback) and calls the method (named
643 using the second argument) on the object (or value) and returns the result of
644 the iterable method.
645  
646 I<Since C<1.02>>
647  
648 =over 4
649  
650 =item call example 1
651  
652 # given: synopsis
653  
654 package main;
655  
656 my $call = $hash->call('map', 'incr');
657  
658 # ['1', 3, '3', 5, '5', 7, '7', 9]
659  
660 =back
661  
662 =over 4
663  
664 =item call example 2
665  
666 # given: synopsis
667  
668 package main;
669  
670 my $call = $hash->call('grep', 'gt', 4);
671  
672 # [5..8]
673  
674 =back
675  
676 =cut
677  
678 =head2 cast
679  
680 cast(string $kind) (object | undef)
681  
682 The cast method converts L<"value"|Venus::Kind::Value> objects between
683 different I<"value"> object types, based on the name of the type provided. This
684 method will return C<undef> if the invocant is not a L<Venus::Kind::Value>.
685  
686 I<Since C<0.08>>
687  
688 =over 4
689  
690 =item cast example 1
691  
692 package main;
693  
694 use Venus::Hash;
695  
696 my $hash = Venus::Hash->new;
697  
698 my $cast = $hash->cast('array');
699  
700 # bless({ value => [{}] }, "Venus::Array")
701  
702 =back
703  
704 =over 4
705  
706 =item cast example 2
707  
708 package main;
709  
710 use Venus::Hash;
711  
712 my $hash = Venus::Hash->new;
713  
714 my $cast = $hash->cast('boolean');
715  
716 # bless({ value => 1 }, "Venus::Boolean")
717  
718 =back
719  
720 =over 4
721  
722 =item cast example 3
723  
724 package main;
725  
726 use Venus::Hash;
727  
728 my $hash = Venus::Hash->new;
729  
730 my $cast = $hash->cast('code');
731  
732 # bless({ value => sub { ... } }, "Venus::Code")
733  
734 =back
735  
736 =over 4
737  
738 =item cast example 4
739  
740 package main;
741  
742 use Venus::Hash;
743  
744 my $hash = Venus::Hash->new;
745  
746 my $cast = $hash->cast('float');
747  
748 # bless({ value => "1.0" }, "Venus::Float")
749  
750 =back
751  
752 =over 4
753  
754 =item cast example 5
755  
756 package main;
757  
758 use Venus::Hash;
759  
760 my $hash = Venus::Hash->new;
761  
762 my $cast = $hash->cast('hash');
763  
764 # bless({ value => {} }, "Venus::Hash")
765  
766 =back
767  
768 =over 4
769  
770 =item cast example 6
771  
772 package main;
773  
774 use Venus::Hash;
775  
776 my $hash = Venus::Hash->new;
777  
778 my $cast = $hash->cast('number');
779  
780 # bless({ value => 2 }, "Venus::Number")
781  
782 =back
783  
784 =over 4
785  
786 =item cast example 7
787  
788 package main;
789  
790 use Venus::Hash;
791  
792 my $hash = Venus::Hash->new;
793  
794 my $cast = $hash->cast('regexp');
795  
796 # bless({ value => qr/(?^u:\{\})/ }, "Venus::Regexp")
797  
798 =back
799  
800 =over 4
801  
802 =item cast example 8
803  
804 package main;
805  
806 use Venus::Hash;
807  
808 my $hash = Venus::Hash->new;
809  
810 my $cast = $hash->cast('scalar');
811  
812 # bless({ value => \{} }, "Venus::Scalar")
813  
814 =back
815  
816 =over 4
817  
818 =item cast example 9
819  
820 package main;
821  
822 use Venus::Hash;
823  
824 my $hash = Venus::Hash->new;
825  
826 my $cast = $hash->cast('string');
827  
828 # bless({ value => "{}" }, "Venus::String")
829  
830 =back
831  
832 =over 4
833  
834 =item cast example 10
835  
836 package main;
837  
838 use Venus::Hash;
839  
840 my $hash = Venus::Hash->new;
841  
842 my $cast = $hash->cast('undef');
843  
844 # bless({ value => undef }, "Venus::Undef")
845  
846 =back
847  
848 =cut
849  
850 =head2 count
851  
852 count() (number)
853  
854 The count method returns the total number of keys defined.
855  
856 I<Since C<0.01>>
857  
858 =over 4
859  
860 =item count example 1
861  
862 # given: synopsis;
863  
864 my $count = $hash->count;
865  
866 # 4
867  
868 =back
869  
870 =cut
871  
872 =head2 default
873  
874 default() (hashref)
875  
876 The default method returns the default value, i.e. C<{}>.
877  
878 I<Since C<0.01>>
879  
880 =over 4
881  
882 =item default example 1
883  
884 # given: synopsis;
885  
886 my $default = $hash->default;
887  
888 # {}
889  
890 =back
891  
892 =cut
893  
894 =head2 delete
895  
896 delete(string $key) (any)
897  
898 The delete method returns the value matching the key specified in the argument
899 and returns the value.
900  
901 I<Since C<0.01>>
902  
903 =over 4
904  
905 =item delete example 1
906  
907 # given: synopsis;
908  
909 my $delete = $hash->delete(1);
910  
911 # 2
912  
913 =back
914  
915 =cut
916  
917 =head2 each
918  
919 each(coderef $code) (arrayref)
920  
921 The each method executes callback for each element in the hash passing the
922 routine the key and value at the current position in the loop. This method can
923 return a list of values in list-context.
924  
925 I<Since C<0.01>>
926  
927 =over 4
928  
929 =item each example 1
930  
931 # given: synopsis;
932  
933 my $each = $hash->each(sub {
934 [$_]
935 });
936  
937 # [[2], [4], [6], [8]]
938  
939 =back
940  
941 =over 4
942  
943 =item each example 2
944  
945 # given: synopsis;
946  
947 my $each = $hash->each(sub {
948 my ($key, $value) = @_;
949  
950 [$key, $value]
951 });
952  
953 # [[1, 2], [3, 4], [5, 6], [7, 8]]
954  
955 =back
956  
957 =cut
958  
959 =head2 empty
960  
961 empty() (hashref)
962  
963 The empty method drops all elements from the hash.
964  
965 I<Since C<0.01>>
966  
967 =over 4
968  
969 =item empty example 1
970  
971 # given: synopsis;
972  
973 my $empty = $hash->empty;
974  
975 # {}
976  
977 =back
978  
979 =cut
980  
981 =head2 eq
982  
983 eq(any $arg) (boolean)
984  
985 The eq method performs an I<"equals"> operation using the argument provided.
986  
987 I<Since C<0.08>>
988  
989 =over 4
990  
991 =item eq example 1
992  
993 package main;
994  
995 use Venus::Array;
996 use Venus::Hash;
997  
998 my $lvalue = Venus::Hash->new;
999 my $rvalue = Venus::Array->new;
1000  
1001 my $result = $lvalue->eq($rvalue);
1002  
1003 # 0
1004  
1005 =back
1006  
1007 =over 4
1008  
1009 =item eq example 2
1010  
1011 package main;
1012  
1013 use Venus::Code;
1014 use Venus::Hash;
1015  
1016 my $lvalue = Venus::Hash->new;
1017 my $rvalue = Venus::Code->new;
1018  
1019 my $result = $lvalue->eq($rvalue);
1020  
1021 # 0
1022  
1023 =back
1024  
1025 =over 4
1026  
1027 =item eq example 3
1028  
1029 package main;
1030  
1031 use Venus::Float;
1032 use Venus::Hash;
1033  
1034 my $lvalue = Venus::Hash->new;
1035 my $rvalue = Venus::Float->new;
1036  
1037 my $result = $lvalue->eq($rvalue);
1038  
1039 # 0
1040  
1041 =back
1042  
1043 =over 4
1044  
1045 =item eq example 4
1046  
1047 package main;
1048  
1049 use Venus::Hash;
1050  
1051 my $lvalue = Venus::Hash->new;
1052 my $rvalue = Venus::Hash->new;
1053  
1054 my $result = $lvalue->eq($rvalue);
1055  
1056 # 1
1057  
1058 =back
1059  
1060 =over 4
1061  
1062 =item eq example 5
1063  
1064 package main;
1065  
1066 use Venus::Hash;
1067 use Venus::Number;
1068  
1069 my $lvalue = Venus::Hash->new;
1070 my $rvalue = Venus::Number->new;
1071  
1072 my $result = $lvalue->eq($rvalue);
1073  
1074 # 0
1075  
1076 =back
1077  
1078 =over 4
1079  
1080 =item eq example 6
1081  
1082 package main;
1083  
1084 use Venus::Hash;
1085 use Venus::Regexp;
1086  
1087 my $lvalue = Venus::Hash->new;
1088 my $rvalue = Venus::Regexp->new;
1089  
1090 my $result = $lvalue->eq($rvalue);
1091  
1092 # 0
1093  
1094 =back
1095  
1096 =over 4
1097  
1098 =item eq example 7
1099  
1100 package main;
1101  
1102 use Venus::Hash;
1103 use Venus::Scalar;
1104  
1105 my $lvalue = Venus::Hash->new;
1106 my $rvalue = Venus::Scalar->new;
1107  
1108 my $result = $lvalue->eq($rvalue);
1109  
1110 # 0
1111  
1112 =back
1113  
1114 =over 4
1115  
1116 =item eq example 8
1117  
1118 package main;
1119  
1120 use Venus::Hash;
1121 use Venus::String;
1122  
1123 my $lvalue = Venus::Hash->new;
1124 my $rvalue = Venus::String->new;
1125  
1126 my $result = $lvalue->eq($rvalue);
1127  
1128 # 0
1129  
1130 =back
1131  
1132 =over 4
1133  
1134 =item eq example 9
1135  
1136 package main;
1137  
1138 use Venus::Hash;
1139 use Venus::Undef;
1140  
1141 my $lvalue = Venus::Hash->new;
1142 my $rvalue = Venus::Undef->new;
1143  
1144 my $result = $lvalue->eq($rvalue);
1145  
1146 # 0
1147  
1148 =back
1149  
1150 =cut
1151  
1152 =head2 exists
1153  
1154 exists(string $key) (boolean)
1155  
1156 The exists method returns true if the value matching the key specified in the
1157 argument exists, otherwise returns false.
1158  
1159 I<Since C<0.01>>
1160  
1161 =over 4
1162  
1163 =item exists example 1
1164  
1165 # given: synopsis;
1166  
1167 my $exists = $hash->exists(1);
1168  
1169 # 1
1170  
1171 =back
1172  
1173 =over 4
1174  
1175 =item exists example 2
1176  
1177 # given: synopsis;
1178  
1179 my $exists = $hash->exists(0);
1180  
1181 # 0
1182  
1183 =back
1184  
1185 =cut
1186  
1187 =head2 find
1188  
1189 find(string @data) (any)
1190  
1191 The find method traverses the data structure using the keys and indices
1192 provided, returning the value found or undef. In list-context, this method
1193 returns a tuple, i.e. the value found and boolean representing whether the
1194 match was successful.
1195  
1196 I<Since C<0.01>>
1197  
1198 =over 4
1199  
1200 =item find example 1
1201  
1202 package main;
1203  
1204 use Venus::Hash;
1205  
1206 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
1207  
1208 my $find = $hash->find('foo', 'bar');
1209  
1210 # "baz"
1211  
1212 =back
1213  
1214 =over 4
1215  
1216 =item find example 2
1217  
1218 package main;
1219  
1220 use Venus::Hash;
1221  
1222 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
1223  
1224 my $find = $hash->find('bar', 0);
1225  
1226 # "baz"
1227  
1228 =back
1229  
1230 =over 4
1231  
1232 =item find example 3
1233  
1234 package main;
1235  
1236 use Venus::Hash;
1237  
1238 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
1239  
1240 my $find = $hash->find('bar');
1241  
1242 # ["baz"]
1243  
1244 =back
1245  
1246 =over 4
1247  
1248 =item find example 4
1249  
1250 package main;
1251  
1252 use Venus::Hash;
1253  
1254 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
1255  
1256 my ($find, $exists) = $hash->find('baz');
1257  
1258 # (undef, 0)
1259  
1260 =back
1261  
1262 =cut
1263  
1264 =head2 ge
1265  
1266 ge(any $arg) (boolean)
1267  
1268 The ge method performs a I<"greater-than-or-equal-to"> operation using the
1269 argument provided.
1270  
1271 I<Since C<0.08>>
1272  
1273 =over 4
1274  
1275 =item ge example 1
1276  
1277 package main;
1278  
1279 use Venus::Array;
1280 use Venus::Hash;
1281  
1282 my $lvalue = Venus::Hash->new;
1283 my $rvalue = Venus::Array->new;
1284  
1285 my $result = $lvalue->ge($rvalue);
1286  
1287 # 0
1288  
1289 =back
1290  
1291 =over 4
1292  
1293 =item ge example 2
1294  
1295 package main;
1296  
1297 use Venus::Code;
1298 use Venus::Hash;
1299  
1300 my $lvalue = Venus::Hash->new;
1301 my $rvalue = Venus::Code->new;
1302  
1303 my $result = $lvalue->ge($rvalue);
1304  
1305 # 0
1306  
1307 =back
1308  
1309 =over 4
1310  
1311 =item ge example 3
1312  
1313 package main;
1314  
1315 use Venus::Float;
1316 use Venus::Hash;
1317  
1318 my $lvalue = Venus::Hash->new;
1319 my $rvalue = Venus::Float->new;
1320  
1321 my $result = $lvalue->ge($rvalue);
1322  
1323 # 1
1324  
1325 =back
1326  
1327 =over 4
1328  
1329 =item ge example 4
1330  
1331 package main;
1332  
1333 use Venus::Hash;
1334  
1335 my $lvalue = Venus::Hash->new;
1336 my $rvalue = Venus::Hash->new;
1337  
1338 my $result = $lvalue->ge($rvalue);
1339  
1340 # 1
1341  
1342 =back
1343  
1344 =over 4
1345  
1346 =item ge example 5
1347  
1348 package main;
1349  
1350 use Venus::Hash;
1351 use Venus::Number;
1352  
1353 my $lvalue = Venus::Hash->new;
1354 my $rvalue = Venus::Number->new;
1355  
1356 my $result = $lvalue->ge($rvalue);
1357  
1358 # 1
1359  
1360 =back
1361  
1362 =over 4
1363  
1364 =item ge example 6
1365  
1366 package main;
1367  
1368 use Venus::Hash;
1369 use Venus::Regexp;
1370  
1371 my $lvalue = Venus::Hash->new;
1372 my $rvalue = Venus::Regexp->new;
1373  
1374 my $result = $lvalue->ge($rvalue);
1375  
1376 # 0
1377  
1378 =back
1379  
1380 =over 4
1381  
1382 =item ge example 7
1383  
1384 package main;
1385  
1386 use Venus::Hash;
1387 use Venus::Scalar;
1388  
1389 my $lvalue = Venus::Hash->new;
1390 my $rvalue = Venus::Scalar->new;
1391  
1392 my $result = $lvalue->ge($rvalue);
1393  
1394 # 0
1395  
1396 =back
1397  
1398 =over 4
1399  
1400 =item ge example 8
1401  
1402 package main;
1403  
1404 use Venus::Hash;
1405 use Venus::String;
1406  
1407 my $lvalue = Venus::Hash->new;
1408 my $rvalue = Venus::String->new;
1409  
1410 my $result = $lvalue->ge($rvalue);
1411  
1412 # 1
1413  
1414 =back
1415  
1416 =over 4
1417  
1418 =item ge example 9
1419  
1420 package main;
1421  
1422 use Venus::Hash;
1423 use Venus::Undef;
1424  
1425 my $lvalue = Venus::Hash->new;
1426 my $rvalue = Venus::Undef->new;
1427  
1428 my $result = $lvalue->ge($rvalue);
1429  
1430 # 1
1431  
1432 =back
1433  
1434 =cut
1435  
1436 =head2 gele
1437  
1438 gele(any $arg1, any $arg2) (boolean)
1439  
1440 The gele method performs a I<"greater-than-or-equal-to"> operation on the 1st
1441 argument, and I<"lesser-than-or-equal-to"> operation on the 2nd argument.
1442  
1443 I<Since C<0.08>>
1444  
1445 =over 4
1446  
1447 =item gele example 1
1448  
1449 package main;
1450  
1451 use Venus::Array;
1452 use Venus::Hash;
1453  
1454 my $lvalue = Venus::Hash->new;
1455 my $rvalue = Venus::Array->new;
1456  
1457 my $result = $lvalue->gele($rvalue);
1458  
1459 # 0
1460  
1461 =back
1462  
1463 =over 4
1464  
1465 =item gele example 2
1466  
1467 package main;
1468  
1469 use Venus::Code;
1470 use Venus::Hash;
1471  
1472 my $lvalue = Venus::Hash->new;
1473 my $rvalue = Venus::Code->new;
1474  
1475 my $result = $lvalue->gele($rvalue);
1476  
1477 # 0
1478  
1479 =back
1480  
1481 =over 4
1482  
1483 =item gele example 3
1484  
1485 package main;
1486  
1487 use Venus::Float;
1488 use Venus::Hash;
1489  
1490 my $lvalue = Venus::Hash->new;
1491 my $rvalue = Venus::Float->new;
1492  
1493 my $result = $lvalue->gele($rvalue);
1494  
1495 # 0
1496  
1497 =back
1498  
1499 =over 4
1500  
1501 =item gele example 4
1502  
1503 package main;
1504  
1505 use Venus::Hash;
1506  
1507 my $lvalue = Venus::Hash->new;
1508 my $rvalue = Venus::Hash->new;
1509  
1510 my $result = $lvalue->gele($rvalue);
1511  
1512 # 0
1513  
1514 =back
1515  
1516 =over 4
1517  
1518 =item gele example 5
1519  
1520 package main;
1521  
1522 use Venus::Hash;
1523 use Venus::Number;
1524  
1525 my $lvalue = Venus::Hash->new;
1526 my $rvalue = Venus::Number->new;
1527  
1528 my $result = $lvalue->gele($rvalue);
1529  
1530 # 0
1531  
1532 =back
1533  
1534 =over 4
1535  
1536 =item gele example 6
1537  
1538 package main;
1539  
1540 use Venus::Hash;
1541 use Venus::Regexp;
1542  
1543 my $lvalue = Venus::Hash->new;
1544 my $rvalue = Venus::Regexp->new;
1545  
1546 my $result = $lvalue->gele($rvalue);
1547  
1548 # 0
1549  
1550 =back
1551  
1552 =over 4
1553  
1554 =item gele example 7
1555  
1556 package main;
1557  
1558 use Venus::Hash;
1559 use Venus::Scalar;
1560  
1561 my $lvalue = Venus::Hash->new;
1562 my $rvalue = Venus::Scalar->new;
1563  
1564 my $result = $lvalue->gele($rvalue);
1565  
1566 # 0
1567  
1568 =back
1569  
1570 =over 4
1571  
1572 =item gele example 8
1573  
1574 package main;
1575  
1576 use Venus::Hash;
1577 use Venus::String;
1578  
1579 my $lvalue = Venus::Hash->new;
1580 my $rvalue = Venus::String->new;
1581  
1582 my $result = $lvalue->gele($rvalue);
1583  
1584 # 0
1585  
1586 =back
1587  
1588 =over 4
1589  
1590 =item gele example 9
1591  
1592 package main;
1593  
1594 use Venus::Hash;
1595 use Venus::Undef;
1596  
1597 my $lvalue = Venus::Hash->new;
1598 my $rvalue = Venus::Undef->new;
1599  
1600 my $result = $lvalue->gele($rvalue);
1601  
1602 # 0
1603  
1604 =back
1605  
1606 =cut
1607  
1608 =head2 gets
1609  
1610 gets(string @args) (arrayref)
1611  
1612 The gets method select values from within the underlying data structure using
1613 L<Venus::Hash/path>, where each argument is a selector, returns all the values
1614 selected. Returns a list in list context.
1615  
1616 I<Since C<4.15>>
1617  
1618 =over 4
1619  
1620 =item gets example 1
1621  
1622 package main;
1623  
1624 use Venus::Hash;
1625  
1626 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
1627  
1628 my $gets = $hash->gets('bar', 'foo.bar');
1629  
1630 # [['baz'], 'baz']
1631  
1632 =back
1633  
1634 =over 4
1635  
1636 =item gets example 2
1637  
1638 package main;
1639  
1640 use Venus::Hash;
1641  
1642 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
1643  
1644 my ($bar, $foo_bar) = $hash->gets('bar', 'foo.bar');
1645  
1646 # (['baz'], 'baz')
1647  
1648 =back
1649  
1650 =over 4
1651  
1652 =item gets example 3
1653  
1654 package main;
1655  
1656 use Venus::Hash;
1657  
1658 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
1659  
1660 my $gets = $hash->gets('bar', 'foo.bar', 'foo.bar.baz');
1661  
1662 # [['baz'], 'baz', undef]
1663  
1664 =back
1665  
1666 =cut
1667  
1668 =head2 grep
1669  
1670 grep(coderef $code) (arrayref)
1671  
1672 The grep method executes callback for each key/value pair in the hash passing
1673 the routine the key and value at the current position in the loop and returning
1674 a new hash reference containing the elements for which the argument evaluated
1675 true. This method can return a list of values in list-context.
1676  
1677 I<Since C<0.01>>
1678  
1679 =over 4
1680  
1681 =item grep example 1
1682  
1683 # given: synopsis;
1684  
1685 my $grep = $hash->grep(sub {
1686 $_ >= 3
1687 });
1688  
1689 # [3..8]
1690  
1691 =back
1692  
1693 =over 4
1694  
1695 =item grep example 2
1696  
1697 # given: synopsis;
1698  
1699 my $grep = $hash->grep(sub {
1700 my ($key, $value) = @_;
1701  
1702 $value >= 3
1703 });
1704  
1705 # [3..8]
1706  
1707 =back
1708  
1709 =cut
1710  
1711 =head2 gt
1712  
1713 gt(any $arg) (boolean)
1714  
1715 The gt method performs a I<"greater-than"> operation using the argument provided.
1716  
1717 I<Since C<0.08>>
1718  
1719 =over 4
1720  
1721 =item gt example 1
1722  
1723 package main;
1724  
1725 use Venus::Array;
1726 use Venus::Hash;
1727  
1728 my $lvalue = Venus::Hash->new;
1729 my $rvalue = Venus::Array->new;
1730  
1731 my $result = $lvalue->gt($rvalue);
1732  
1733 # 0
1734  
1735 =back
1736  
1737 =over 4
1738  
1739 =item gt example 2
1740  
1741 package main;
1742  
1743 use Venus::Code;
1744 use Venus::Hash;
1745  
1746 my $lvalue = Venus::Hash->new;
1747 my $rvalue = Venus::Code->new;
1748  
1749 my $result = $lvalue->gt($rvalue);
1750  
1751 # 0
1752  
1753 =back
1754  
1755 =over 4
1756  
1757 =item gt example 3
1758  
1759 package main;
1760  
1761 use Venus::Float;
1762 use Venus::Hash;
1763  
1764 my $lvalue = Venus::Hash->new;
1765 my $rvalue = Venus::Float->new;
1766  
1767 my $result = $lvalue->gt($rvalue);
1768  
1769 # 1
1770  
1771 =back
1772  
1773 =over 4
1774  
1775 =item gt example 4
1776  
1777 package main;
1778  
1779 use Venus::Hash;
1780  
1781 my $lvalue = Venus::Hash->new;
1782 my $rvalue = Venus::Hash->new;
1783  
1784 my $result = $lvalue->gt($rvalue);
1785  
1786 # 0
1787  
1788 =back
1789  
1790 =over 4
1791  
1792 =item gt example 5
1793  
1794 package main;
1795  
1796 use Venus::Hash;
1797 use Venus::Number;
1798  
1799 my $lvalue = Venus::Hash->new;
1800 my $rvalue = Venus::Number->new;
1801  
1802 my $result = $lvalue->gt($rvalue);
1803  
1804 # 1
1805  
1806 =back
1807  
1808 =over 4
1809  
1810 =item gt example 6
1811  
1812 package main;
1813  
1814 use Venus::Hash;
1815 use Venus::Regexp;
1816  
1817 my $lvalue = Venus::Hash->new;
1818 my $rvalue = Venus::Regexp->new;
1819  
1820 my $result = $lvalue->gt($rvalue);
1821  
1822 # 0
1823  
1824 =back
1825  
1826 =over 4
1827  
1828 =item gt example 7
1829  
1830 package main;
1831  
1832 use Venus::Hash;
1833 use Venus::Scalar;
1834  
1835 my $lvalue = Venus::Hash->new;
1836 my $rvalue = Venus::Scalar->new;
1837  
1838 my $result = $lvalue->gt($rvalue);
1839  
1840 # 0
1841  
1842 =back
1843  
1844 =over 4
1845  
1846 =item gt example 8
1847  
1848 package main;
1849  
1850 use Venus::Hash;
1851 use Venus::String;
1852  
1853 my $lvalue = Venus::Hash->new;
1854 my $rvalue = Venus::String->new;
1855  
1856 my $result = $lvalue->gt($rvalue);
1857  
1858 # 1
1859  
1860 =back
1861  
1862 =over 4
1863  
1864 =item gt example 9
1865  
1866 package main;
1867  
1868 use Venus::Hash;
1869 use Venus::Undef;
1870  
1871 my $lvalue = Venus::Hash->new;
1872 my $rvalue = Venus::Undef->new;
1873  
1874 my $result = $lvalue->gt($rvalue);
1875  
1876 # 1
1877  
1878 =back
1879  
1880 =cut
1881  
1882 =head2 gtlt
1883  
1884 gtlt(any $arg1, any $arg2) (boolean)
1885  
1886 The gtlt method performs a I<"greater-than"> operation on the 1st argument, and
1887 I<"lesser-than"> operation on the 2nd argument.
1888  
1889 I<Since C<0.08>>
1890  
1891 =over 4
1892  
1893 =item gtlt example 1
1894  
1895 package main;
1896  
1897 use Venus::Array;
1898 use Venus::Hash;
1899  
1900 my $lvalue = Venus::Hash->new;
1901 my $rvalue = Venus::Array->new;
1902  
1903 my $result = $lvalue->gtlt($rvalue);
1904  
1905 # 0
1906  
1907 =back
1908  
1909 =over 4
1910  
1911 =item gtlt example 2
1912  
1913 package main;
1914  
1915 use Venus::Code;
1916 use Venus::Hash;
1917  
1918 my $lvalue = Venus::Hash->new;
1919 my $rvalue = Venus::Code->new;
1920  
1921 my $result = $lvalue->gtlt($rvalue);
1922  
1923 # 0
1924  
1925 =back
1926  
1927 =over 4
1928  
1929 =item gtlt example 3
1930  
1931 package main;
1932  
1933 use Venus::Float;
1934 use Venus::Hash;
1935  
1936 my $lvalue = Venus::Hash->new;
1937 my $rvalue = Venus::Float->new;
1938  
1939 my $result = $lvalue->gtlt($rvalue);
1940  
1941 # 0
1942  
1943 =back
1944  
1945 =over 4
1946  
1947 =item gtlt example 4
1948  
1949 package main;
1950  
1951 use Venus::Hash;
1952  
1953 my $lvalue = Venus::Hash->new;
1954 my $rvalue = Venus::Hash->new;
1955  
1956 my $result = $lvalue->gtlt($rvalue);
1957  
1958 # 0
1959  
1960 =back
1961  
1962 =over 4
1963  
1964 =item gtlt example 5
1965  
1966 package main;
1967  
1968 use Venus::Hash;
1969 use Venus::Number;
1970  
1971 my $lvalue = Venus::Hash->new;
1972 my $rvalue = Venus::Number->new;
1973  
1974 my $result = $lvalue->gtlt($rvalue);
1975  
1976 # 0
1977  
1978 =back
1979  
1980 =over 4
1981  
1982 =item gtlt example 6
1983  
1984 package main;
1985  
1986 use Venus::Hash;
1987 use Venus::Regexp;
1988  
1989 my $lvalue = Venus::Hash->new;
1990 my $rvalue = Venus::Regexp->new;
1991  
1992 my $result = $lvalue->gtlt($rvalue);
1993  
1994 # 0
1995  
1996 =back
1997  
1998 =over 4
1999  
2000 =item gtlt example 7
2001  
2002 package main;
2003  
2004 use Venus::Hash;
2005 use Venus::Scalar;
2006  
2007 my $lvalue = Venus::Hash->new;
2008 my $rvalue = Venus::Scalar->new;
2009  
2010 my $result = $lvalue->gtlt($rvalue);
2011  
2012 # 0
2013  
2014 =back
2015  
2016 =over 4
2017  
2018 =item gtlt example 8
2019  
2020 package main;
2021  
2022 use Venus::Hash;
2023 use Venus::String;
2024  
2025 my $lvalue = Venus::Hash->new;
2026 my $rvalue = Venus::String->new;
2027  
2028 my $result = $lvalue->gtlt($rvalue);
2029  
2030 # 0
2031  
2032 =back
2033  
2034 =over 4
2035  
2036 =item gtlt example 9
2037  
2038 package main;
2039  
2040 use Venus::Hash;
2041 use Venus::Undef;
2042  
2043 my $lvalue = Venus::Hash->new;
2044 my $rvalue = Venus::Undef->new;
2045  
2046 my $result = $lvalue->gtlt($rvalue);
2047  
2048 # 0
2049  
2050 =back
2051  
2052 =cut
2053  
2054 =head2 iterator
2055  
2056 iterator() (coderef)
2057  
2058 The iterator method returns a code reference which can be used to iterate over
2059 the hash. Each time the iterator is executed it will return the values of the
2060 next element in the hash until all elements have been seen, at which point the
2061 iterator will return an undefined value. This method can return a tuple with
2062 the key and value in list-context.
2063  
2064 I<Since C<0.01>>
2065  
2066 =over 4
2067  
2068 =item iterator example 1
2069  
2070 # given: synopsis;
2071  
2072 my $iterator = $hash->iterator;
2073  
2074 # sub { ... }
2075  
2076 # while (my $value = $iterator->()) {
2077 # say $value; # 1
2078 # }
2079  
2080 =back
2081  
2082 =over 4
2083  
2084 =item iterator example 2
2085  
2086 # given: synopsis;
2087  
2088 my $iterator = $hash->iterator;
2089  
2090 # sub { ... }
2091  
2092 # while (grep defined, my ($key, $value) = $iterator->()) {
2093 # say $value; # 1
2094 # }
2095  
2096 =back
2097  
2098 =cut
2099  
2100 =head2 keys
2101  
2102 keys() (arrayref)
2103  
2104 The keys method returns an array reference consisting of all the keys in the
2105 hash.
2106  
2107 I<Since C<0.01>>
2108  
2109 =over 4
2110  
2111 =item keys example 1
2112  
2113 # given: synopsis;
2114  
2115 my $keys = $hash->keys;
2116  
2117 # [1, 3, 5, 7]
2118  
2119 =back
2120  
2121 =cut
2122  
2123 =head2 le
2124  
2125 le(any $arg) (boolean)
2126  
2127 The le method performs a I<"lesser-than-or-equal-to"> operation using the
2128 argument provided.
2129  
2130 I<Since C<0.08>>
2131  
2132 =over 4
2133  
2134 =item le example 1
2135  
2136 package main;
2137  
2138 use Venus::Array;
2139 use Venus::Hash;
2140  
2141 my $lvalue = Venus::Hash->new;
2142 my $rvalue = Venus::Array->new;
2143  
2144 my $result = $lvalue->le($rvalue);
2145  
2146 # 0
2147  
2148 =back
2149  
2150 =over 4
2151  
2152 =item le example 2
2153  
2154 package main;
2155  
2156 use Venus::Code;
2157 use Venus::Hash;
2158  
2159 my $lvalue = Venus::Hash->new;
2160 my $rvalue = Venus::Code->new;
2161  
2162 my $result = $lvalue->le($rvalue);
2163  
2164 # 1
2165  
2166 =back
2167  
2168 =over 4
2169  
2170 =item le example 3
2171  
2172 package main;
2173  
2174 use Venus::Float;
2175 use Venus::Hash;
2176  
2177 my $lvalue = Venus::Hash->new;
2178 my $rvalue = Venus::Float->new;
2179  
2180 my $result = $lvalue->le($rvalue);
2181  
2182 # 0
2183  
2184 =back
2185  
2186 =over 4
2187  
2188 =item le example 4
2189  
2190 package main;
2191  
2192 use Venus::Hash;
2193  
2194 my $lvalue = Venus::Hash->new;
2195 my $rvalue = Venus::Hash->new;
2196  
2197 my $result = $lvalue->le($rvalue);
2198  
2199 # 1
2200  
2201 =back
2202  
2203 =over 4
2204  
2205 =item le example 5
2206  
2207 package main;
2208  
2209 use Venus::Hash;
2210 use Venus::Number;
2211  
2212 my $lvalue = Venus::Hash->new;
2213 my $rvalue = Venus::Number->new;
2214  
2215 my $result = $lvalue->le($rvalue);
2216  
2217 # 0
2218  
2219 =back
2220  
2221 =over 4
2222  
2223 =item le example 6
2224  
2225 package main;
2226  
2227 use Venus::Hash;
2228 use Venus::Regexp;
2229  
2230 my $lvalue = Venus::Hash->new;
2231 my $rvalue = Venus::Regexp->new;
2232  
2233 my $result = $lvalue->le($rvalue);
2234  
2235 # 1
2236  
2237 =back
2238  
2239 =over 4
2240  
2241 =item le example 7
2242  
2243 package main;
2244  
2245 use Venus::Hash;
2246 use Venus::Scalar;
2247  
2248 my $lvalue = Venus::Hash->new;
2249 my $rvalue = Venus::Scalar->new;
2250  
2251 my $result = $lvalue->le($rvalue);
2252  
2253 # 0
2254  
2255 =back
2256  
2257 =over 4
2258  
2259 =item le example 8
2260  
2261 package main;
2262  
2263 use Venus::Hash;
2264 use Venus::String;
2265  
2266 my $lvalue = Venus::Hash->new;
2267 my $rvalue = Venus::String->new;
2268  
2269 my $result = $lvalue->le($rvalue);
2270  
2271 # 0
2272  
2273 =back
2274  
2275 =over 4
2276  
2277 =item le example 9
2278  
2279 package main;
2280  
2281 use Venus::Hash;
2282 use Venus::Undef;
2283  
2284 my $lvalue = Venus::Hash->new;
2285 my $rvalue = Venus::Undef->new;
2286  
2287 my $result = $lvalue->le($rvalue);
2288  
2289 # 0
2290  
2291 =back
2292  
2293 =cut
2294  
2295 =head2 length
2296  
2297 length() (number)
2298  
2299 The length method returns the total number of keys defined, and is an alias for
2300 the L</count> method.
2301  
2302 I<Since C<0.08>>
2303  
2304 =over 4
2305  
2306 =item length example 1
2307  
2308 # given: synopsis;
2309  
2310 my $length = $hash->length;
2311  
2312 # 4
2313  
2314 =back
2315  
2316 =cut
2317  
2318 =head2 list
2319  
2320 list() (any)
2321  
2322 The list method returns a shallow copy of the underlying hash reference as an
2323 array reference.
2324  
2325 I<Since C<0.01>>
2326  
2327 =over 4
2328  
2329 =item list example 1
2330  
2331 # given: synopsis;
2332  
2333 my $list = $hash->list;
2334  
2335 # 4
2336  
2337 =back
2338  
2339 =over 4
2340  
2341 =item list example 2
2342  
2343 # given: synopsis;
2344  
2345 my @list = $hash->list;
2346  
2347 # (1..8)
2348  
2349 =back
2350  
2351 =cut
2352  
2353 =head2 lt
2354  
2355 lt(any $arg) (boolean)
2356  
2357 The lt method performs a I<"lesser-than"> operation using the argument provided.
2358  
2359 I<Since C<0.08>>
2360  
2361 =over 4
2362  
2363 =item lt example 1
2364  
2365 package main;
2366  
2367 use Venus::Array;
2368 use Venus::Hash;
2369  
2370 my $lvalue = Venus::Hash->new;
2371 my $rvalue = Venus::Array->new;
2372  
2373 my $result = $lvalue->lt($rvalue);
2374  
2375 # 0
2376  
2377 =back
2378  
2379 =over 4
2380  
2381 =item lt example 2
2382  
2383 package main;
2384  
2385 use Venus::Code;
2386 use Venus::Hash;
2387  
2388 my $lvalue = Venus::Hash->new;
2389 my $rvalue = Venus::Code->new;
2390  
2391 my $result = $lvalue->lt($rvalue);
2392  
2393 # 1
2394  
2395 =back
2396  
2397 =over 4
2398  
2399 =item lt example 3
2400  
2401 package main;
2402  
2403 use Venus::Float;
2404 use Venus::Hash;
2405  
2406 my $lvalue = Venus::Hash->new;
2407 my $rvalue = Venus::Float->new;
2408  
2409 my $result = $lvalue->lt($rvalue);
2410  
2411 # 0
2412  
2413 =back
2414  
2415 =over 4
2416  
2417 =item lt example 4
2418  
2419 package main;
2420  
2421 use Venus::Hash;
2422  
2423 my $lvalue = Venus::Hash->new;
2424 my $rvalue = Venus::Hash->new;
2425  
2426 my $result = $lvalue->lt($rvalue);
2427  
2428 # 0
2429  
2430 =back
2431  
2432 =over 4
2433  
2434 =item lt example 5
2435  
2436 package main;
2437  
2438 use Venus::Hash;
2439 use Venus::Number;
2440  
2441 my $lvalue = Venus::Hash->new;
2442 my $rvalue = Venus::Number->new;
2443  
2444 my $result = $lvalue->lt($rvalue);
2445  
2446 # 0
2447  
2448 =back
2449  
2450 =over 4
2451  
2452 =item lt example 6
2453  
2454 package main;
2455  
2456 use Venus::Hash;
2457 use Venus::Regexp;
2458  
2459 my $lvalue = Venus::Hash->new;
2460 my $rvalue = Venus::Regexp->new;
2461  
2462 my $result = $lvalue->lt($rvalue);
2463  
2464 # 1
2465  
2466 =back
2467  
2468 =over 4
2469  
2470 =item lt example 7
2471  
2472 package main;
2473  
2474 use Venus::Hash;
2475 use Venus::Scalar;
2476  
2477 my $lvalue = Venus::Hash->new;
2478 my $rvalue = Venus::Scalar->new;
2479  
2480 my $result = $lvalue->lt($rvalue);
2481  
2482 # 0
2483  
2484 =back
2485  
2486 =over 4
2487  
2488 =item lt example 8
2489  
2490 package main;
2491  
2492 use Venus::Hash;
2493 use Venus::String;
2494  
2495 my $lvalue = Venus::Hash->new;
2496 my $rvalue = Venus::String->new;
2497  
2498 my $result = $lvalue->lt($rvalue);
2499  
2500 # 0
2501  
2502 =back
2503  
2504 =over 4
2505  
2506 =item lt example 9
2507  
2508 package main;
2509  
2510 use Venus::Hash;
2511 use Venus::Undef;
2512  
2513 my $lvalue = Venus::Hash->new;
2514 my $rvalue = Venus::Undef->new;
2515  
2516 my $result = $lvalue->lt($rvalue);
2517  
2518 # 0
2519  
2520 =back
2521  
2522 =cut
2523  
2524 =head2 map
2525  
2526 map(coderef $code) (arrayref)
2527  
2528 The map method executes callback for each key/value in the hash passing the
2529 routine the value at the current position in the loop and returning a new hash
2530 reference containing the elements for which the argument returns a value or
2531 non-empty list. This method can return a list of values in list-context.
2532  
2533 I<Since C<0.01>>
2534  
2535 =over 4
2536  
2537 =item map example 1
2538  
2539 # given: synopsis;
2540  
2541 my $map = $hash->map(sub {
2542 $_ * 2
2543 });
2544  
2545 # [4, 8, 12, 16]
2546  
2547 =back
2548  
2549 =over 4
2550  
2551 =item map example 2
2552  
2553 # given: synopsis;
2554  
2555 my $map = $hash->map(sub {
2556 my ($key, $value) = @_;
2557  
2558 [$key, ($value * 2)]
2559 });
2560  
2561 # [[1, 4], [3, 8], [5, 12], [7, 16]]
2562  
2563 =back
2564  
2565 =cut
2566  
2567 =head2 merge
2568  
2569 merge(hashref @data) (hashref)
2570  
2571 The merge method returns a hash reference where the elements in the hash and
2572 the elements in the argument(s) are merged. This operation performs a deep
2573 merge and clones the datasets to ensure no side-effects.
2574  
2575 I<Since C<0.01>>
2576  
2577 =over 4
2578  
2579 =item merge example 1
2580  
2581 # given: synopsis;
2582  
2583 my $merge = $hash->merge({1 => 'a'});
2584  
2585 # { 1 => "a", 3 => 4, 5 => 6, 7 => 8 }
2586  
2587 =back
2588  
2589 =over 4
2590  
2591 =item merge example 2
2592  
2593 # given: synopsis;
2594  
2595 my $merge = $hash->merge({1 => 'a'}, {5 => 'b'});
2596  
2597 # { 1 => "a", 3 => 4, 5 => "b", 7 => 8 }
2598  
2599 =back
2600  
2601 =cut
2602  
2603 =head2 ne
2604  
2605 ne(any $arg) (boolean)
2606  
2607 The ne method performs a I<"not-equal-to"> operation using the argument provided.
2608  
2609 I<Since C<0.08>>
2610  
2611 =over 4
2612  
2613 =item ne example 1
2614  
2615 package main;
2616  
2617 use Venus::Array;
2618 use Venus::Hash;
2619  
2620 my $lvalue = Venus::Hash->new;
2621 my $rvalue = Venus::Array->new;
2622  
2623 my $result = $lvalue->ne($rvalue);
2624  
2625 # 1
2626  
2627 =back
2628  
2629 =over 4
2630  
2631 =item ne example 2
2632  
2633 package main;
2634  
2635 use Venus::Code;
2636 use Venus::Hash;
2637  
2638 my $lvalue = Venus::Hash->new;
2639 my $rvalue = Venus::Code->new;
2640  
2641 my $result = $lvalue->ne($rvalue);
2642  
2643 # 1
2644  
2645 =back
2646  
2647 =over 4
2648  
2649 =item ne example 3
2650  
2651 package main;
2652  
2653 use Venus::Float;
2654 use Venus::Hash;
2655  
2656 my $lvalue = Venus::Hash->new;
2657 my $rvalue = Venus::Float->new;
2658  
2659 my $result = $lvalue->ne($rvalue);
2660  
2661 # 1
2662  
2663 =back
2664  
2665 =over 4
2666  
2667 =item ne example 4
2668  
2669 package main;
2670  
2671 use Venus::Hash;
2672  
2673 my $lvalue = Venus::Hash->new;
2674 my $rvalue = Venus::Hash->new;
2675  
2676 my $result = $lvalue->ne($rvalue);
2677  
2678 # 0
2679  
2680 =back
2681  
2682 =over 4
2683  
2684 =item ne example 5
2685  
2686 package main;
2687  
2688 use Venus::Hash;
2689 use Venus::Number;
2690  
2691 my $lvalue = Venus::Hash->new;
2692 my $rvalue = Venus::Number->new;
2693  
2694 my $result = $lvalue->ne($rvalue);
2695  
2696 # 1
2697  
2698 =back
2699  
2700 =over 4
2701  
2702 =item ne example 6
2703  
2704 package main;
2705  
2706 use Venus::Hash;
2707 use Venus::Regexp;
2708  
2709 my $lvalue = Venus::Hash->new;
2710 my $rvalue = Venus::Regexp->new;
2711  
2712 my $result = $lvalue->ne($rvalue);
2713  
2714 # 1
2715  
2716 =back
2717  
2718 =over 4
2719  
2720 =item ne example 7
2721  
2722 package main;
2723  
2724 use Venus::Hash;
2725 use Venus::Scalar;
2726  
2727 my $lvalue = Venus::Hash->new;
2728 my $rvalue = Venus::Scalar->new;
2729  
2730 my $result = $lvalue->ne($rvalue);
2731  
2732 # 1
2733  
2734 =back
2735  
2736 =over 4
2737  
2738 =item ne example 8
2739  
2740 package main;
2741  
2742 use Venus::Hash;
2743 use Venus::String;
2744  
2745 my $lvalue = Venus::Hash->new;
2746 my $rvalue = Venus::String->new;
2747  
2748 my $result = $lvalue->ne($rvalue);
2749  
2750 # 1
2751  
2752 =back
2753  
2754 =over 4
2755  
2756 =item ne example 9
2757  
2758 package main;
2759  
2760 use Venus::Hash;
2761 use Venus::Undef;
2762  
2763 my $lvalue = Venus::Hash->new;
2764 my $rvalue = Venus::Undef->new;
2765  
2766 my $result = $lvalue->ne($rvalue);
2767  
2768 # 1
2769  
2770 =back
2771  
2772 =cut
2773  
2774 =head2 new
2775  
2776 new(any @args) (Venus::Hash)
2777  
2778 The new method constructs an instance of the package.
2779  
2780 I<Since C<4.15>>
2781  
2782 =over 4
2783  
2784 =item new example 1
2785  
2786 package main;
2787  
2788 use Venus::Hash;
2789  
2790 my $new = Venus::Hash->new;
2791  
2792 # bless(..., "Venus::Hash")
2793  
2794 =back
2795  
2796 =over 4
2797  
2798 =item new example 2
2799  
2800 package main;
2801  
2802 use Venus::Hash;
2803  
2804 my $new = Venus::Hash->new({1..8});
2805  
2806 # bless(..., "Venus::Hash")
2807  
2808 =back
2809  
2810 =over 4
2811  
2812 =item new example 3
2813  
2814 package main;
2815  
2816 use Venus::Hash;
2817  
2818 my $new = Venus::Hash->new(value => {1..8});
2819  
2820 # bless(..., "Venus::Hash")
2821  
2822 =back
2823  
2824 =cut
2825  
2826 =head2 none
2827  
2828 none(coderef $code) (boolean)
2829  
2830 The none method returns true if none of the elements in the array meet the
2831 criteria set by the operand and rvalue.
2832  
2833 I<Since C<0.01>>
2834  
2835 =over 4
2836  
2837 =item none example 1
2838  
2839 # given: synopsis;
2840  
2841 my $none = $hash->none(sub {
2842 $_ < 1
2843 });
2844  
2845 # 1
2846  
2847 =back
2848  
2849 =over 4
2850  
2851 =item none example 2
2852  
2853 # given: synopsis;
2854  
2855 my $none = $hash->none(sub {
2856 my ($key, $value) = @_;
2857  
2858 $value < 1
2859 });
2860  
2861 # 1
2862  
2863 =back
2864  
2865 =cut
2866  
2867 =head2 one
2868  
2869 one(coderef $code) (boolean)
2870  
2871 The one method returns true if only one of the elements in the array meet the
2872 criteria set by the operand and rvalue.
2873  
2874 I<Since C<0.01>>
2875  
2876 =over 4
2877  
2878 =item one example 1
2879  
2880 # given: synopsis;
2881  
2882 my $one = $hash->one(sub {
2883 $_ == 2
2884 });
2885  
2886 # 1
2887  
2888 =back
2889  
2890 =over 4
2891  
2892 =item one example 2
2893  
2894 # given: synopsis;
2895  
2896 my $one = $hash->one(sub {
2897 my ($key, $value) = @_;
2898  
2899 $value == 2
2900 });
2901  
2902 # 1
2903  
2904 =back
2905  
2906 =cut
2907  
2908 =head2 pairs
2909  
2910 pairs() (arrayref)
2911  
2912 The pairs method is an alias to the pairs_array method. This method can return
2913 a list of values in list-context.
2914  
2915 I<Since C<0.01>>
2916  
2917 =over 4
2918  
2919 =item pairs example 1
2920  
2921 # given: synopsis;
2922  
2923 my $pairs = $hash->pairs;
2924  
2925 # [[1, 2], [3, 4], [5, 6], [7, 8]]
2926  
2927 =back
2928  
2929 =cut
2930  
2931 =head2 path
2932  
2933 path(string $expr) (any)
2934  
2935 The path method traverses the data structure using the path expr provided,
2936 returning the value found or undef. In list-context, this method returns a
2937 tuple, i.e. the value found and boolean representing whether the match was
2938 successful.
2939  
2940 I<Since C<0.01>>
2941  
2942 =over 4
2943  
2944 =item path example 1
2945  
2946 package main;
2947  
2948 use Venus::Hash;
2949  
2950 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
2951  
2952 my $path = $hash->path('/foo/bar');
2953  
2954 # "baz"
2955  
2956 =back
2957  
2958 =over 4
2959  
2960 =item path example 2
2961  
2962 package main;
2963  
2964 use Venus::Hash;
2965  
2966 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
2967  
2968 my $path = $hash->path('/bar/0');
2969  
2970 # "baz"
2971  
2972 =back
2973  
2974 =over 4
2975  
2976 =item path example 3
2977  
2978 package main;
2979  
2980 use Venus::Hash;
2981  
2982 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
2983  
2984 my $path = $hash->path('/bar');
2985  
2986 # ["baz"]
2987  
2988 =back
2989  
2990 =over 4
2991  
2992 =item path example 4
2993  
2994 package main;
2995  
2996 use Venus::Hash;
2997  
2998 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
2999  
3000 my ($path, $exists) = $hash->path('/baz');
3001  
3002 # (undef, 0)
3003  
3004 =back
3005  
3006 =cut
3007  
3008 =head2 puts
3009  
3010 puts(any @args) (arrayref)
3011  
3012 The puts method select values from within the underlying data structure using
3013 L<Venus::Hash/path>, optionally assigning the value to the preceeding scalar
3014 reference and returns all the values selected.
3015  
3016 I<Since C<3.20>>
3017  
3018 =over 4
3019  
3020 =item puts example 1
3021  
3022 package main;
3023  
3024 use Venus::Hash;
3025  
3026 my $hash = Venus::Hash->new({
3027 size => "small",
3028 fruit => "apple",
3029 meta => {
3030 expiry => '5d',
3031 },
3032 color => "red",
3033 });
3034  
3035 my $puts = $hash->puts(undef, 'fruit', undef, 'color');
3036  
3037 # ["apple", "red"]
3038  
3039 =back
3040  
3041 =over 4
3042  
3043 =item puts example 2
3044  
3045 package main;
3046  
3047 use Venus::Hash;
3048  
3049 my $hash = Venus::Hash->new({
3050 size => "small",
3051 fruit => "apple",
3052 meta => {
3053 expiry => '5d',
3054 },
3055 color => "red",
3056 });
3057  
3058 $hash->puts(\my $fruit, 'fruit', \my $expiry, 'meta.expiry');
3059  
3060 my $puts = [$fruit, $expiry];
3061  
3062 # ["apple", "5d"]
3063  
3064 =back
3065  
3066 =over 4
3067  
3068 =item puts example 3
3069  
3070 package main;
3071  
3072 use Venus::Hash;
3073  
3074 my $hash = Venus::Hash->new({
3075 size => "small",
3076 fruit => "apple",
3077 meta => {
3078 expiry => '5d',
3079 },
3080 color => "red",
3081 });
3082  
3083 $hash->puts(
3084 \my $fruit, 'fruit',
3085 \my $color, 'color',
3086 \my $expiry, 'meta.expiry',
3087 \my $ripe, 'meta.ripe',
3088 );
3089  
3090 my $puts = [$fruit, $color, $expiry, $ripe];
3091  
3092 # ["apple", "red", "5d", undef]
3093  
3094 =back
3095  
3096 =over 4
3097  
3098 =item puts example 4
3099  
3100 package main;
3101  
3102 use Venus::Hash;
3103  
3104 my $hash = Venus::Hash->new({set => [1..20]});
3105  
3106 $hash->puts(
3107 \my $a, 'set.0',
3108 \my $b, 'set.1',
3109 \my $m, ['set', '2:-2'],
3110 \my $x, 'set.18',
3111 \my $y, 'set.19',
3112 );
3113  
3114 my $puts = [$a, $b, $m, $x, $y];
3115  
3116 # [1, 2, [3..19], 19, 20]
3117  
3118 =back
3119  
3120 =over 4
3121  
3122 =item puts example 5
3123  
3124 package main;
3125  
3126 use Venus::Hash;
3127  
3128 my $hash = Venus::Hash->new({set => [{1..4}, {1..4}]});
3129  
3130 $hash->puts(\my $a, 'set');
3131  
3132 my $puts = $a;
3133  
3134 # [{1..4}, {1..4}]
3135  
3136 =back
3137  
3138 =cut
3139  
3140 =head2 random
3141  
3142 random() (any)
3143  
3144 The random method returns a random element from the array.
3145  
3146 I<Since C<0.01>>
3147  
3148 =over 4
3149  
3150 =item random example 1
3151  
3152 # given: synopsis;
3153  
3154 my $random = $hash->random;
3155  
3156 # 6
3157  
3158 # my $random = $hash->random;
3159  
3160 # 4
3161  
3162 =back
3163  
3164 =cut
3165  
3166 =head2 reset
3167  
3168 reset() (arrayref)
3169  
3170 The reset method returns nullifies the value of each element in the hash.
3171  
3172 I<Since C<0.01>>
3173  
3174 =over 4
3175  
3176 =item reset example 1
3177  
3178 # given: synopsis;
3179  
3180 my $reset = $hash->reset;
3181  
3182 # { 1 => undef, 3 => undef, 5 => undef, 7 => undef }
3183  
3184 =back
3185  
3186 =cut
3187  
3188 =head2 reverse
3189  
3190 reverse() (hashref)
3191  
3192 The reverse method returns a hash reference consisting of the hash's keys and
3193 values inverted. Note, keys with undefined values will be dropped.
3194  
3195 I<Since C<0.01>>
3196  
3197 =over 4
3198  
3199 =item reverse example 1
3200  
3201 # given: synopsis;
3202  
3203 my $reverse = $hash->reverse;
3204  
3205 # { 2 => 1, 4 => 3, 6 => 5, 8 => 7 }
3206  
3207 =back
3208  
3209 =cut
3210  
3211 =head2 rsort
3212  
3213 rsort() (arrayref)
3214  
3215 The rsort method returns an array reference containing the values in the array
3216 sorted alphanumerically in reverse.
3217  
3218 I<Since C<4.15>>
3219  
3220 =over 4
3221  
3222 =item rsort example 1
3223  
3224 package main;
3225  
3226 use Venus::Hash;
3227  
3228 my $hash = Venus::Hash->new({1 => 'a', 2 => 'b', 3 => 'c', 4 => 'd'});
3229  
3230 my $rsort = $hash->rsort;
3231  
3232 # ["d", "c", "b", "a"]
3233  
3234 =back
3235  
3236 =cut
3237  
3238 =head2 sets
3239  
3240 sets(string @args) (arrayref)
3241  
3242 The sets method find values from within the underlying data structure using
3243 L<Venus::Hash/path>, where each argument pair is a selector and value, and
3244 returns all the values provided. Returns a list in list context. Note, nested
3245 data structures can be updated but not created.
3246  
3247 I<Since C<4.15>>
3248  
3249 =over 4
3250  
3251 =item sets example 1
3252  
3253 package main;
3254  
3255 use Venus::Hash;
3256  
3257 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
3258  
3259 my $sets = $hash->sets('bar' => 'bar', 'foo.bar' => 'bar');
3260  
3261 # ['bar', 'bar']
3262  
3263 =back
3264  
3265 =over 4
3266  
3267 =item sets example 2
3268  
3269 package main;
3270  
3271 use Venus::Hash;
3272  
3273 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
3274  
3275 my ($bar, $foo_bar) = $hash->sets('bar' => 'bar', 'foo.bar' => 'bar');
3276  
3277 # ('bar', 'bar')
3278  
3279 =back
3280  
3281 =over 4
3282  
3283 =item sets example 3
3284  
3285 package main;
3286  
3287 use Venus::Hash;
3288  
3289 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
3290  
3291 my $sets = $hash->sets('bar' => 'bar', 'foo.bar' => 'bar', 'foo.baz' => 'box');
3292  
3293 # ['bar', 'bar', 'box']
3294  
3295 =back
3296  
3297 =over 4
3298  
3299 =item sets example 4
3300  
3301 package main;
3302  
3303 use Venus::Hash;
3304  
3305 my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'}, 'bar' => ['baz']});
3306  
3307 my $sets = $hash->sets('bar' => 'bar', 'foo.bar' => 'bar', 'foo.baz.box' => 'box');
3308  
3309 # ['bar', 'bar', 'box']
3310  
3311 # $hash->gets('foo.bar.baz');
3312  
3313 # undef
3314  
3315 =back
3316  
3317 =cut
3318  
3319 =head2 shuffle
3320  
3321 shuffle() (arrayref)
3322  
3323 The shuffle method returns an array with the values returned in a randomized order.
3324  
3325 I<Since C<4.15>>
3326  
3327 =over 4
3328  
3329 =item shuffle example 1
3330  
3331 package main;
3332  
3333 use Venus::Hash;
3334  
3335 my $hash = Venus::Hash->new({1..20});
3336  
3337 my $shuffle = $hash->shuffle;
3338  
3339 # [6, 12, 2, 20, 18, 16, 10, 4, 8, 14]
3340  
3341 =back
3342  
3343 =cut
3344  
3345 =head2 slice
3346  
3347 slice(string @keys) (arrayref)
3348  
3349 The slice method returns an array reference of the values that correspond to
3350 the key(s) specified in the arguments.
3351  
3352 I<Since C<0.01>>
3353  
3354 =over 4
3355  
3356 =item slice example 1
3357  
3358 # given: synopsis;
3359  
3360 my $slice = $hash->slice(1, 3);
3361  
3362 # [2, 4]
3363  
3364 =back
3365  
3366 =cut
3367  
3368 =head2 sort
3369  
3370 sort() (arrayref)
3371  
3372 The sort method returns an array reference containing the values in the array
3373 sorted alphanumerically.
3374  
3375 I<Since C<4.15>>
3376  
3377 =over 4
3378  
3379 =item sort example 1
3380  
3381 package main;
3382  
3383 use Venus::Hash;
3384  
3385 my $hash = Venus::Hash->new({1 => 'a', 2 => 'b', 3 => 'c', 4 => 'd'});
3386  
3387 my $sort = $hash->sort;
3388  
3389 # ["a".."d"]
3390  
3391 =back
3392  
3393 =cut
3394  
3395 =head2 tv
3396  
3397 tv(any $arg) (boolean)
3398  
3399 The tv method performs a I<"type-and-value-equal-to"> operation using argument
3400 provided.
3401  
3402 I<Since C<0.08>>
3403  
3404 =over 4
3405  
3406 =item tv example 1
3407  
3408 package main;
3409  
3410 use Venus::Array;
3411 use Venus::Hash;
3412  
3413 my $lvalue = Venus::Hash->new;
3414 my $rvalue = Venus::Array->new;
3415  
3416 my $result = $lvalue->tv($rvalue);
3417  
3418 # 0
3419  
3420 =back
3421  
3422 =over 4
3423  
3424 =item tv example 2
3425  
3426 package main;
3427  
3428 use Venus::Code;
3429 use Venus::Hash;
3430  
3431 my $lvalue = Venus::Hash->new;
3432 my $rvalue = Venus::Code->new;
3433  
3434 my $result = $lvalue->tv($rvalue);
3435  
3436 # 0
3437  
3438 =back
3439  
3440 =over 4
3441  
3442 =item tv example 3
3443  
3444 package main;
3445  
3446 use Venus::Float;
3447 use Venus::Hash;
3448  
3449 my $lvalue = Venus::Hash->new;
3450 my $rvalue = Venus::Float->new;
3451  
3452 my $result = $lvalue->tv($rvalue);
3453  
3454 # 0
3455  
3456 =back
3457  
3458 =over 4
3459  
3460 =item tv example 4
3461  
3462 package main;
3463  
3464 use Venus::Hash;
3465  
3466 my $lvalue = Venus::Hash->new;
3467 my $rvalue = Venus::Hash->new;
3468  
3469 my $result = $lvalue->tv($rvalue);
3470  
3471 # 1
3472  
3473 =back
3474  
3475 =over 4
3476  
3477 =item tv example 5
3478  
3479 package main;
3480  
3481 use Venus::Hash;
3482 use Venus::Number;
3483  
3484 my $lvalue = Venus::Hash->new;
3485 my $rvalue = Venus::Number->new;
3486  
3487 my $result = $lvalue->tv($rvalue);
3488  
3489 # 0
3490  
3491 =back
3492  
3493 =over 4
3494  
3495 =item tv example 6
3496  
3497 package main;
3498  
3499 use Venus::Hash;
3500 use Venus::Regexp;
3501  
3502 my $lvalue = Venus::Hash->new;
3503 my $rvalue = Venus::Regexp->new;
3504  
3505 my $result = $lvalue->tv($rvalue);
3506  
3507 # 0
3508  
3509 =back
3510  
3511 =over 4
3512  
3513 =item tv example 7
3514  
3515 package main;
3516  
3517 use Venus::Hash;
3518 use Venus::Scalar;
3519  
3520 my $lvalue = Venus::Hash->new;
3521 my $rvalue = Venus::Scalar->new;
3522  
3523 my $result = $lvalue->tv($rvalue);
3524  
3525 # 0
3526  
3527 =back
3528  
3529 =over 4
3530  
3531 =item tv example 8
3532  
3533 package main;
3534  
3535 use Venus::Hash;
3536 use Venus::String;
3537  
3538 my $lvalue = Venus::Hash->new;
3539 my $rvalue = Venus::String->new;
3540  
3541 my $result = $lvalue->tv($rvalue);
3542  
3543 # 0
3544  
3545 =back
3546  
3547 =over 4
3548  
3549 =item tv example 9
3550  
3551 package main;
3552  
3553 use Venus::Hash;
3554 use Venus::Undef;
3555  
3556 my $lvalue = Venus::Hash->new;
3557 my $rvalue = Venus::Undef->new;
3558  
3559 my $result = $lvalue->tv($rvalue);
3560  
3561 # 0
3562  
3563 =back
3564  
3565 =cut
3566  
3567 =head2 values
3568  
3569 values() (arrayref)
3570  
3571 The values method returns an array reference consisting of all the values in
3572 the hash.
3573  
3574 I<Since C<4.15>>
3575  
3576 =over 4
3577  
3578 =item values example 1
3579  
3580 # given: synopsis;
3581  
3582 my $values = $hash->values;
3583  
3584 # [2, 4, 6, 8]
3585  
3586 =back
3587  
3588 =cut
3589  
3590 =head1 AUTHORS
3591  
3592 Awncorp, C<awncorp@cpan.org>
3593  
3594 =cut
3595  
3596 =head1 LICENSE
3597  
3598 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
3599  
3600 This program is free software, you can redistribute it and/or modify it under
3601 the terms of the Apache license version 2.0.
3602  
3603 =cut
« blib/lib/Venus/Hook.pm ↑ Summary blib/lib/Venus/Json.pm »