MooseX...:Traits(3pm)

πŸ“¦
version 1.102570 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ MooseX::CompileTime::Traits ✨

okay bestie, gather round, because this one is lowkey iconic πŸ’– it's a page from the User Contributed Perl Documentation (yes, the MooseX...:Traits(3pm) one, the title got a lil truncated in the header, we don't talk about it πŸ™ˆ), and it's all about letting classes and roles get their traits at compile time. no cap.


πŸ¦‹ NAME πŸ¦‹

MooseX::CompileTime::Traits β€” Allow compile time traits for classes/roles


🌸 VERSION 🌸

version 1.102570


✨ SYNOPSIS ✨

here's the vibe, fr fr:

role Bar(Int :$bar) { method bar { $bar + 2 } }
role Baz(Int :$baz) { method baz { $baz + 4 } }

class Foo with MooseX::CompileTime::Traits { }
class Flarg with MooseX::CompileTime::Traits { }

...

use Foo traits => [ Bar => { bar => 2 } ];
use Flarg traits => [ Bar => { bar => 1 }, Baz => { baz => 1} ];

Foo->new()->bar(); # 4
my $flarg = Flarg->new();
$flarg->bar(); # 3
$flarg->baz(); # 5

like. look at that. 4, 3, 5. the math is mathing πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

MooseX::CompileTime::Traits allows role application at compile time via use statements. what this class actually does is provide an import method that will apply each of the roles (along with any arguments for parameterized roles). it's giving "I do the boring wiring so you don't have to" πŸ‘‘

roles and their arguments should be provided as an ArrayRef of tuples. yes, tuples. keep them cozy in an arrayref, bestie.

simply with the role to gain the functionality. that's it. that's the whole move. 🫢


πŸŽ€ PUBLIC_METHODS πŸŽ€

⭐ import ⭐

(ClassName $class: ArrayRef :$traits?)

import is provided such that when your class or role is use'd it can take additional arguments that will be validatated (yes, the original says it like that, and honestly? we respect the typo era 🩷) and interpreted as roles or traits that need to be applied.

so: use your class, pass traits, and the roles get applied for you. no manual labor. main character energy only 🌈

πŸ¦‹ AUTHOR πŸ¦‹

Nicholas Perez <nperez@cpan.org>


This software is copyright (c) 2010 by Infinity Interactive.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page, bestie πŸ’– this lil doc was baked with perl v5.36.0 and dated 2022-12-12, and honestly it ate. go forth and apply your traits at compile time, you gorgeous genius, you πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from