File: callback_hash_entry.t

package info (click to toggle)
libdata-visitor-perl 0.30-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 204 kB
  • ctags: 49
  • sloc: perl: 1,169; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 736 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use Data::Visitor::Callback;

my $data = {
	type_a => {
		point => 50,
		subtype_a_2 => {
			point => 27,
			subtype_a_2_bar => {
				circle => 14,
			},
		},
	},
	point => 33,
};


my $sum = 0;

Data::Visitor::Callback->new(
	ignore_return_values => 1,
	hash_entry => sub {
		my ( $self, $k, $v ) = @_;
		$sum += $v unless ref $v;
	},
)->visit($data);

is($sum, 124, 'get_recursive_hash_value_visitor, all values');


$sum = 0;
Data::Visitor::Callback->new(
	ignore_return_values => 1,
	hash_entry => sub {
		my ( $self, $k, $v ) = @_;
		$sum += $v if $k eq 'point';
	},
)->visit($data);

is($sum, 110, 'get_recursive_hash_value_visitor, only "point" keys');

done_testing;