Sub::Ha...Counter(3)

✨ NAME ✨

okay so bestie, this is Sub::HandlesVia::HandlerLibrary::Counter β€” a whole library of counter-related methods πŸ’… it lives in the Sub::Ha...Counter(3) corner of the User Contributed Perl Documentation, and it's here to make your attributes do math without you lifting a finger πŸŽ€


🌸 SYNOPSIS 🌸

like, here's the vibe. you got a class, you got an attribute, and instead of writing a million little methods by hand, you just say "handles_via Counter" and the whole squad shows up:

package My::Class {
  use Moo;
  use Sub::HandlesVia;
  use Types::Standard 'Int';
  has attr => (
    is => 'rwp',
    isa => Int,
    handles_via => 'Counter',
    handles => {
      'my_dec' => 'dec',
      'my_inc' => 'inc',
      'my_reset' => 'reset',
      'my_set' => 'set',
    },
  );
}

not me setting up four whole methods in like six lines 😭 iconic behaviour fr fr.


πŸ’– DESCRIPTION πŸ’–

this is a library of methods for Sub::HandlesVia. that's it, that's the whole thesis. it gives your attributes counter superpowers πŸ¦‹


πŸ‘‘ DELEGATABLE METHODS πŸ‘‘

these are the ones you can hand off to your attributes. slay.

πŸ’… dec( $amount? )

Arguments: Optional[Int].

decrements the counter by $amount, or by 1 if no value is given. so if you're feeling vague, it just does one, no questions asked ✨

my $object = My::Class->new( attr => 10 );
$object->my_dec;
$object->my_dec;
say $object->attr; ## ==> 8
$object->my_dec( 5 );
say $object->attr; ## ==> 3

watch it go down. the numbers. they descend. we love to see it πŸ“‰

πŸŽ€ inc( $amount? )

Arguments: Optional[Int].

increments the counter by $amount, or by 1 if no value is given. same deal, opposite direction, main character energy only πŸ’œ

my $object = My::Class->new( attr => 0 );
$object->my_inc;
$object->my_inc;
say $object->attr; ## ==> 2
$object->my_inc( 3 );
say $object->attr; ## ==> 5

the way it just... goes up. obsessed 🌈

πŸ¦‹ reset()

sets the counter to its default value, or to 0 if it has no default. it's giving "start over, fresh face, new me" πŸ’–

my $object = My::Class->new( attr => 10 );
$object->my_reset;
say $object->attr; ## ==> 0
heads up bestie: if your attribute has a default, reset goes back to that β€” not automatically to 0. 0 is only the fallback when there's no default at all. iykyk.

⭐ set( $value )

Arguments: Int.

sets the counter to the given value. no vibes, no ambiguity, just vibes-override πŸ’…

my $object = My::Class->new( attr => 0 );
$object->my_set( 5 );
say $object->attr; ## ==> 5

😭 BUGS 😭

pls pls pls report any bugs to:

<https://github.com/tobyink/p5-sub-handlesvia/issues>

they wanna know. we gotta tell them. it's a whole thing 🫢


πŸ”₯ SEE ALSO πŸ”₯

  • Sub::HandlesVia. the mothership. the blueprint. the icon herself πŸ‘‘

🧚 AUTHOR 🧚

Toby Inkster <tobyink@cpan.org>.


This software is copyright (c) 2020, 2022 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


πŸ’€ DISCLAIMER OF WARRANTIES πŸ’€

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

no cap, that one's in all caps for a reason β€” there are literally no warranties, express or implied, so don't come for anyone if it breaks 🫣

and that's the whole page, bestie!! πŸŽ€ this was Sub::Ha...Counter(3) from the User Contributed Perl Documentation, perl v5.42.0, dated 2026-02-11 β€” tysm for reading, go forth and counter πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from