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

Validation::Class::Listing - Generic Container Class for an Array Reference

version 7.900057

    use Validation::Class::Listing;
    my $foos = Validation::Class::Listing->new;
    $foos->add('foo');
    $foos->add('bar', 'baz');
    print $foos->count; # 3 objects

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

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

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

    $self = $self->clear;

    my $count = $self->count;

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

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

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

    my $value = $self->first;

    my $value = $self->get($index); # i.e. $self->[$index]

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

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

    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
    }

    my $string = $self->join($delimiter);

    my $value = $self->last;

    my @list = $self->list;

    my @list = $self->nsort;

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

    my @list = $self->rnsort;

    my @list = $self->rsort;

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

    my @list = $self->unique();

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.

2017-11-24 perl v5.26.1