Valida...isting(3pm)
π 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 πβ¨
π 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.
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
- 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