MooseX...::List(3pm)
π MooseX::AttributeHelpers::MethodProvider::List β aka MooseX...::List(3pm) β¨
okay bestie, sit down, hydrate, because we're about to talk about the method generator for MooseX::AttributeHelpers::Collection::List and it's honestly a whole vibe. it's giving Perl, it's giving User Contributed Perl Documentation, it's giving slay. π¦
β¨ VERSION β¨
version 0.25 β yes queen, we're on 0.25, no cap.
πΈ SYNOPSIS πΈ
okay so here's the entire situation, and honestly? iconic. look at this:
package Stuff;
use Moose;
use MooseX::AttributeHelpers;
has 'options' => (
metaclass => 'Collection::List',
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub { [] },
auto_deref => 1,
provides => {
elements => 'all_options',
map => 'map_options',
grep => 'filter_options',
find => 'find_option',
first => 'first_option',
last => 'last_option',
get => 'get_option',
join => 'join_options',
count => 'count_options',
empty => 'do_i_have_options',
sort => 'sorted_options',
}
);
no Moose;
1;
not me reading provides and just... π«Ά the way that each key maps to a name you pick yourself? chef's kiss. you're literally naming your own methods. main character energy fr fr.
π DESCRIPTION π
so this is a role β and what it does is provide the method generators for MooseX::AttributeHelpers::Collection::List. that's it. that's the whole job. and it does it beautifully. β¨
π METHODS π
meta
yeah. that's the method. that's the whole list. meta. periodt. π
π PROVIDED METHODS π
these are the methods you get to hand out like friendship bracelets. let's go one by one, no skipping, i don't play that. π
countβ returns the number of elements in the list. that's it. just counting. little accountant behaviour, we love it.
$stuff = Stuff->new;
$stuff->options(["foo", "bar", "baz", "boo"]);
my $count = $stuff->count_options;
print "$count\n"; # prints 4
emptyβ if the list is populated, returns true. otherwise, returns false. (yes the name isemptyand it's true when it's not empty. i know. i KNOW. it's giving chaos but it's what the docs say so we're rolling with it. π)
$stuff->do_i_have_options ? print "Good boy.\n" : die "No options!\n" ;
findβ this method accepts a subroutine reference as its argument. that sub will receive each element of the list in turn. if it returns true for an element, that element will be returned by thefindmethod. first match wins, no take-backs. β¨
my $found = $stuff->find_option( sub { $_[0] =~ /^b/ } );
print "$found\n"; # prints "bar"
grepβ this method accepts a subroutine reference as its argument. this method returns every element for which that subroutine reference returns a true value. find gives you one, grep gives you the whole squad. π₯
my @found = $stuff->filter_options( sub { $_[0] =~ /^b/ } );
print "@found\n"; # prints "bar baz boo"
mapβ this method accepts a subroutine reference as its argument. the subroutine will be executed for each element of the list. it is expected to return a modified version of that element. the return value of the method is a list of the modified options. glow-up generator, honestly. π¦
my @mod_options = $stuff->map_options( sub { $_[0] . "-tag" } );
print "@mod_options\n"; # prints "foo-tag bar-tag baz-tag boo-tag"
sortβ sorts and returns the elements of the list.
you can provide an optional subroutine reference to sort with (as you can with the core sort function). however, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. that's the plot twist. no $a, no $b, just vibes and positional args. π
# ascending ASCIIbetical
my @sorted = $stuff->sort_options();
# Descending alphabetical order
my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } );
print "@sorted_options\n"; # prints "foo boo baz bar"
elementsβ returns all of the elements of the list. all of them. the whole roster. β
my @option = $stuff->all_options;
print "@options\n"; # prints "foo bar baz boo"
joinβ joins every element of the list using the separator given as argument. you pick the lil glue string. π
my $joined = $stuff->join_options( ':' );
print "$joined\n"; # prints "foo:bar:baz:boo"
getβ returns an element of the list by its index. zero-indexed, bestie, don't come at me. π
my $option = $stuff->get_option(1);
print "$option\n"; # prints "bar"
firstβ returns the first element of the list. the OG. the main character. π
my $first = $stuff->first_option;
print "$first\n"; # prints "foo"
lastβ returns the last element of the list. the finale. the closing number. π
my $last = $stuff->last_option;
print "$last\n"; # prints "boo"
π«Ά SUPPORT π«Ά
got bugs? we listen. bugs may be submitted through the RT bug tracker at <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> (or you can email <bug-MooseX-AttributeHelpers@rt.cpan.org>). π¬
there is also a mailing list available for users of this distribution, at <http://lists.perl.org/list/moose.html>. join the club, we have snacks. π
there is also an irc channel available for users of this distribution, at #moose on irc.perl.org <irc://irc.perl.org/#moose>. come say hi, it's a vibe. π¬
π AUTHOR π
Stevan Little <stevan@iinteractive.com> β the legend, the icon, the moment. π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in freedom, bestie, go wild. π
and that's the whole page!! this was generated by perl v5.34.0 and it's dated 2022-06-15 β a lil time capsule from the User Contributed Perl Documentation collection, and honestly it ate. mwah. π
β¨ no cap, ily, go write some list methods. π¦
π¦ where this page comes from
- debian bookworm: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-attributehelpers-perl 0.25-2 Β· 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