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.
  • inc
  • inc($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.
  • dec
  • dec($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: inc and dec each 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 πŸŒˆπŸ‘‘


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