MouseX...ts::Str(3pm)

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

πŸ’– 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 you
  • append($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 two replace entries β€” 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 πŸ’œ

  • meta
  • method_provider_class
  • helper_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