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$valuefrom the current value of the attribute. yes it'ssub, 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>
β COPYRIGHT AND LICENSE β
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
- fedora 43: perl-Moose 2.4000-4.fc43 Β· 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