Moose::...Counter(3)
π Moose::...Counter π
okay bestie, so this is a page from the User Contributed Perl Documentation manual β yes that's the manual name, we're not hiding it, it's giving β¨community vibesβ¨. Sit down, grab a strawberry π, and let's talk about the absolute icon that is this trait.
πΈ NAME πΈ
Moose::Meta::Attribute::Native::Trait::Counter β it's the helper trait for Int attributes that represent counters. that's it. that's the whole job. and it does it flawlessly, no cap.
π¦ VERSION π¦
this one's rockin' version 2.4000 π
β¨ SYNOPSIS β¨
okay so here's the whole vibe in code, and I need you to look at it because it's genuinely so clean:
package MyHomePage;
use Moose;
has 'counter' => (
traits => ['Counter'],
is => 'ro',
isa => 'Num',
default => 0,
handles => {
inc_counter => 'inc',
dec_counter => 'dec',
reset_counter => 'reset',
},
);
my $page = MyHomePage->new();
$page->inc_counter; # same as $page->counter( $page->counter + 1 );
$page->dec_counter; # same as $page->counter( $page->counter - 1 );
my $count_by_twos = 2;
$page->inc_counter($count_by_twos);
like?? you just hand it a traits => ['Counter'] and suddenly your attribute has main character energy with a whole delegation glow-up. the handles hash is literally you naming your little minions. obsessed.
π DESCRIPTION π
so, what is this trait actually doing? it provides native delegation methods for counters. and here's the tea β a counter can be any sort of number, integer or not, doesn't matter, it's inclusive like that π«Ά.
the delegation methods let you:
- increment it β¬οΈ
- decrement it β¬οΈ
- reset it π
that's the whole menu, and it ate. no leftovers.
π DEFAULT TYPE π
if you don't give your attribute an isa value? don't stress, bestie, it just defaults to Num. automatic. generous. iconic. π
π PROVIDED METHODS π
here's the part where we meet the whole squad. every single one. let's go.
set($value)β sets the counter to the value you passed in, and hands you back the new value. it needs exactly one argument, so don't ghost it β pass something. this method requires a single argument.incinc($arg)β bumps the attribute value up by however much the argument says, or by 1 if you gave it nothing. it returns the new value. it accepts a single argument.decdec($arg)β brings the attribute value down by the argument's amount, or by 1 if there's no argument. returns the new value. accepts a single argument.resetβ puts the value stored in this slot back to its default value, and returns the new value. it's giving factory reset but make it cute. πβ¨
side note bestie:incanddeceach get listed twice in the original β once bare and once with($arg)β and I'm keeping both because that's just how the delegation names show up. no skipping, no merging, we respect the list. π
π BUGS π
found a bug? okay dramatic, but valid. go look at "BUGS" in Moose for all the details on how to report it. the Moose page has the whole procedure, iykyk.
π«Ά AUTHORS π«Ά
these are the legends who made this happen, every single one, in order:
- Stevan Little <stevan@cpan.org>
- Dave Rolsky <autarch@urth.org>
- Jesse Luehrs <doy@cpan.org>
- Shawn M Moore <sartak@cpan.org>
- ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman) <nothingmuch@woobling.org>
- Karen Etheridge <ether@cpan.org>
- Florian Ragwitz <rafl@debian.org>
- Hans Dieter Pearcey <hdp@cpan.org>
- Chris Prather <chris@prather.org>
- Matt S Trout <mstrout@cpan.org>
the way they all showed up for one little counter trait?? collaboration goals fr fr ππ
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2006 by Infinity Interactive, Inc.
and it's free software, bestie β you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so go forth, remix, slay responsibly. π
and that's the whole page, start to finish π β this was generated from the User Contributed Perl Documentation source, perl v5.42.0, dated 2025-07-25, and the page title is Moose::...Counter(3). mwah. go increment something. β¨π
π¦ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms