Valida...apping(3pm)

πŸ“¦
version 7.900059 Β· 7 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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. πŸ‘‘


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