Valida...apping(3pm)
π NAME π
Validation::Class::Mapping β a generic container class for a hash reference, bestie. It's the lil' box that holds your key/value situation together. π
β¨ VERSION β¨
version 7.900059 β yes, that's the exact number, no cap.
πΈ SYNOPSIS πΈ
use Validation::Class::Mapping;
my $foos = Validation::Class::Mapping->new;
$foos->add(foo => 'one foo');
$foos->add(bar => 'one bar');
print $foos->count; # 2 objects
okay so look at that. You make a $foos object, you add two things to it, and count tells you there's 2 objects in there. That's the whole vibe. π
π¦ DESCRIPTION π¦
Validation::Class::Mapping is a container class that gives you general-purpose functionality for hashref objects. That's it, that's the girl. It holds stuff, it hands stuff back, it does the little hashref tasks so you don't have to. β¨
π METHODS π
This is the main character section, fr fr. Every single one of these is here, no skipping. π«Ά
π new
my $self = Validation::Class::Mapping->new;
Constructor behavior. You call it on the class, you get $self back. Iconic.
π add
$self = $self->add(foo => 1, bar => 2);
Slaps one or more key/value pairs into the object and hands you back $self. Chainable energy. π
π clear
$self = $self->clear;
Wipes it. Empty. Gone. Returns $self.
π count
my $count = $self->count;
Gives you the count of what's inside. A number. That's the tea. π₯
π§ delete
$value = $self->delete($name);
Removes the thing named $name and gives you back $value.
β defined
$true if $self->defined($name) # defined
Truthy when $name is defined. That's it.
πΈ each
$self = $self->each(sub{
my ($key, $value) = @_;
});
Runs your callback over every pair, handing you ($key, $value). Returns $self.
π¦ exists
$true if $self->exists($name) # exists
Truthy when $name exists. Note: exists and defined are not the same thing, bestie, don't get it twisted. π
π get
my $value = $self->get($name); # i.e. $self->{$name}
Fetches the value for $name. Same energy as reaching in with $self->{$name} directly.
π
grep
$new_list = $self->grep(qr/update_/);
Filters with a regex and gives you back a new list of what matched. So qr/update_/ grabs everything with update_ in the name. β¨
π has
$true if $self->has($name) # defined or exists
Truthy when $name is defined or exists β it's the either/or queen.
π₯ hash
my $hash = $self->hash;
Hands you back the hash. The whole thing.
π iterator
my $next = $self->iterator();
# defaults to iterating by keys but accepts: sort, rsort, nsort, or rnsort
# e.g. $self->iterator('sort', sub{ (shift) cmp (shift) });
while (my $item = $next->()) {
# do something with $item (value)
}
okay this one's giving main character energy. You get back $next, and calling $next->() walks you through the values one at a time. It defaults to iterating by keys, but it accepts sort, rsort, nsort, or rnsort if you wanna switch it up, and you can pass a comparison sub like $self->iterator('sort', sub{ (shift) cmp (shift) }). Then while (my $item = $next->()) loops and $item is your value. π
π¦ keys
my @keys = $self->keys;
All the keys, as a list. Boom.
π list
my %hash = $self->list;
Gives you back a %hash. A whole hash, from your object.
πΈ merge
$self->merge($hashref);
Merges a $hashref in. Note: returns nothing here, bestie, just does the thing.
β nsort
my @keys = $self->nsort;
Numeric sort on the keys, handed back as a list.
π pairs
my @pairs = $self->pairs;
# or filter using $self->pairs('grep', $regexp);
foreach my $pair (@pairs) {
# $pair->{key} is $pair->{value};
}
Gives you key/value pairs as little hashrefs. You can also filter the whole thing with $self->pairs('grep', $regexp). Then in the loop, $pair->{key} is $pair->{value}. π
π§ rmerge
$self->rmerge($hashref);
The reverse merge, with a $hashref. Also returns nothing β just vibes.
π rnsort
my @keys = $self->rnsort;
Reverse numeric sort on the keys. List back.
π
rsort
my @keys = $self->rsort;
Reverse sort on the keys, returned as a list.
π₯ sort
my @keys = $self->sort(sub{...});
Sorts the keys with your sub{...} and hands the list back.
π¦ values
my @values = $self->values;
All the values, as a list. Periodt.
π AUTHOR π
Al Newkirk <anewkirk@ana.io> β the icon who wrote this. π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2011 by Al Newkirk.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
fr fr, that's the actual license text, don't come for me. π«Ά
User Contributed Perl Documentation came through with this one, and it was generated under perl v5.36.0 on 2023-06-11. That's the sign-off bestie, mwah, slay, bye. πβ¨π
π¦ where this page comes from
- debian trixie: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms