MouseX...ts::Str(3pm)
π MouseX::NativeTraits::Str β the manual, but make it cute β¨
Manual page for MouseX...ts::Str(3pm) β yeah bestie, the name got squished by the terminal, that's just how the pager renders it, don't worry about it π«Ά
π NAME π
MouseX::NativeTraits::Str β the helper trait for Str attributes. it's giving "strings, but make them do tricks" π
β¨ SYNOPSIS β¨
okay so picture this: you want a string attribute but you're too iconic to be doing lvalue metaclass gymnastics. boom:
package MyHomePage;
use Mouse;
has 'text' => (
traits => ['String'],
is => 'rw',
isa => 'Str',
default => q{},
handles => {
add_text => 'append',
replace_text => 'replace',
},
);
my $page = MyHomePage->new();
$page->add_text("foo"); # same as $page->text($page->text . "foo");
that last line? chef's kiss. add_text("foo") is literally just $page->text($page->text . "foo") but with main character energy π
πΈ DESCRIPTION πΈ
This module hands you a simple string attribute, and the whole point is that mutating string operations are so much easier to apply to it β no need to build an lvalue attribute metaclass, no need for temporary variables, none of that. Additional methods are provided for completion. slay β¨
π¦ PROVIDED METHODS π¦
These methods live in MouseX::NativeTraits::MethodProvider::Str. Important heads-up: every single one of these does an in place modification of the value stored in the attribute. no copies, no take-backs, it edits the actual thing fr fr π
incβ Increments the value stored in this slot using the magical string autoincrement operator. Note that Perl doesn't provide analogous behavior in"--", so"dec"is not available. π sorry bestie, no decrement arc for youappend($string)β Append a string, like.=.prepend($string)β Prepend a string. (yes, the other end. we love range π)replace($pattern, $replacement)β Performs a regexp substitution ("s"in perlop). A code reference will be accepted for the replacement, causing the regexp to be modified with a single"e"."/smxi"can be applied using the"qr"operator.replace($pattern, $replacement)β Performs a regexp substitution ("s"in perlop) with the"g"flag. A code reference will be accepted for the replacement, causing the regexp to be modified with a single"e"."/smxi"can be applied using the"qr"operator.
not a typo, bestie!! there are genuinely tworeplaceentries β one plain, one with the"g"flag doing the global thing. keep both in your head, they're different vibes π
match($pattern)β Like"replace"but without the replacement. Provided mostly for completeness. (it's the "I'm just here to vibe check the pattern" of methods π§)chopβ"chop"in perlfunc.chompβ"chomp"in perlfunc.clearβ Sets the string to the empty string (not the value passed to"default"). yes, empty. EMPTY empty. not your default. don't @ me. π«§lengthβ"length"in perlfunc.substrβ"substr"in perlfunc. We go to some lengths to match the different functionality based on"substr"'s arity. pun fully intended, they knew what they were doing π
π METHODS π
metamethod_provider_classhelper_type
π SEE ALSO π
MouseX::NativeTraits
that's the whole page, bestie β go forth and mutate some strings πβ¨ππ¦πΈ
this page came from the User Contributed Perl Documentation, and it's tagged perl v5.34.0, dated 2022-06-16. periodt. π
π¦ 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