Valida...isting(3pm)

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

πŸ’– Validation::Class::Listing πŸ’–

okay bestie, gather round, because this one is a whole mood β€” it's a page from the User Contributed Perl Documentation (the 3pm section, for my fellow perl girlies who live in man pages 🫢), and it's all about a lil container class that holds an arrayref. iconic behavior honestly.

✨ NAME ✨

Validation::Class::Listing β€” Generic Container Class for an Array Reference

like... it's a bucket. for stuff. an arrayref bucket. no cap. πŸŽ€


🌸 VERSION 🌸

version 7.900059

(that's the version, keep it in your notes bestie, we don't skip the numbers here πŸ’…)


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the vibe, straight up:

use Validation::Class::Listing;

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

$foos->add('foo');
$foos->add('bar', 'baz');

print $foos->count; # 3 objects

so you make one, you shove 'foo' in there, then 'bar' and 'baz' together, and boom β€” count says 3 objects. it's giving organized. it's giving collected. 🌈


πŸ’œ DESCRIPTION πŸ’œ

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

that's the whole thesis bestie. it's a container. it holds arrayref objects. it does general-purpose stuff with them. lowkey the most reliable friend in the group chat. ✨


πŸ‘‘ METHODS πŸ‘‘

every single one, no skips, no shortcuts, periodt:

πŸ’– new πŸ’–

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

πŸ’– add πŸ’–

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

πŸ’– clear πŸ’–

$self = $self->clear;

πŸ’– count πŸ’–

my $count = $self->count;

πŸ’– delete πŸ’–

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

πŸ’– defined πŸ’–

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

πŸ’– each πŸ’–

$self = $self->each(sub{

    my ($index, $value) = @_;

});

πŸ’– first πŸ’–

my $value = $self->first;

πŸ’– get πŸ’–

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

πŸ’– grep πŸ’–

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

πŸ’– has πŸ’–

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

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

ngl the iterator one is the main character of this whole list. it defaults to iterating by keys, but it also accepts sort, rsort, nsort, or rnsort, and you can hand it a custom sub like that one up there. πŸ’…

πŸ’– join πŸ’–

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

πŸ’– last πŸ’–

my $value = $self->last;

πŸ’– list πŸ’–

my @list = $self->list;

πŸ’– nsort πŸ’–

my @list = $self->nsort;

πŸ’– pairs πŸ’–

my @pairs = $self->pairs;
# or filter using $self->pairs('grep', $regexp);

foreach my $pair (@pairs) {
    # $pair->{index} is $pair->{value};
}

so each pair is a little hashref situation where $pair->{index} is $pair->{value} β€” cute right?? and you can filter the whole thing with $self->pairs('grep', $regexp). obsessed. πŸ“

πŸ’– rnsort πŸ’–

my @list = $self->rnsort;

πŸ’– rsort πŸ’–

my @list = $self->rsort;

πŸ’– sort πŸ’–

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

πŸ’– unique πŸ’–

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

🧚 AUTHOR 🧚

Al Newkirk <anewkirk@ana.io>

shoutout to Al, the legend who made all of this happen πŸ™ˆβœ¨


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.

so yeah bestie, it's free software β€” redistribute it, modify it, do your thing, just keep it under the same terms as the Perl 5 programming language system itself. that's the deal, and we respect the deal. πŸ’œ

and that's a wrap, fr fr! this page came to you from perl v5.36.0, dated 2023-06-11, live from the Valida...isting(3pm) corner of the manual. go forth and container-ize, bestie β€” you ate. πŸ’…πŸ”₯πŸ‘‘

πŸ“¦ where this page comes from