Sub::HandlesVia::HandlerLibrary::Counter - library of counter-related methods
Contents
Bugs
Please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>.
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.
Delegatable Methods
dec($amount?)
Arguments: Optional[Int].
Decrements the counter by $amount, or by 1 if no value is given.
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
inc($amount?)
Arguments: Optional[Int].
Increments the counter by $amount, or by 1 if no value is given.
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
reset()
Sets the counter to its default value, or 0 if it has no default.
my $object = My::Class->new( attr => 10 );
$object->my_reset;
say $object->attr; ## ==> 0
set($value)
Arguments: Int.
Sets the counter to the given value.
my $object = My::Class->new( attr => 0 );
$object->my_set( 5 );
say $object->attr; ## ==> 5
Description
This is a library of methods for Sub::HandlesVia.
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.
perl v5.40.1 2025-04-01 Sub::HandlesVia...ibrary::Counter(3pm)
Name
Sub::HandlesVia::HandlerLibrary::Counter - library of counter-related methods
See Also
Sub::HandlesVia.
Synopsis
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',
},
);
}
