DOKK / manpages / debian 12 / libvalidation-class-perl / Validation::Class::Mapping.3pm.en
Validation::Class::Mapping(3pm) User Contributed Perl Documentation Validation::Class::Mapping(3pm)

Validation::Class::Mapping - Generic Container Class for a Hash Reference

version 7.900058

    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

Validation::Class::Mapping is a container class that provides general-purpose functionality for hashref objects.

    my $self = Validation::Class::Mapping->new;

    $self = $self->add(foo => 1, bar => 2);

    $self = $self->clear;

    my $count = $self->count;

    $value = $self->delete($name);

    $true if $self->defined($name) # defined

    $self = $self->each(sub{
        my ($key, $value) = @_;
    });

    $true if $self->exists($name) # exists

    my $value = $self->get($name); # i.e. $self->{$name}

    $new_list = $self->grep(qr/update_/);

    $true if $self->has($name) # defined or exists

    my $hash = $self->hash;

    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)
    }

    my @keys = $self->keys;

    my %hash = $self->list;

    $self->merge($hashref);

    my @keys = $self->nsort;

    my @pairs = $self->pairs;
    # or filter using $self->pairs('grep', $regexp);
    foreach my $pair (@pairs) {
        # $pair->{key} is $pair->{value};
    }

    $self->rmerge($hashref);

    my @keys = $self->rnsort;

    my @keys = $self->rsort;

    my @keys = $self->sort(sub{...});

    my @values = $self->values;

Al Newkirk <anewkirk@ana.io>

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.

2022-06-22 perl v5.34.0