Sub::Ha...::Number(3)

πŸ’– Sub::HandlesVia::HandlerLibrary::Number πŸ’–

okay bestie, welcome to the Sub::HandlesVia::HandlerLibrary::Number page β€” it's the library of number-related methods and it is genuinely so useful, no cap. this is the Sub::HandlesVia handler library for numbers, and she does math so you don't have to. periodt. πŸŽ€


✨ SYNOPSIS ✨

look at this gorgeous little setup, she's giving main character energy:

package My::Class {
  use Moo;
  use Sub::HandlesVia;
  use Types::Standard 'Num';
  has attr => (
    is => 'rwp',
    isa => Num,
    handles_via => 'Number',
    handles => {
      'my_abs' => 'abs',
      'my_add' => 'add',
      'my_ceil' => 'ceil',
      'my_cmp' => 'cmp',
      'my_div' => 'div',
      'my_eq' => 'eq',
      'my_floor' => 'floor',
      'my_ge' => 'ge',
      'my_get' => 'get',
      'my_gt' => 'gt',
      'my_le' => 'le',
      'my_lt' => 'lt',
      'my_mod' => 'mod',
      'my_mul' => 'mul',
      'my_ne' => 'ne',
      'my_set' => 'set',
      'my_sub' => 'sub',
    },
  );
}

🌸 DESCRIPTION 🌸

so like, this is a library of methods for Sub::HandlesVia. that's it, that's the whole vibe. πŸ’…


πŸ¦‹ DELEGATABLE METHODS πŸ¦‹

abs()

finds the absolute value of the current number, and she updates the attribute while she's at it. iconic behavior honestly.

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

add( $addend )

Arguments: Num.

adds a number to the existing number, updating the attribute. girl math but make it real. πŸ’–

my $object = My::Class->new( attr => 4 );
$object->my_add( 5 );
say $object->attr; ## ==> 9

ceil()

finds the ceiling of the current number, updating the attribute. it's like ceil from builtin, but in-place. lowkey obsessed.


cmp( $num )

Arguments: Num.

returns $object->attr <=> $num. spaceship operator core πŸš€


div( $divisor )

Arguments: Num.

divides the existing number by a number, updating the attribute.

my $object = My::Class->new( attr => 6 );
$object->my_div( 2 );
say $object->attr; ## ==> 3

eq( $num )

Arguments: Num.

returns $object->attr == $num.


floor()

finds the floor of the current number, updating the attribute. like floor from builtin, but in-place. she stays grounded fr fr. 🌈


ge( $num )

Arguments: Num.

returns $object->attr >= $num.


get()

returns the current value of the number. just vibes, no changes. πŸ‘‘

my $object = My::Class->new( attr => 4 );
say $object->my_get; ## ==> 4

gt( $num )

Arguments: Num.

returns $object->attr > $num.


le( $num )

Arguments: Num.

returns $object->attr <= $num.


lt( $num )

Arguments: Num.

returns $object->attr < $num.


mod( $divisor )

Arguments: Num.

finds the current number modulo a divisor, updating the attribute.

my $object = My::Class->new( attr => 5 );
$object->my_mod( 2 );
say $object->attr; ## ==> 1

mul( $factor )

Arguments: Num.

multiplies the existing number by a number, updating the attribute.

my $object = My::Class->new( attr => 2 );
$object->my_mul( 5 );
say $object->attr; ## ==> 10

ne( $num )

Arguments: Num.

returns $object->attr != $num.


set( $value )

Arguments: Num.

sets the number to a new value. glow up moment. ✨

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

sub( $subtrahend )

Arguments: Num.

subtracts a number from the existing number, updating the attribute.

my $object = My::Class->new( attr => 9 );
$object->my_sub( 6 );
say $object->attr; ## ==> 3

πŸ’€ BUGS πŸ’€

found a bug? not the vibe, pls report it, bestie:

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


🫢 SEE ALSO 🫢

  • Sub::HandlesVia.

πŸ‘‘ AUTHOR πŸ‘‘

Toby Inkster <tobyink@cpan.org>. legend behavior, honestly.


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.

and that's the whole page bestie!! this was perl v5.42.0, dated 2026-02-11 β€” mwah, slay, bye πŸ’…πŸŽ€βœ¨

πŸ“¦ where this page comes from