1Validation::Class::MappUisnegr(3C)ontributed Perl DocumeVnatlaitdiaotnion::Class::Mapping(3)
2
3
4
6 Validation::Class::Mapping - Generic Container Class for a Hash
7 Reference
8
10 version 7.900057
11
13 use Validation::Class::Mapping;
14
15 my $foos = Validation::Class::Mapping->new;
16
17 $foos->add(foo => 'one foo');
18 $foos->add(bar => 'one bar');
19
20 print $foos->count; # 2 objects
21
23 Validation::Class::Mapping is a container class that provides general-
24 purpose functionality for hashref objects.
25
27 new
28 my $self = Validation::Class::Mapping->new;
29
30 add
31 $self = $self->add(foo => 1, bar => 2);
32
33 clear
34 $self = $self->clear;
35
36 count
37 my $count = $self->count;
38
39 delete
40 $value = $self->delete($name);
41
42 defined
43 $true if $self->defined($name) # defined
44
45 each
46 $self = $self->each(sub{
47
48 my ($key, $value) = @_;
49
50 });
51
52 exists
53 $true if $self->exists($name) # exists
54
55 get
56 my $value = $self->get($name); # i.e. $self->{$name}
57
58 grep
59 $new_list = $self->grep(qr/update_/);
60
61 has
62 $true if $self->has($name) # defined or exists
63
64 hash
65 my $hash = $self->hash;
66
67 iterator
68 my $next = $self->iterator();
69
70 # defaults to iterating by keys but accepts: sort, rsort, nsort, or rnsort
71 # e.g. $self->iterator('sort', sub{ (shift) cmp (shift) });
72
73 while (my $item = $next->()) {
74 # do something with $item (value)
75 }
76
77 keys
78 my @keys = $self->keys;
79
80 list
81 my %hash = $self->list;
82
83 merge
84 $self->merge($hashref);
85
86 nsort
87 my @keys = $self->nsort;
88
89 pairs
90 my @pairs = $self->pairs;
91 # or filter using $self->pairs('grep', $regexp);
92
93 foreach my $pair (@pairs) {
94 # $pair->{key} is $pair->{value};
95 }
96
97 rmerge
98 $self->rmerge($hashref);
99
100 rnsort
101 my @keys = $self->rnsort;
102
103 rsort
104 my @keys = $self->rsort;
105
106 sort
107 my @keys = $self->sort(sub{...});
108
109 values
110 my @values = $self->values;
111
113 Al Newkirk <anewkirk@ana.io>
114
116 This software is copyright (c) 2011 by Al Newkirk.
117
118 This is free software; you can redistribute it and/or modify it under
119 the same terms as the Perl 5 programming language system itself.
120
121
122
123perl v5.32.1 2021-01-27 Validation::Class::Mapping(3)