MooseX...ounter(3pm)

πŸ“¦
version 0.25 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

MooseX::AttributeHelpers::Trait::Counter β€” it's giving simple counter attribute, bestie πŸ’…


✨ VERSION ✨

version 0.25 🫢


πŸŽ€ SYNOPSIS πŸŽ€

okay so here's the whole vibe, copy-paste ready:

package MyHomePage;
use Moose;
use MooseX::AttributeHelpers;

has 'counter' => (
    metaclass => 'Counter',
    is        => 'ro',
    isa       => 'Num',
    default   => sub { 0 },
    provides  => {
        inc => 'inc_counter',
        dec => 'dec_counter',
        reset => 'reset_counter',
    }
);

my $page = MyHomePage->new();
$page->inc_counter; # same as $page->counter($page->counter + 1);
$page->dec_counter; # same as $page->counter($page->counter - 1);

πŸ¦‹ DESCRIPTION πŸ¦‹

so this module hands you a simple counter attribute β€” like, a little number that lives in your object and can be incremented and decremented. that's the whole thing. iconic, honestly. ✨

and here's the cute part: if your attribute definition doesn't include any of is, isa, default or provides, but does use the "Counter" metaclass, then this module just applies the defaults from the SYNOPSIS up there for you. no cap. which means you can do an absolutely bare-bones counter like this:

has 'foo' => (metaclass => 'Counter');
$obj->inc_foo;

and it just works. main character energy fr fr 🌟


πŸ’… METHODS πŸ’…

  • meta β€” yeah, the meta thing 🌸
  • method_provider β€” the method provider situation πŸ’œ
  • has_method_provider β€” checks whether there's a method provider πŸŽ€
  • helper_type β€” the helper type πŸ¦‹
  • process_options_for_provides β€” this one runs before its superclass method, okay? important. 🫢
  • check_provides_values β€” and this one runs after its superclass method. so, before and after. periodt. πŸ‘‘

πŸ‘‘ PROVIDED METHODS πŸ‘‘

okay so before we get into these β€” super important, do not skip this: all of these methods do in place modification of the value stored in the attribute. like, they're not handing you back a fresh copy, they are reaching in and changing the actual thing. πŸ’€

  • set β€” sets the counter to the value you give it. 🎯
  • inc β€” bumps the value stored in this slot up by 1. and if you hand it an argument, the counter gets increased by the amount you specified. πŸ”₯
  • dec β€” drops the value stored in this slot down by 1. and if you hand it an argument, the counter gets increased by the amount you specified. (yep, that's what it says πŸ™ˆ)
  • reset β€” resets the value stored in this slot back to its default value. it's giving factory reset but make it cute. 🌈

🌈 SUPPORT 🌈

if something's busted, here's where to go:


πŸ“ AUTHOR πŸ“

Stevan Little <stevan@iinteractive.com> β€” thank you king 🫑


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. ✨


okay bestie that's the whole page!! πŸ₯³ it's from perl v5.34.0, dated 2022-06-15, and this whole manual page is MooseX...ounter(3pm) from the User Contributed Perl Documentation. go forth and counter, you've got this πŸ’–πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from