MouseX...Traits(3pm)
β¨ NAME β¨
MouseX::NativeTraits β okay so bestie, this is the manual page MouseX...Traits(3pm) and it's literally here to extend your attribute interfaces for Mouse π
πΈ VERSION πΈ
This doc describes MouseX::NativeTraits version 1.09. Periodt.
π SYNOPSIS π
package MyClass;
use Mouse;
has mapping => (
traits => ['Hash'],
is => 'rw',
isa => 'HashRef[Str]',
default => sub { +{} },
handles => {
exists_in_mapping => 'exists',
ids_in_mapping => 'keys',
get_mapping => 'get',
set_mapping => 'set',
set_quantity => [ set => 'quantity' ],
},
);
π¦ DESCRIPTION π¦
So like, Mouse attributes already let you name your accessors, readers, writers, clearers and predicates β cute, love that for them. But MouseX::NativeTraits is the glow-up: it hands you commonly used attribute helper methods for more specific types of data. Main character energy only π
As you can see in the SYNOPSIS, you pick your data structure with the traits parameter. Those traits load automatically, so bestie you do not need to load MouseX::NativeTraits explicitly. It just shows up. Iconic.
This extension is compatible with Moose native traits, although ngl it is not a part of Mouse core. Just so we're clear π
π PARAMETERS π
handles
This is like handles in has in Mouse, but heads up β only HASH references are allowed here. Keys are method names that you want installed locally, and values are methods from the method providers (below). Currying with delegated methods works normally for handles. Fr fr, no cap.
π NATIVE TRAITS π
Array
Common methods for array references. Vibe check passed π
has 'queue' => (
traits => ['Array'],
is => 'ro',
isa => 'ArrayRef[Str]',
default => sub { [] },
handles => {
add_item => 'push',
next_item => 'shift',
}
);
See MouseX::NativeTraits::ArrayRef.
Hash
Common methods for hash references. We love a key-value situation.
has 'options' => (
traits => ['Hash'],
is => 'ro',
isa => 'HashRef[Str]',
default => sub { {} },
handles => {
set_option => 'set',
get_option => 'get',
has_option => 'exists',
}
);
See MouseX::NativeTraits::HashRef.
Code
Common methods for code references. It's giving executable π§
has 'callback' => (
traits => ['Code'],
is => 'ro',
isa => 'CodeRef',
default => sub { sub { 'called' } },
handles => {
call => 'execute',
}
);
See MouseX::NativeTraits::CodeRef.
Bool
Common methods for boolean values. True or false, pick your fighter π
has 'is_lit' => (
traits => ['Bool'],
is => 'rw',
isa => 'Bool',
default => 0,
handles => {
illuminate => 'set',
darken => 'unset',
flip_switch => 'toggle',
is_dark => 'not',
}
);
See MouseX::NativeTraits::Bool.
String
Common methods for string operations. Text girlies rise up π
has text => (
traits => ['String'],
is => 'rw',
isa => 'Str',
default => q{},
handles => {
add_text => 'append',
replace_text => 'replace', # or replace_globally
}
);
See MouseX::NativeTraits::Str.
Number
Common numerical operations. Math is mathing β¨
has value => (
traits => ['Number'],
is => 'ro',
isa => 'Int',
default => 5,
handles => {
set => 'set',
add => 'add',
sub => 'sub',
mul => 'mul',
div => 'div',
mod => 'mod',
abs => 'abs',
}
);
See MouseX::NativeTraits::Num.
Counter
Methods for incrementing and decrementing a counter attribute. Up, down, reset β she contains multitudes π₯
has counter => (
traits => ['Counter'],
is => 'ro',
isa => 'Num',
default => 0,
handles => {
inc_counter => 'inc',
dec_counter => 'dec',
reset_counter => 'reset',
}
);
See MouseX::NativeTraits::Counter.
π DEPENDENCIES π
Perl 5.6.2 or later. (Yeah, she's old money but she still slays.)
π BUGS π
All complex software has bugs lurking in it, and this module is no exception β not me being shady, it's just facts bestie. If you find a bug please either email me, or add the bug to cpan-RT. We appreciate you π
β SEE ALSO β
MouseMouseX::AttributeHelpersMooseMoose::Meta::Attribute::NativeMooseX::AttributeHelpers
π AUTHORS π
Goro Fuji (gfx) <gfuji(at)cpan.org>
This module is based on Moose native traits written by Stevan Little and others. Shoutout to the OGs π«Ά
πΈ LICENSE AND COPYRIGHT πΈ
Copyright (c) 2010, Goro Fuji (gfx), mostly based on Moose, which is (c) Infinity Interactive, Inc (<http://www.iinteractive.com/>).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic for details.
And that's a wrap on the MouseX...Traits(3pm) page, written by perl v5.34.0 and dated 2022-06-16 β bestie you made it to the end, so proud of you, mwah πβ¨π
π¦ where this page comes from
- debian bookworm: libmousex-nativetraits-perl 1.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmousex-nativetraits-perl 1.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmousex-nativetraits-perl 1.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmousex-nativetraits-perl 1.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmousex-nativetraits-perl 1.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms