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,resetgoes back to that β not automatically to0.0is 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>.
π COPYRIGHT AND LICENCE π
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
- fedora 44: perl-Sub-HandlesVia 0.053005-1.fc44 Β· 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