Moose::...::Number(3)

πŸ’– Moose::...::Number(3) πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation and it's literally all about Moose::Meta::Attribute::Native::Trait::Number β€” say that five times fast, I dare you 🫢


✨ NAME ✨

Moose::Meta::Attribute::Native::Trait::Number β€” it's the helper trait for Num attributes, and it's giving "math but make it Moose" πŸ’…


🌸 VERSION 🌸

version 2.4000 β€” yes she's got a version, she's official ✨


πŸŽ€ SYNOPSIS πŸŽ€

okay so here's the whole vibe in code, don't touch anything, it's perfect:

package Real;
use Moose;

has 'integer' => (
    traits  => ['Number'],
    is      => 'ro',
    isa     => 'Num',
    default => 5,
    handles => {
        set => 'set',
        add => 'add',
        sub => 'sub',
        mul => 'mul',
        div => 'div',
        mod => 'mod',
        abs => 'abs',
    },
);

my $real = Real->new();
$real->add(5);    # same as $real->integer($real->integer + 5);
$real->sub(2);    # same as $real->integer($real->integer - 2);

see those comments? πŸ‘€ that's the whole point. $real->add(5) is literally just $real->integer($real->integer + 5) wearing a cute little delegation outfit. iconic behaviour, no notes πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

so this trait hands you native delegation methods for numbers, and every single one of them corresponds to a real arithmetic operation β€” addition, multiplication, all the classics you learned before you could spell "Moose". it's not doing anything sneaky, it's just math, but, like, ✨*aesthetically*✨.


🌈 DEFAULT TYPE 🌈

if you don't give your attribute an isa value, bestie, it's gonna default to Num. that's the deal. that's the default. periodt πŸ’…


πŸ‘‘ PROVIDED METHODS πŸ‘‘

heads up: all of these methods modify the attribute's value in place, and all of them return the new value. every single one. no exceptions, no cap πŸ”₯
  • add($value) β€” adds the current value of the attribute to $value. classic. a staple. the moment 🫢
  • sub($value) β€” subtracts $value from the current value of the attribute. yes it's sub, no it's not the Perl keyword, don't @ me 😭
  • mul($value) β€” multiplies the current value of the attribute by $value. growth mindset fr fr 🌱
  • div($value) β€” divides the current value of the attribute by $value. sharing is caring ✨
  • mod($value) β€” returns the current value of the attribute modulo $value. the remainder, the leftovers, the little bit at the end πŸ“
  • abs β€” sets the current value of the attribute to its absolute value. no negativity allowed, we're only accepting positive energy in this house πŸ’– (note: no arguments on this one, she takes nothing, she's self-sufficient πŸ‘‘)

πŸ’€ BUGS πŸ’€

found a bug? 😭 don't panic. go read "BUGS" in Moose for the details on how to report them β€” that's where the whole reporting situation lives, and it's got you covered.


🧚 AUTHORS 🧚

these are the legends who made it happen, show some respect:

  • Stevan Little <stevan@cpan.org>
  • Dave Rolsky <autarch@urth.org>
  • Jesse Luehrs <doy@cpan.org>
  • Shawn M Moore <sartak@cpan.org>
  • Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman) <nothingmuch@woobling.org>
  • Karen Etheridge <ether@cpan.org>
  • Florian Ragwitz <rafl@debian.org>
  • Hans Dieter Pearcey <hdp@cpan.org>
  • Chris Prather <chris@prather.org>
  • Matt S Trout <mstrout@cpan.org>

this software is copyright (c) 2006 by Infinity Interactive, Inc.

and it's free software, bestie β€” you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. go wild, just keep the terms πŸ’œ


and that's the whole page!! πŸŽ€ it came from the perl v5.42.0 docs, dated 2025-07-25, and honestly? she ate. mwah πŸ’‹

πŸ“¦ where this page comes from